Skip to content
Myr

Fixed an issue with the new path finding logic

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 086348e · Browse files · 1 file+13 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−1 removed

  • other:+13 added−1 removed

1 file+13 added−1 removed

modified:flask/helpers.py+13 added-1 removed
614 unmodified lines
615 returns the path of a package or the folder that contains a module.616617 Not to be confused with the package path returned by :func:`find_package`.618 """619 # Module already imported and has a file attribute. Use that first.620 mod = sys.modules.get(import_name)621 if mod is not None and hasattr(mod, '__file__'):622 return os.path.dirname(os.path.abspath(mod.__file__))623624 # Next attempt: check the loader.625 loader = pkgutil.get_loader(import_name)626627 # Loader does not exist or we're referring to an unloaded main module628 # or a main module without path (interactive sessions), go with the629 # current working directory.630 if loader is None or import_name == '__main__':621 # import name is not found, or interactive/main module631 return os.getcwd()632633 # For .egg, zipimporter does not have get_filename until Python 2.7.634 # Some other loaders might exhibit the same behavior.635 if hasattr(loader, 'get_filename'):636 filepath = loader.get_filename(import_name)637 else:638 # Fall back to imports.639 __import__(import_name)640 filepath = sys.modules[import_name].__file__641642 # filepath is import_name.py for a module, or __init__.py for a package.643 return os.path.dirname(os.path.abspath(filepath))644645
197 unmodified lines