Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix when package overwrites __path__ to a string. #43

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
run: |
nox -s test_import_third_party-${{ matrix.conda-py }}
- name: Setup tmate session
if: ${{ failure() }}
if: ${{ failure() && false }}
uses: mxschmitt/action-tmate@v3

test-twine:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='code-data-share',
version='0.1.0',
version='0.0.3',
packages=['cds'],
package_dir={'': 'src'},
python_requires='>=3.8.0',
Expand Down
19 changes: 17 additions & 2 deletions src/cds/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ def wrap_exec_module(self, module):
# __path__ must be an iterable of strings,
# we convert any valid __path__ to tuple of strings.
# Ref: https://docs.python.org/3/reference/import.html#module-path
path = tuple(path) if path else None
if not path:
path = None
elif isinstance(path, str):
# Some package might change this, which is non-standard.
# There is no correct way to handle this.
# We retain the file location to maintain the original import function,
# and also record the `path` for debugging purposes.
import os.path
path = (os.path.dirname(file), path)
else:
try:
path = tuple(path)
except TypeError:
_verbose(f"{name}.__path__ is not iterable: {path}", 1)
path = None
meta_map[name] = (package, file, path)
return module

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

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