Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Fixed for Python 3.6 / pip 9.0.1 on Mac OS X 10.13. #16

Merged
merged 1 commit into from
Dec 15, 2017

Conversation

alexreg
Copy link
Contributor

@alexreg alexreg commented Dec 15, 2017

There was some Mac-specific code in pip that was causing issues with the get_platform monkey patch.

I'm not sure if I added the monkey patch for sysconfig.get_platform correctly (this is needed for Python 2.7 and >= 3.2, according to the pip source code, apparently). In any case, it seems to work!

@alexreg
Copy link
Contributor Author

alexreg commented Dec 15, 2017

Oh, and great work on this utility by the way. Finding it very handy for uploading packages to AWS lambda. :-)

@asottile
Copy link
Member

Cool to hear that it's helping you out!

I'll double check this patch when I'm at a mac later. Thanks for the PR :D

Just curious, what commands are you trying / seeing on mac (so I can make sure they work myself!) -- the main intention of this package was for linux platforms but I can definitely see wanting to "rename" a specific mac distribution set.

@alexreg
Copy link
Contributor Author

alexreg commented Dec 15, 2017

No problem. Let me know if you need me to amend the PR.

I was doing pip-custom-platform download --platform manylinux1_x86_64 --dist foo and pip-custom-platform install --platform manylinux1_x86_64 --target foo, both on individual packages and requirements files, and it was still downloading/installing packages for my actual platform (macOS).

@asottile
Copy link
Member

I have a slightly different patch which I think works better? I couldn't get this to work with your patch for instance:

pip-custom-platform wheel --platform=macwat simplejson
pip-custom-platform install wheelhouse/*macwat.whl

(note that the way that pymonkey works (the monkeypatching utility library) is it's a post import hook. It's too late to patch pep425tags because it has already initialized some module-scoped variables based on the real platform -- so I have to re-initialize them. For pip10, this isn't necessary but that's not out / widely used yet).

Here's the patch:

diff --git a/pip_custom_platform/pymonkey.py b/pip_custom_platform/pymonkey.py
index 3d8e772..facf730 100644
--- a/pip_custom_platform/pymonkey.py
+++ b/pip_custom_platform/pymonkey.py
@@ -11,6 +11,11 @@ def pymonkey_patch(mod, args):
     if mod.__name__ == 'distutils.util':
         from pip_custom_platform.default_platform import get_platform_func
         mod.get_platform = get_platform_func(args, mod.get_platform)
+    elif mod.__name__ in ('pip.pep425tags', 'pip._internal.pep425tags'):
+        from pip_custom_platform.default_platform import get_platform_func
+        mod.get_platform = get_platform_func(args, mod.get_platform)
+        mod.supported_tags = mod.get_supported()
+        mod.supported_tags_noarch = mod.get_supported(noarch=True)
     elif mod.__name__ in ('pip', 'pip._internal') and hasattr(mod, 'main'):
         from pip_custom_platform._main import get_main
         mod.main = get_main(mod.main)

try it out and let me know if it works for you! (then either you or I can commit it and I'll merge it in :D)

@alexreg
Copy link
Contributor Author

alexreg commented Dec 15, 2017

Yep, seems to work well! I'm surprised you don't need the sysconfig patch, as the pip code suggests you would, but fair enough. Thanks for quickly addressing this. :-)

Added monkey patch for pep425tags modules.
@asottile
Copy link
Member

yeah the sysnconfig stuff isn't necessary because we patch away the function that would call sysconfig! (and since it's a post-import hook, we actually get a chance to patch it before the function would get imported by some other module -- so our patch percolates)

@asottile asottile merged commit 7033d4a into asottile-archive:master Dec 15, 2017
@asottile
Copy link
Member

I'll make a release for this when I get the chance! (leaving this unread in my email so it bothers me until I do it 😆 )

@alexreg
Copy link
Contributor Author

alexreg commented Dec 15, 2017

Okay, guess I didn't check closely enough! Sounds good. Looks forward to the release. :-)

@asottile
Copy link
Member

This has been released as v0.3.2!

@alexreg
Copy link
Contributor Author

alexreg commented Dec 18, 2017

Brilliant, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants