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 extension detection #11499

Merged
merged 2 commits into from Nov 19, 2018

Conversation

@chbrown
Copy link
Contributor

commented Nov 18, 2018

If the path leading up to the Python installation's site-packages contains a ., this check does not do what it says it does :(

For instance, on macOS, the site-packages directory is located at /usr/local/lib/python3.7/site-packages, which means that trying to use the magic %run -m my.module will always fail, because split_path[1] will always start with 7/site-packages.

There are better ways to check that a file extension matches expectations, but I thought it was cute that I could fix this bug by inserting a single character :)

My current workaround looks like this:

import importlib
import_path = importlib.util.find_spec('my.module').origin
%run $import_path
Fix extension detection
If the path leading up to the Python installation's `site-packages` contains a `.`, this check does not do what it says it does :(

For instance, on macOS, the `site-packages` directory is located at `/usr/local/lib/python3.7/site-packages`, which means that trying to use the magic `%run -m my.module` will always fail, because `split_path[1]` will always start with `7/site-packages`.

There are better ways to check that a file extension matches expectations, but I thought it was cute that I could fix this bug by inserting a single character :)

My current workaround looks like this:
```python
import importlib
import_path = importlib.util.find_spec('my.module').origin
%run $import_path
```
@Carreau

This comment has been minimized.

Copy link
Member

commented Nov 19, 2018

THanks that seem reasonable, I'll see if I can add a test to make sure there is no regressions.

@Carreau Carreau added this to the 7.2 milestone Nov 19, 2018

@Carreau

This comment has been minimized.

Copy link
Member

commented Nov 19, 2018

I've modified test to check for multiple dot in path. Thanks.

@Carreau Carreau merged commit 5e7f930 into ipython:master Nov 19, 2018

4 checks passed

codecov/patch 100% of diff hit (target 0%)
Details
codecov/project Absolute coverage decreased by -<.01% but relative coverage increased by +31.58% compared to 844ad8b
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@chbrown chbrown deleted the chbrown:patch-1 branch Nov 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.