forked from orbit-oss/flask
Updated docstring
This commit is contained in:
parent
c3844d1102
commit
1d6f86bc87
1 changed files with 10 additions and 4 deletions
|
|
@ -466,23 +466,29 @@ def send_from_directory(directory, filename, **options):
|
||||||
return send_file(filename, conditional=True, **options)
|
return send_file(filename, conditional=True, **options)
|
||||||
|
|
||||||
|
|
||||||
def get_root_path(name):
|
def get_root_path(import_name):
|
||||||
"""Returns the path to a package or cwd if that cannot be found. This
|
"""Returns the path to a package or cwd if that cannot be found. This
|
||||||
returns the path of a package or the folder that contains a module.
|
returns the path of a package or the folder that contains a module.
|
||||||
|
|
||||||
Not to be confused with the package path returned by :func:`find_package`.
|
Not to be confused with the package path returned by :func:`find_package`.
|
||||||
"""
|
"""
|
||||||
|
__import__(import_name)
|
||||||
try:
|
try:
|
||||||
return os.path.abspath(os.path.dirname(sys.modules[name].__file__))
|
directory = os.path.dirname(sys.modules[import_name].__file__)
|
||||||
except (KeyError, AttributeError):
|
return os.path.abspath(directory)
|
||||||
|
except AttributeError:
|
||||||
return os.getcwd()
|
return os.getcwd()
|
||||||
|
|
||||||
|
|
||||||
def find_package(import_name):
|
def find_package(import_name):
|
||||||
"""Finds a package and returns the prefix (or None if the package is
|
"""Finds a package and returns the prefix (or None if the package is
|
||||||
not installed) as well as the folder that contains the package or
|
not installed) as well as the folder that contains the package or
|
||||||
module as a tuple.
|
module as a tuple. The package path returned is the module that would
|
||||||
|
have to be added to the pythonpath in order to make it possible to
|
||||||
|
import the module. The prefix is the path below which a UNIX like
|
||||||
|
folder structure exists (lib, share etc.).
|
||||||
"""
|
"""
|
||||||
|
__import__(import_name)
|
||||||
root_mod = sys.modules[import_name.split('.')[0]]
|
root_mod = sys.modules[import_name.split('.')[0]]
|
||||||
package_path = getattr(root_mod, '__file__', None)
|
package_path = getattr(root_mod, '__file__', None)
|
||||||
if package_path is None:
|
if package_path is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue