Fill the cache of potential modules and packages for this directory.
(self)
| 1401 | return None |
| 1402 | |
| 1403 | def _fill_cache(self): |
| 1404 | """Fill the cache of potential modules and packages for this directory.""" |
| 1405 | path = self.path |
| 1406 | try: |
| 1407 | contents = _os.listdir(path or _os.getcwd()) |
| 1408 | except (FileNotFoundError, PermissionError, NotADirectoryError): |
| 1409 | # Directory has either been removed, turned into a file, or made |
| 1410 | # unreadable. |
| 1411 | contents = [] |
| 1412 | # We store two cached versions, to handle runtime changes of the |
| 1413 | # PYTHONCASEOK environment variable. |
| 1414 | if not sys.platform.startswith('win'): |
| 1415 | self._path_cache = set(contents) |
| 1416 | else: |
| 1417 | # Windows users can import modules with case-insensitive file |
| 1418 | # suffixes (for legacy reasons). Make the suffix lowercase here |
| 1419 | # so it's done once instead of for every import. This is safe as |
| 1420 | # the specified suffixes to check against are always specified in a |
| 1421 | # case-sensitive manner. |
| 1422 | lower_suffix_contents = set() |
| 1423 | for item in contents: |
| 1424 | name, dot, suffix = item.partition('.') |
| 1425 | if dot: |
| 1426 | new_name = f'{name}.{suffix.lower()}' |
| 1427 | else: |
| 1428 | new_name = name |
| 1429 | lower_suffix_contents.add(new_name) |
| 1430 | self._path_cache = lower_suffix_contents |
| 1431 | if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS): |
| 1432 | self._relaxed_path_cache = {fn.lower() for fn in contents} |
| 1433 | |
| 1434 | @classmethod |
| 1435 | def path_hook(cls, *loader_details): |