diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/python/ipython/py3/IPython/utils/module_paths.py | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/python/ipython/py3/IPython/utils/module_paths.py')
-rw-r--r-- | contrib/python/ipython/py3/IPython/utils/module_paths.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/contrib/python/ipython/py3/IPython/utils/module_paths.py b/contrib/python/ipython/py3/IPython/utils/module_paths.py new file mode 100644 index 0000000000..0570c322e6 --- /dev/null +++ b/contrib/python/ipython/py3/IPython/utils/module_paths.py @@ -0,0 +1,70 @@ +"""Utility functions for finding modules + +Utility functions for finding modules on sys.path. + +`find_module` returns a path to module or None, given certain conditions. + +""" +#----------------------------------------------------------------------------- +# Copyright (c) 2011, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +# Stdlib imports +import importlib +import os + +# Third-party imports + +# Our own imports + + +#----------------------------------------------------------------------------- +# Globals and constants +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Local utilities +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Classes and functions +#----------------------------------------------------------------------------- + +def find_mod(module_name): + """ + Find module `module_name` on sys.path, and return the path to module `module_name`. + + - If `module_name` refers to a module directory, then return path to __init__ file. + - If `module_name` is a directory without an __init__file, return None. + - If module is missing or does not have a `.py` or `.pyw` extension, return None. + - Note that we are not interested in running bytecode. + - Otherwise, return the fill path of the module. + + Parameters + ---------- + module_name : str + + Returns + ------- + module_path : str + Path to module `module_name`, its __init__.py, or None, + depending on above conditions. + """ + loader = importlib.util.find_spec(module_name) + module_path = loader.origin + if module_path is None: + return None + else: + split_path = module_path.split(".") + if split_path[-1] in ["py", "pyw"]: + return module_path + else: + return None |