| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,6 +96,22 @@ def makepath(*paths): | |||
| 96 | 96 | return dir, os.path.normcase(dir) | |
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | + def abs_paths(): | ||
| 100 | + """Set all module __file__ and __cached__ attributes to an absolute path""" | ||
| 101 | + for m in set(sys.modules.values()): | ||
| 102 | + if (getattr(getattr(m, '__loader__', None), '__module__', None) not in | ||
| 103 | + ('_frozen_importlib', '_frozen_importlib_external')): | ||
| 104 | + continue # don't mess with a PEP 302-supplied __file__ | ||
| 105 | + try: | ||
| 106 | + m.__file__ = os.path.abspath(m.__file__) | ||
| 107 | + except (AttributeError, OSError): | ||
| 108 | + pass | ||
| 109 | + try: | ||
| 110 | + m.__cached__ = os.path.abspath(m.__cached__) | ||
| 111 | + except (AttributeError, OSError): | ||
| 112 | + pass | ||
| 113 | + | ||
| 114 | + | ||
| 99 | 115 | def removeduppaths(): | |
| 100 | 116 | """ Remove duplicate entries from sys.path along with making them | |
| 101 | 117 | absolute""" | |
@@ -506,7 +522,13 @@ def main(): | |||
| 506 | 522 | """ | |
| 507 | 523 | global ENABLE_USER_SITE | |
| 508 | 524 | ||
| 525 | + orig_path = sys.path[:] | ||
| 509 | 526 | known_paths = removeduppaths() | |
| 527 | + if orig_path != sys.path: | ||
| 528 | + # removeduppaths() might make sys.path absolute. | ||
| 529 | + # fix __file__ and __cached__ of already imported modules too. | ||
| 530 | + abs_paths() | ||
| 531 | + | ||
| 510 | 532 | known_paths = venv(known_paths) | |
| 511 | 533 | if ENABLE_USER_SITE is None: | |
| 512 | 534 | ENABLE_USER_SITE = check_enableusersite() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments