##// END OF EJS Templates
Remove yield test that are not support by pytest anymore...
Remove yield test that are not support by pytest anymore And remove comparison of str/unicode as it is not relevant anymore as both are the same. We can now unpin pytest as well, which we should make sure is in release notes and in the conda-forge recipe As nose does not understand `@parametrize`, and the nose `@skip` decorator messes with that as well, we mark tests with parametrize as not-tests for iptests

File last commit:

r25582:6e079503
r26183:61376395
Show More
module_paths.py
73 lines | 2.4 KiB | text/x-python | PythonLexer
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """Utility functions for finding modules
Utility functions for finding modules on sys.path.
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 `find_module` returns a path to module or None, given certain conditions.
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
"""
#-----------------------------------------------------------------------------
# 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
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 import importlib
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 import os
Nathan Goldbaum
support using '%run -m' for modules importable via an import hook
r25582 import sys
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
# Third-party imports
# Our own imports
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Local utilities
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 def find_mod(module_name):
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 Find module `module_name` on sys.path, and return the path to module `module_name`.
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 - 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.
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Parameters
----------
module_name : str
Returns
-------
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 module_path : str
Path to module `module_name`, its __init__.py, or None,
depending on above conditions.
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 loader = importlib.util.find_spec(module_name)
module_path = loader.origin
if module_path is None:
Nathan Goldbaum
support using '%run -m' for modules importable via an import hook
r25582 if loader.loader in sys.meta_path:
return loader.loader
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 return None
else:
split_path = module_path.split(".")
Christopher Brown
Fix extension detection...
r24836 if split_path[-1] in ["py", "pyw"]:
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 return module_path
else:
return None