Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed May 23, 2024
1 parent 3cdc897 commit 3f93b78
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
41 changes: 32 additions & 9 deletions ubelt/util_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,17 +551,21 @@ def check_dpath(dpath):
# break with pytest anymore? Nope, pytest still doesn't work right
# with it.
for finder_fpath in new_editable_finder_paths:
mapping = _static_parse('MAPPING', finder_fpath)
try:
target = dirname(mapping[_pkg_name])
except KeyError:
mapping = _static_parse('MAPPING', finder_fpath)
except AttributeError:
...
else:
if not exclude or normalize(target) not in real_exclude: # pragma: nobranch
modpath = check_dpath(target)
if modpath: # pragma: nobranch
found_modpath = modpath
break
try:
target = dirname(mapping[_pkg_name])
except KeyError:
...
else:
if not exclude or normalize(target) not in real_exclude: # pragma: nobranch
modpath = check_dpath(target)
if modpath: # pragma: nobranch
found_modpath = modpath
break
if found_modpath is not None:
break

Expand Down Expand Up @@ -646,6 +650,14 @@ def _importlib_import_modpath(modpath): # nocover
return module


def _importlib_modname_to_modpath(modname): # nocover
import importlib.util
spec = importlib.util.find_spec(modname)
print(f'spec={spec}')
modpath = spec.origin.replace('.pyc', '.py')
return modpath


def _pkgutil_modname_to_modpath(modname): # nocover
"""
faster version of :func:`_syspath_modname_to_modpath` using builtin python
Expand Down Expand Up @@ -717,7 +729,18 @@ def modname_to_modpath(modname, hide_init=True, hide_main=False, sys_path=None):
>>> modpath = basename(modname_to_modpath('_ctypes'))
>>> assert 'ctypes' in modpath
"""
modpath = _syspath_modname_to_modpath(modname, sys_path)
if hide_main or sys_path:
modpath = _syspath_modname_to_modpath(modname, sys_path)
else:
# import xdev
# with xdev.embed_on_exception_context:
try:
modpath = _importlib_modname_to_modpath(modname)
except Exception:
modpath = _syspath_modname_to_modpath(modname, sys_path)
# modpath = _pkgutil_modname_to_modpath(modname, sys_path)
# modpath = _syspath_modname_to_modpath(modname, sys_path)

if modpath is None:
return None

Expand Down
2 changes: 1 addition & 1 deletion ubelt/util_indexable.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def diff(self, other, rel_tol=1e-9, abs_tol=0.0, equal_nan=False):
is the number of approximately equal items (i.e. floats) there were
Example:
>>> from ubelt.util_indexable import * # NOQA
>>> import ubelt as ub
>>> dct1 = {
>>> 'foo': [1.222222, 1.333],
>>> 'bar': 1,
Expand Down

0 comments on commit 3f93b78

Please sign in to comment.