Skip to content

Commit 9845236

Browse files
authored
[Fix] Fix when package overwrites __path__ to a string. (#43)
Summary: Fix when package overwrites `__path__` to a string. Test Plan: all Reviewed-by: - Issue: -
1 parent 219b1a8 commit 9845236

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
run: |
6767
nox -s test_import_third_party-${{ matrix.conda-py }}
6868
- name: Setup tmate session
69-
if: ${{ failure() }}
69+
if: ${{ failure() && false }}
7070
uses: mxschmitt/action-tmate@v3
7171

7272
test-twine:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='code-data-share',
13-
version='0.1.0',
13+
version='0.0.3',
1414
packages=['cds'],
1515
package_dir={'': 'src'},
1616
python_requires='>=3.8.0',

src/cds/dump.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,21 @@ def wrap_exec_module(self, module):
4545
# __path__ must be an iterable of strings,
4646
# we convert any valid __path__ to tuple of strings.
4747
# Ref: https://docs.python.org/3/reference/import.html#module-path
48-
path = tuple(path) if path else None
48+
if not path:
49+
path = None
50+
elif isinstance(path, str):
51+
# Some package might change this, which is non-standard.
52+
# There is no correct way to handle this.
53+
# We retain the file location to maintain the original import function,
54+
# and also record the `path` for debugging purposes.
55+
import os.path
56+
path = (os.path.dirname(file), path)
57+
else:
58+
try:
59+
path = tuple(path)
60+
except TypeError:
61+
_verbose(f"{name}.__path__ is not iterable: {path}", 1)
62+
path = None
4963
meta_map[name] = (package, file, path)
5064
return module
5165

@@ -68,8 +82,9 @@ def wrap_exec_module(self, module):
6882
_verbose(f'executing module {line} triggers an SystemExit({e.code}), ignoring.', 1)
6983
except Exception as e:
7084
_verbose(f'executing module {line} triggers an {e.__class__.__name__}, traceback:', 1)
85+
import sys
7186
import traceback
72-
_verbose(''.join(traceback.format_exception(e)), 1)
87+
_verbose(''.join(traceback.format_exception(*sys.exc_info())), 1)
7388

7489
shared_class_data = tuple([(k, v) for k, v in {
7590
k: (*meta_map[k], code_map[k])

0 commit comments

Comments
 (0)