Lines Matching refs:path

1 """Core implementation of path-based import.
97 """Replacement for os.path.join()."""
103 path = []
107 path = [path_sep + tail]
113 path = [tail]
115 path.append(tail)
118 path.append(tail)
119 path = [p.rstrip(path_separators) for p in path if p]
120 if len(path) == 1 and not path[0]:
123 return root + path_sep.join(path)
127 """Replacement for os.path.join()."""
132 def _path_split(path):
133 """Replacement for os.path.split()."""
134 i = max(path.rfind(p) for p in path_separators)
136 return '', path
137 return path[:i], path[i + 1:]
140 def _path_stat(path):
141 """Stat the path.
147 return _os.stat(path)
150 def _path_is_mode_type(path, mode):
151 """Test whether the path is the specified mode type."""
153 stat_info = _path_stat(path)
159 def _path_isfile(path):
160 """Replacement for os.path.isfile."""
161 return _path_is_mode_type(path, 0o100000)
164 def _path_isdir(path):
165 """Replacement for os.path.isdir."""
166 if not path:
167 path = _os.getcwd()
168 return _path_is_mode_type(path, 0o040000)
172 def _path_isabs(path):
173 """Replacement for os.path.isabs."""
174 if not path:
176 root = _os._path_splitroot(path)[0].replace('/', '\\')
180 def _path_isabs(path):
181 """Replacement for os.path.isabs."""
182 return path.startswith(path_separators)
185 def _write_atomic(path, data, mode=0o666):
186 """Best-effort function to write data to a path atomically.
190 path_tmp = '{}.{}'.format(path, id(path))
198 _os.replace(path_tmp, path)
437 def cache_from_source(path, debug_override=None, *, optimization=None):
438 """Given the path to a .py file, return the path to its .pyc file.
440 The .py file does not need to exist; this simply returns the path to the
462 path = _os.fspath(path)
463 head, tail = _path_split(path)
481 # We need an absolute path to the py file to avoid the possibility of
492 # Strip initial drive from a Windows path. We know we have an absolute
493 # path here, so the second part of the check rules out a POSIX path that
498 # Strip initial path separator from `head` to complete the conversion
499 # back to a root-relative path before joining.
508 def source_from_cache(path):
509 """Given the path to a .pyc. file, return the path to its .py file.
511 The .pyc file does not need to exist; this simply returns the path to
512 the .py file calculated to correspond to the .pyc file. If path does
519 path = _os.fspath(path)
520 head, pycache_filename = _path_split(path)
531 f'{path!r}')
549 """Convert a bytecode file path to a source path (if possible).
579 def _calc_mode(path):
582 mode = _path_stat(path).st_mode
737 name=name, path=bytecode_path)
853 """Meta path finder for modules declared in the Windows registry."""
886 def find_spec(cls, fullname, path=None, target=None):
902 def find_module(cls, fullname, path=None):
911 spec = cls.find_spec(fullname, path)
925 the path returned by get_filename has a filename of '__init__.py'."""
950 def path_mtime(self, path):
952 specified path (a str).
954 Raises OSError when the path cannot be handled.
958 def path_stats(self, path):
960 path (a str).
968 Raises OSError when the path cannot be handled.
970 return {'mtime': self.path_mtime(path)}
973 """Optional method which writes data (bytes) to a file path (a str).
977 The source path is needed in order to correctly transfer permissions
982 def set_data(self, path, data):
983 """Optional method which writes data (bytes) to a file path (a str).
991 path = self.get_filename(fullname)
993 source_bytes = self.get_data(path)
999 def source_to_code(self, data, path, *, _optimize=-1):
1004 return _bootstrap._call_with_frames_removed(compile, data, path, 'exec',
1038 'path': bytecode_path,
1097 def __init__(self, fullname, path):
1098 """Cache the module name and the path to the file found by the
1101 self.path = path
1108 return hash(self.name) ^ hash(self.path)
1124 """Return the path to the source file as found by the finder."""
1125 return self.path
1127 def get_data(self, path):
1128 """Return the data from path as raw bytes."""
1130 with _io.open_code(str(path)) as file:
1133 with _io.FileIO(path, 'r') as file:
1146 def path_stats(self, path):
1147 """Return the metadata for the path."""
1148 st = _path_stat(path)
1156 def set_data(self, path, data, *, _mode=0o666):
1158 parent, filename = _path_split(path)
1179 _write_atomic(path, data, _mode)
1180 _bootstrap._verbose_message('created {!r}', path)
1183 _bootstrap._verbose_message('could not create {!r}: {!r}', path,
1192 path = self.get_filename(fullname)
1193 data = self.get_data(path)
1198 'path': path,
1204 bytecode_path=path,
1220 def __init__(self, name, path):
1222 self.path = path
1229 return hash(self.name) ^ hash(self.path)
1236 spec.name, self.path)
1243 self.name, self.path)
1247 file_name = _path_split(self.path)[1]
1261 """Return the path to the source file as found by the finder."""
1262 return self.path
1266 """Represents a namespace package's path. It uses the module name
1268 __path__. When this changes, the module's own path is recomputed,
1269 using path_finder. For top-level modules, the parent module's path
1270 is sys.path."""
1276 def __init__(self, name, path, path_finder):
1278 self._path = path
1284 """Returns a tuple of (parent-module-name, parent-path-attr-name)"""
1287 # This is a top-level module. sys.path contains the parent path.
1288 return 'sys', 'path'
1290 # parent path.
1298 # If the parent's path has changed, recalculate _path
1303 # do remember the new parent path
1317 def __setitem__(self, index, path):
1318 self._path[index] = path
1337 def __init__(self, name, path, path_finder):
1338 self._path = _NamespacePath(name, path, path_finder)
1373 _bootstrap._verbose_message('namespace module loaded with path {!r}',
1391 """Meta path finder for sys.path and package __path__ attributes."""
1395 """Call the invalidate_caches() method on all path entry finders
1398 # Drop entry if finder name is a relative path. The current
1409 def _path_hooks(path):
1410 """Search sys.path_hooks for a finder for 'path'."""
1415 return hook(path)
1422 def _path_importer_cache(cls, path):
1423 """Get the finder for the path entry from sys.path_importer_cache.
1425 If the path entry is not in the cache, find the appropriate finder
1429 if path == '':
1431 path = _os.getcwd()
1437 finder = sys.path_importer_cache[path]
1439 finder = cls._path_hooks(path)
1440 sys.path_importer_cache[path] = finder
1465 def _get_spec(cls, fullname, path, target=None):
1470 for entry in path:
1487 # Remember these path entries (if any) for when we
1489 # on path.
1497 def find_spec(cls, fullname, path=None, target=None):
1498 """Try to find a spec for 'fullname' on sys.path or 'path'.
1502 if path is None:
1503 path = sys.path
1504 spec = cls._get_spec(fullname, path, target)
1510 # We found at least one namespace path. Return a spec which
1521 def find_module(cls, fullname, path=None):
1522 """find the module on sys.path or 'path' based on sys.path_hooks and
1531 spec = cls.find_spec(fullname, path)
1544 of directories ``context.path``.
1559 def __init__(self, path, *loader_details):
1560 """Initialize with the path to search on and a variable number of
1567 # Base (directory) path
1568 if not path or path == '.':
1569 self.path = _os.getcwd()
1570 elif not _path_isabs(path):
1571 self.path = _path_join(_os.getcwd(), path)
1573 self.path = path
1599 def _get_spec(self, loader_class, fullname, path, smsl, target):
1600 loader = loader_class(fullname, path)
1601 return spec_from_file_location(fullname, path, loader=loader,
1612 mtime = _path_stat(self.path or _os.getcwd()).st_mtime
1627 base_path = _path_join(self.path, tail_module)
1634 # If a namespace package, return the path if we don't
1640 full_path = _path_join(self.path, tail_module + suffix)
1657 path = self.path
1659 contents = _os.listdir(path or _os.getcwd())
1689 which will return an instance using the specified loaders and the path
1692 If the path called on the closure is not a directory, ImportError is
1696 def path_hook_for_FileFinder(path):
1698 if not _path_isdir(path):
1699 raise ImportError('only directories are supported', path=path)
1700 return cls(path, *loader_details)
1705 return 'FileFinder({!r})'.format(self.path)
1750 """Install the path-based import components."""