コード例 #1
0
        private static PythonVersion TryGetCPythonPath(PythonLanguageVersion version, RegistryKey python, bool x64)
        {
            if (python != null)
            {
                string versionStr = version.ToString().Substring(1);
                string id         = versionStr = versionStr[0] + "." + versionStr[1];
                if (!x64 && version >= PythonLanguageVersion.V35)
                {
                    versionStr += "-32";
                }

                using (var versionKey = python.OpenSubKey(versionStr + "\\InstallPath")) {
                    if (versionKey != null)
                    {
                        var installPath = versionKey.GetValue("");
                        if (installPath != null)
                        {
                            var path = Path.Combine(installPath.ToString(), "python.exe");
                            var arch = NativeMethods.GetBinaryType(path);
                            if (arch == ProcessorArchitecture.X86)
                            {
                                return(x64 ? null : new PythonVersion(
                                           path,
                                           version,
                                           CPythonInterpreterFactoryConstants.GetIntepreterId(
                                               "PythonCore",
                                               arch,
                                               id
                                               ),
                                           false,
                                           false,
                                           true
                                           ));
                            }
                            else if (arch == ProcessorArchitecture.Amd64)
                            {
                                return(x64 ? new PythonVersion(
                                           path,
                                           version,
                                           CPythonInterpreterFactoryConstants.GetIntepreterId(
                                               "PythonCore",
                                               arch,
                                               id
                                               ),
                                           true,
                                           false,
                                           true
                                           ) : null);
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                }
            }
            return(null);
        }
コード例 #2
0
        private static PythonVersion GetJythonVersion(PythonLanguageVersion version)
        {
            var candidates = new List <DirectoryInfo>();
            var ver        = version.ToVersion();
            var path1      = string.Format("jython{0}{1}*", ver.Major, ver.Minor);
            var path2      = string.Format("jython{0}.{1}*", ver.Major, ver.Minor);

            foreach (var drive in DriveInfo.GetDrives())
            {
                if (drive.DriveType != DriveType.Fixed)
                {
                    continue;
                }

                try {
                    candidates.AddRange(drive.RootDirectory.EnumerateDirectories(path1));
                    candidates.AddRange(drive.RootDirectory.EnumerateDirectories(path2));
                } catch {
                }
            }

            foreach (var dir in candidates)
            {
                var interpreter = dir.EnumerateFiles("jython.bat").FirstOrDefault();
                if (interpreter == null)
                {
                    continue;
                }
                var libPath = dir.EnumerateDirectories("Lib").FirstOrDefault();
                if (libPath == null || !libPath.EnumerateFiles("site.py").Any())
                {
                    continue;
                }
                return(new PythonVersion(
                           interpreter.FullName,
                           version,
                           CPythonInterpreterFactoryConstants.GetIntepreterId(
                               "Jython",
                               ProcessorArchitecture.X86,
                               version.ToVersion().ToString()
                               ),
                           false,
                           false,
                           true
                           ));
            }
            return(null);
        }
コード例 #3
0
        private async void AddCustomEnvironment_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (_service == null)
            {
                return;
            }

            const string baseName = "New Environment";
            string       name     = baseName;
            int          count    = 2;

            while (_interpreters.FindConfiguration(CPythonInterpreterFactoryConstants.GetIntepreterId("VisualStudio", ProcessorArchitecture.X86, name)) != null)
            {
                name = baseName + " " + count++;
            }

            var factory = _service.AddConfigurableInterpreter(
                name,
                new InterpreterConfiguration(
                    "",
                    name,
                    "",
                    "python\\python.exe",
                    arch: ProcessorArchitecture.X86
                    )
                );

            UpdateEnvironments(factory);

            await Dispatcher.InvokeAsync(() => {
                var coll = TryFindResource("SortedExtensions") as CollectionViewSource;
                if (coll != null)
                {
                    var select = coll.View.OfType <ConfigurationExtensionProvider>().FirstOrDefault();
                    if (select != null)
                    {
                        coll.View.MoveCurrentTo(select);
                    }
                }
            }, DispatcherPriority.Normal);
        }
コード例 #4
0
        private static PythonVersion GetCPythonVersion(PythonLanguageVersion version, bool x64 = false)
        {
            if (!x64)
            {
                foreach (var baseKey in new[] { Registry.LocalMachine, Registry.CurrentUser })
                {
                    using (var python = baseKey.OpenSubKey(PythonCorePath)) {
                        var res = TryGetCPythonPath(version, python, x64);
                        if (res != null)
                        {
                            return(res);
                        }
                    }
                }
            }

            if (Environment.Is64BitOperatingSystem && x64)
            {
                foreach (var baseHive in new[] { RegistryHive.LocalMachine, RegistryHive.CurrentUser })
                {
                    var python64 = RegistryKey.OpenBaseKey(baseHive, RegistryView.Registry64).OpenSubKey(PythonCorePath);
                    var res      = TryGetCPythonPath(version, python64, x64);
                    if (res != null)
                    {
                        return(res);
                    }
                }
            }

            var path = "C:\\Python" + version.ToString().Substring(1) + "\\python.exe";
            var arch = NativeMethods.GetBinaryType(path);

            if (arch == ProcessorArchitecture.X86 && !x64)
            {
                return(new PythonVersion(path, version,
                                         CPythonInterpreterFactoryConstants.GetIntepreterId(
                                             "PythonCore",
                                             arch,
                                             version.ToVersion().ToString()
                                             ),
                                         false,
                                         false,
                                         true
                                         ));
            }
            else if (arch == ProcessorArchitecture.Amd64 && x64)
            {
                return(new PythonVersion(
                           path,
                           version,
                           CPythonInterpreterFactoryConstants.GetIntepreterId(
                               "PythonCore",
                               arch,
                               version.ToVersion().ToString()
                               ),
                           true,
                           false,
                           true
                           ));
            }

            if (x64)
            {
                path = "C:\\Python" + version.ToString().Substring(1) + "_x64\\python.exe";
                arch = NativeMethods.GetBinaryType(path);
                if (arch == ProcessorArchitecture.Amd64)
                {
                    return(new PythonVersion(
                               path,
                               version,
                               CPythonInterpreterFactoryConstants.GetIntepreterId(
                                   "PythonCore",
                                   arch,
                                   version.ToVersion().ToString()
                                   ),
                               true,
                               false,
                               true

                               ));
                }
            }

            return(null);
        }