-
Notifications
You must be signed in to change notification settings - Fork 117
Fix importing module from python file #323
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
Conversation
|
@rsarm can you running try with this branch? |
reframe/utility/__init__.py
Outdated
| filename = os.path.join(filename, '__init__.py') | ||
|
|
||
| if filename.startswith('..'): | ||
| if filename.startswith('..') or os.path.isfile(filename): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait a sec. Is this not always true??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the filename is a directory no
Codecov Report
@@ Coverage Diff @@
## master #323 +/- ##
==========================================
- Coverage 91.24% 91.18% -0.06%
==========================================
Files 67 67
Lines 7935 7941 +6
==========================================
+ Hits 7240 7241 +1
- Misses 695 700 +5
Continue to review full report at Codecov.
|
The current implementation first resolves the module file relative to ReFrame. If it is inside ReFrame's top-level dir, it uses the standard Python mechanism (from importlib) to import the module. If not it loads it directly from the file assigning it a module name derived from the file's basename.
reframe/utility/__init__.py
Outdated
|
|
||
| module_name = _get_module_name(filename) | ||
| if os.path.isabs(filename): | ||
| if os.path.isabs(filename) or os.path.basename(filename) == filename: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix does not work. Try running reframe from a directory up:
./reframe/bin/reframe --system=generic -c reframe/tutorial/example1.py -l
The whole problem comes from how the sys.path is defined (check this). Actually, for our case, the first element is the path where the reframe.py or test_reframe.py exists. That's why these relative imports work fine when we we invoke ReFrame from the same directory. I've done a PR into your branch with the correct implementation.
…rrect-impl Fix import from file code.
Fixes #322