You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This means that it gets imported only when no package of the same name can be found using the PathFinder, which for instance looks into site_packages. Normally, this poses no problem, because the pip install command uninstalls any package of the same name before doing the editable install.
However, "expanding" the local site-packages directory by using (additional) .pth files, packages found in these additional locations will always shadow editable installs, because pip can't touch them.
Example:
I have a rather large venv, let's call it base_env. I want to make modifications to it (update/remove some packages) and would like to test this.
I could create an empty second venv (test_env) and just add a .pth file to its site-packages directory that points to the base_env's site-packages. This way, I have access to all of base_env's packages in test_env. If I update any of them using pip install -U mypackage, pip will install the new version in test_env's site-packages dir, try to uninstall the old version and fail. But that's ok, because the local site-packages dir takes precedence over the one in base_env due to the order in sys.path, so when importing mypackage, I'll get the local, updated version.
The same happens when I just do a regular install from local source files by doing pip install path/to/mypackage.
However, when I execute pip install -e path/to/mypackage, import mypackage will always give me the version from base_env, because the EditableFinder is never called since the package was already found by the PathFinder.
I realize this might be an edge case, but I don't find the scenario all too contrived and the fact that just adding -e to the pip command in this case completely changes import behavior at least violates POLA to me.
Would there be a downside to ensuring that editable installs always take precedence over potentially existing packages of the same name? This could be achieved by simply changing the position in sys.meta_path.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current template for the addition of the
EditableFinderfor a package installed bypip install -e path/to/mypackageappends it tosys.meta_path:setuptools/setuptools/command/editable_wheel.py
Line 890 in 5a13876
This means that it gets imported only when no package of the same name can be found using the
PathFinder, which for instance looks intosite_packages. Normally, this poses no problem, because thepip installcommand uninstalls any package of the same name before doing the editable install.However, "expanding" the local
site-packagesdirectory by using (additional).pthfiles, packages found in these additional locations will always shadow editable installs, becausepipcan't touch them.Example:
I have a rather large venv, let's call it
base_env. I want to make modifications to it (update/remove some packages) and would like to test this.I could create an empty second venv (
test_env) and just add a.pthfile to itssite-packagesdirectory that points to thebase_env'ssite-packages. This way, I have access to all ofbase_env's packages intest_env. If I update any of them usingpip install -U mypackage, pip will install the new version intest_env'ssite-packagesdir, try to uninstall the old version and fail. But that's ok, because the localsite-packagesdir takes precedence over the one inbase_envdue to the order insys.path, so when importingmypackage, I'll get the local, updated version.The same happens when I just do a regular install from local source files by doing
pip install path/to/mypackage.However, when I execute
pip install -e path/to/mypackage,import mypackagewill always give me the version frombase_env, because theEditableFinderis never called since the package was already found by thePathFinder.I realize this might be an edge case, but I don't find the scenario all too contrived and the fact that just adding
-eto thepipcommand in this case completely changes import behavior at least violates POLA to me.Would there be a downside to ensuring that editable installs always take precedence over potentially existing packages of the same name? This could be achieved by simply changing the position in
sys.meta_path.Beta Was this translation helpful? Give feedback.
All reactions