Пример #1
0
 def get_all_stdlib_module_names(self, python_version):
   """Get the names of all modules in typeshed and pytype/pytd/builtins."""
   if self._env_home:
     raise NotImplementedError("Not implemented: Can't scan external typeshed")
   major = python_version[0]
   subdirs = [os.path.join("pytd/builtins/%d" % major),
              os.path.join("pytd/stdlib/%d" % major),
              "typeshed/stdlib/%d" % major,
              "typeshed/stdlib/2and3",
              "typeshed/third_party/%d" % major,
              "typeshed/third_party/2and3",
             ]
   if major == 3:
     for i in range(0, python_version[1] + 1):
       # iterate over 3.0, 3.1, 3.2, ...
       subdirs.append("typeshed/stdlib/3.%d" % i)
   module_names = set()
   for subdir in subdirs:
     try:
       contents = list(utils.list_pytype_files(subdir))
     except utils.NoSuchDirectory:
       pass
     else:
       for filename in contents:
         module_names.add(utils.path_to_module_name(filename))
   assert "ctypes" in module_names  # sanity check
   return module_names
Пример #2
0
 def blacklisted_modules(self, python_version):
   """Return the blacklist, as a list of module names. E.g. ["x", "y.z"]."""
   for full_filename in self.read_blacklist():
     filename = os.path.splitext(full_filename)[0]
     path = filename.split("/")  # E.g. ["stdlib", "2", "html", "parser.pyi"]
     # It's possible that something is blacklisted with a more
     # specific version (e.g. stdlib/3.4/...). That usually just means
     # that this module didn't exist in earlier Python versions. So
     # we can still just use python_version[0].
     if (path[1].startswith(str(python_version[0])) or
         path[1] == "2and3"):
       yield utils.path_to_module_name("/".join(path[2:]))
Пример #3
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(utils.list_pytype_files(subdir))
         except utils.NoSuchDirectory:
             pass
         else:
             for filename in contents:
                 module_names.add(utils.path_to_module_name(filename))
     assert "ctypes" in module_names  # sanity check
     return module_names
Пример #4
0
 def testPathToModuleName(self):
   self.assertEqual("x.y.z", utils.path_to_module_name("x/y/z.pyi"))
   self.assertEqual("x.y.z", utils.path_to_module_name("x/y/z.pytd"))
   self.assertEqual("x.y.z", utils.path_to_module_name("x/y/z/__init__.pyi"))