Skip to content

Fix extension detection#11499

Merged
Carreau merged 2 commits intoipython:masterfrom
chbrown:patch-1
Nov 19, 2018
Merged

Fix extension detection#11499
Carreau merged 2 commits intoipython:masterfrom
chbrown:patch-1

Conversation

@chbrown
Copy link
Contributor

@chbrown chbrown 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

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
Copy link
Member

Carreau 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
Copy link
Member

Carreau 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
@chbrown chbrown deleted the patch-1 branch November 19, 2018 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants