コード例 #1
0
ファイル: AstAnalysisTests.cs プロジェクト: pmshenoy/PTVS
        private static IPythonModule Parse(string path, PythonLanguageVersion version)
        {
            var interpreter = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion()).CreateInterpreter();

            if (!Path.IsPathRooted(path))
            {
                path = TestData.GetPath(Path.Combine("TestData", "AstAnalysis", path));
            }
            return(AstPythonModule.FromFile(interpreter, path, version));
        }
コード例 #2
0
        private IPythonModule LoadModuleFromDirectory(string searchPath, string moduleName)
        {
            Func <string, bool> isPackage = null;

            if (!ModulePath.PythonVersionRequiresInitPyFiles(_langVersion))
            {
                isPackage = Directory.Exists;
            }

            ModulePath package;

            try {
                package = ModulePath.FromBasePathAndName(searchPath, moduleName, isPackage);
            } catch (ArgumentException) {
                return(null);
            }

            EnsureSearchPathDB();
            if (package.IsNativeExtension || package.IsCompiled)
            {
                _searchPathDb.LoadExtensionModule(package);
            }
            else
            {
                _searchPathDb.AddModule(package.FullName, AstPythonModule.FromFile(
                                            this,
                                            package.SourceFile,
                                            _factory.GetLanguageVersion(),
                                            package.FullName
                                            ));
            }

            var mod = _searchPathDb.GetModule(package.FullName);

            if (!package.IsSpecialName)
            {
                int i = package.FullName.LastIndexOf('.');
                if (i >= 1)
                {
                    var parent    = package.FullName.Remove(i);
                    var parentMod = _searchPathDb.GetModule(parent) as AstPythonModule;
                    if (parentMod != null)
                    {
                        parentMod.AddChildModule(package.Name, mod);
                    }
                }
            }

            return(mod);
        }
コード例 #3
0
        public IEnumerable <TestCaseInfo> GetTestCasesFromAst(string path)
        {
            IPythonModule module;

            try {
                module = AstPythonModule.FromFile(_analyzer.Interpreter, path, _analyzer.LanguageVersion);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                return(Enumerable.Empty <TestCaseInfo>());
            }

            var ctxt = _analyzer.Interpreter.CreateModuleContext();

            return(GetTestCasesFromAst(module, ctxt));
        }
コード例 #4
0
        private IPythonModule LoadModuleFromDirectory(string searchPath, string moduleName)
        {
            Func <string, bool> isPackage = null;

            if (!ModulePath.PythonVersionRequiresInitPyFiles(_langVersion))
            {
                isPackage = Directory.Exists;
            }

            ModulePath package;

            try {
                package = ModulePath.FromBasePathAndName(searchPath, moduleName, isPackage);
            } catch (ArgumentException) {
                return(null);
            }

            var db = EnsureSearchPathDB();

            if (package.IsNativeExtension || package.IsCompiled)
            {
                db.LoadExtensionModule(package);
            }
            else
            {
                db.AddModule(package.FullName, AstPythonModule.FromFile(
                                 this,
                                 package.SourceFile,
                                 _factory.GetLanguageVersion(),
                                 package.FullName
                                 ));
            }

            if (db != _searchPathDb)
            {
                // Racing with the DB being invalidated.
                // It's okay if we miss it here, so don't worry
                // about taking the lock.
                return(null);
            }

            var mod = db.GetModule(package.FullName);

            if (!package.IsSpecialName)
            {
                int i = package.FullName.LastIndexOf('.');
                if (i >= 1)
                {
                    var parent    = package.FullName.Remove(i);
                    var parentMod = db.GetModule(parent) as AstPythonModule;
                    if (parentMod != null)
                    {
                        parentMod.AddChildModule(package.Name, mod);
                    }
                }
            }

            lock (_searchPathDbLock) {
                if (db != _searchPathDb)
                {
                    // Raced with the DB being invalidated
                    return(null);
                }
            }

            return(mod);
        }