aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/utils/module_paths.py
diff options
context:
space:
mode:
authornkozlovskiy <nmk@ydb.tech>2023-09-29 12:24:06 +0300
committernkozlovskiy <nmk@ydb.tech>2023-09-29 12:41:34 +0300
commite0e3e1717e3d33762ce61950504f9637a6e669ed (patch)
treebca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/ipython/py3/IPython/utils/module_paths.py
parent38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff)
downloadydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz
add ydb deps
Diffstat (limited to 'contrib/python/ipython/py3/IPython/utils/module_paths.py')
-rw-r--r--contrib/python/ipython/py3/IPython/utils/module_paths.py70
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..6f8cb1004a
--- /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.
+
+"""
+#-----------------------------------------------------------------------------
+# 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 sys
+
+# 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.
+ """
+ spec = importlib.util.find_spec(module_name)
+ module_path = spec.origin
+ if module_path is None:
+ if spec.loader in sys.meta_path:
+ return spec.loader
+ return None
+ else:
+ split_path = module_path.split(".")
+ if split_path[-1] in ["py", "pyw"]:
+ return module_path
+ else:
+ return None