-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Appdirs vendor should not use win32api #4874
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
Comments
It's in conditional code that falls back to ctypes, which is always available. So there's no issue. Pip doesn't have a prohibition against importing C code, just against vendoring it. And while we don't typically rely on non-vendored modules outside of the stdlib, it's fine if vendored modules do so as long as the external module is optional (which this is). |
Edit: the failure was that it couldn't remove the win32api DLL because it was locked. |
Hmm, presumably the failure was because of a problem with your modified pywin32? Nevertheless, I agree - as appdirs is vendored, I'd suggest raising the issue with them. Given that ctypes is always available, I see no reason for having that pywin32 code, but if they do want to retain it, having an option to ignore pywin32 and/or fall back to ctypes on errors seems reasonable. |
I was more surprised by the fact that pip has 2 versions of appdirs: |
The failure was because I modified the import mechanism to load pywin32 C extensions just like every other C extension that Python uses. This is a somewhat technical and detailed topic, but IMO the modified pywin32 was perfectly valid. |
@pfmoore I'm not sure that this is an appdirs issue. It works fine except when |
@xoviat Can you clarify? The only place in pip which loads pywin32 is in @benoit-pierre Agreed that's weird. Looks like |
That's correct. The code works for every other application, except pip which may be removing DLLs. Is it their responsibility to fix problems that are unique to pip? |
What appears to have happened is that somewhere along the way, someone discovered this issue and fixed it. Then sometime later, a vendored copy was brought in that reintroduced the problem. |
I think we should patch appdirs that we vendor and use that instead then? |
I don't know how this could be happening. I'm not even sure what you mean by "removing DLLs". If you can provide a precise explanation of what you think is happening, that would help.
I don't think we should. My point is that pip itself isn't using the vendored appdirs at all. So we (in theory) don't care. Our vendored If @xoviat can establish that a standalone |
|
OK, so now you really need to follow the standard "reporting a bug" process. Please provide the exact sequence of commands you used, describe what you expected to happen, and what actually happened. |
It's
|
Traceback:
|
If you want to go the long way around, dig into the C code, trace all of the locks, you'll eventually find that the simplest solution is to simply comment out that code in |
Maybe pip could patch src/pip/_internal/__init__.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git i/src/pip/_internal/__init__.py w/src/pip/_internal/__init__.py
index 532edd26..4b991c60 100755
--- i/src/pip/_internal/__init__.py
+++ w/src/pip/_internal/__init__.py
@@ -38,6 +38,20 @@ else:
else:
securetransport.inject_into_urllib3()
+
+if sys.platform == "win32":
+ from pip._vendor import appdirs
+ try:
+ from ctypes import windll
+ appdirs._get_win_folder = appdirs._get_win_folder_with_ctypes
+ except ImportError:
+ try:
+ import com.sun.jna
+ appdirs._get_win_folder = appdirs._get_win_folder_with_jna
+ except ImportError:
+ appdirs._get_win_folder = appdirs._get_win_folder_from_registry
+
+
from pip import __version__
from pip._internal import cmdoptions
from pip._internal.exceptions import CommandError, PipError |
I don't really care much about it unless this can break with a sequence of pip install and uninstall. it's a pip bug if If it does break, pip should patch appdirs to unconditionally use ctypes... or that should happen upstream. I have a slight preference for latter.
This feels uncalled for. Please don't make a comment that might put others off. We're all trying to help each other here on our own free time. Let's keep our tones positive. :) Anyway, I don't want to derail the discussion here nor do I think I'd have any major inputs on this so I'll recede to spectating this issue now. |
Did not mean to put anyone off with my comment. Sorry about that. |
Isn't this just the pip can't import C code on Windows, because Python holds a lock to the dll file and thus we error out trying to remove the file on uninstall? IIRC we've commented out simplejson and pyopenssl support on Windows for the same reason? |
Yes, it's exactly that.
Yes, this is an excellent solution. OK to implement? |
What's importing |
|
Yep.
|
Yes, it appears so. Apologies for any confusion I may have caused, but I didn't have any idea that's the issue that was being reported. Rather than patching the vendored appdirs (which I don't have an issue with now I know what the problem is), could we patch the vendored Or we could monkeypatch it at runtime, as follows (untested): # Monkeypatch pkg_resources to use our version of appdirs
import pip._vendor.pkg_resources
import pip._internal.utils.appdirs
pip._vendor.pkg_resources.appdirs = pip._internal.utils.appdirs |
I don't think it's possible to monkeypatch pkg_resources because it may initialize the working set on import. |
I think we should drop |
Yeah, overall that seems like the best option. |
_vendor/appdirs.py
imports win32api. It should not because it loads a c library.The text was updated successfully, but these errors were encountered: