Ejemplo n.º 1
0
 def get_all_module_names(self, python_version):
     """Get the names of all modules in typeshed or bundled with pytype."""
     module_names = set()
     for abspath in self.get_typeshed_paths(python_version):
         relpath = abspath.rpartition("typeshed/")[-1]
         module_names |= _get_module_names_in_path(self._list_modules,
                                                   relpath, python_version)
     for abspath in self.get_pytd_paths(python_version):
         relpath = abspath.rpartition("pytype/")[-1]
         module_names |= _get_module_names_in_path(
             lambda path, unused_ver: pytype_source_utils.list_pytype_files(
                 path), relpath, python_version)
     # Also load modules not in typeshed, so that we have a dummy entry for them.
     for f in self.missing:
         parts = f.split("/")
         if self._use_new_structure:
             if ("@python2" in parts) != (python_version[0] == 2):
                 continue
             if parts[0] == "stdlib":
                 start_index = 1  # remove stdlib/ prefix
             else:
                 assert parts[0] == "stubs"
                 start_index = 2  # remove stubs/{package}/ prefix
             if parts[start_index] == "@python2":
                 start_index += 1
             filename = "/".join(parts[start_index:])
             module_names.add(filename.replace("/", "."))
         else:
             if parts[1].startswith(str(python_version[0])):
                 filename = "/".join(
                     parts[2:])  # remove prefixes like stdlib/2.7
                 module_names.add(filename.replace("/", "."))
     assert "ctypes" in module_names  # sanity check
     return module_names
Ejemplo n.º 2
0
 def _list_files(self, basedir):
     """Lists files recursively in a basedir relative to typeshed root."""
     if self._env_home:
         return pytype_source_utils.list_files(
             os.path.join(self._root, basedir))
     else:
         return pytype_source_utils.list_pytype_files(
             os.path.join("typeshed", basedir))
Ejemplo n.º 3
0
 def _list_files(self, basedir):
     """Lists files recursively in a basedir relative to typeshed root."""
     if self._env_home:
         fs = pytype_source_utils.list_files(
             os.path.join(self._root, basedir))
     else:
         fs = pytype_source_utils.list_pytype_files(
             os.path.join("typeshed", basedir))
     return [f for f in fs if "@python2" not in f]
Ejemplo n.º 4
0
 def get_all_module_names(self, python_version):
     """Get the names of all modules in typeshed or bundled with pytype."""
     module_names = set()
     for abspath in self.get_typeshed_paths():
         relpath = abspath.rpartition("typeshed/")[-1]
         module_names |= _get_module_names_in_path(self._list_modules,
                                                   relpath, python_version)
     for abspath in self.get_pytd_paths():
         relpath = abspath.rpartition("pytype/")[-1]
         module_names |= _get_module_names_in_path(
             lambda path, _: pytype_source_utils.list_pytype_files(path),
             relpath, python_version)
     # Also load modules not in typeshed, so that we have a dummy entry for them.
     module_names |= self._get_missing_modules()
     assert "ctypes" in module_names  # sanity check
     return module_names
Ejemplo n.º 5
0
 def get_all_module_names(self, python_version):
     """Get the names of all modules in typeshed or bundled with pytype."""
     if self._env_home:
         raise NotImplementedError(
             "Not implemented: Can't scan external typeshed")
     paths = (self.get_typeshed_paths(python_version) +
              self.get_pytd_paths(python_version))
     subdirs = [d.rpartition("pytype/")[-1] for d in paths]
     module_names = set()
     for subdir in subdirs:
         try:
             contents = list(pytype_source_utils.list_pytype_files(subdir))
         except pytype_source_utils.NoSuchDirectory:
             pass
         else:
             for filename in contents:
                 module_names.add(
                     module_utils.path_to_module_name(filename))
     assert "ctypes" in module_names  # sanity check
     return module_names
 def testListPytypeFiles(self):
     l = list(pytype_source_utils.list_pytype_files("pytd/stdlib/2"))
     self.assertIn("_ctypes.pytd", l)
     self.assertIn("collections.pytd", l)
Ejemplo n.º 7
0
 def test_list_pytype_files(self):
     l = list(pytype_source_utils.list_pytype_files("stubs/stdlib"))
     self.assertIn("_ctypes.pytd", l)
     self.assertIn("collections.pytd", l)