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
Load six from system package or bundled copy #2623
Conversation
👍 I'm not sure about the new directory "bundled" though, as everything in "extern" is already "bundled" as it were. Can you just put |
Also -- whatever solution we come up with here should be (ideally) generalizable to the other external dependencies we include (configobj and py.test). (Though the bundling of py.test is already kind of a special case -- that probably doesn't have to change). |
After trying different things I found that the best way is to put the bundled libraries in a different subpackge, not under the same package you are importing. At first I put the bundled six as a file _six.py under astropy/extern/six but I found it confusing. You would end up importing astropy.extern.six._six What is possible is that I can use a six.py module instead of a six subpackage. I can test it. If something along the line of this gets approved, I will do the same for the others, configobj and ply, yes |
@sergiopasra: That sounds like a good idea. Go ahead and update this PR, and I'm glad to have another look. |
@mdboom I have changed the six subpackage to a six module. The module does work as the subpackage |
Thanks for the update. It does seem like the Travis failure is somehow legitimate. Any thoughts about why that might be happening? |
No, no idea. It seems to fail in the only case where build_sphinx is run, Is that correct? But I can run build_sphinx -w in my system and it works. |
This seems unnecessarily complex and fragile to me. I'd rather just have modules in astropy perform imports of six from some subpackage, where the subpackage's This would require changing how some of Astropy's modules use. For example, An alternative might also be to make |
@embray If you think this is complex, then you should see my first implementation, it used a CustomImporter class in Anyway. My prefered solution would be to use always the system
So we agree that the procedure is:
The discussion is about how you convert the imported six module into the real six module. Your approach has some disadvantages:
|
Well, no, but neither is creating dummy modules and manually inserting them in to |
I have another idea for this that might work. Hang tight... |
@sergiopasra I sent a PR to sergiopasra#1 with an alternative idea. It seems to work for me, but if you'd like to give it a try let me know how it works for you. |
One thing we might also want to add to this is that if the system version is found it should have some minimum For example I just tried running
My system version of According to six's changelog it looks like for astropy we should currently require a minimum of 1.5.0. |
This last commit allows to check the |
|
…le--looking first for the unadorned 'six' module that would be found on sys.path, and failing that looking up 'astropy.extern.bundled.six'. Then load that module using the load_module machinery, but giving it the new name 'astropy.extern.six'. That makes everything 'just work' and is compatible with six's own sys.modules games.
1) Checks for bundled six over system copy *first*. For typical user self-installs I'd rather Astropy use its bundled version rather than default to whatever (potentially untested) version is floating around on the user's system (which may not even be the right module named "six"! 2) Regardless of where the 'six' module is found, checks that its __version__ meets the current minimum version 1.5.0.
Okay, I rebased my PR and added a version check as well. One thing I also made different is that in my version the bundled copy of 'six' is checked for first. The reason for this is that if users install Astropy themselves (via pip install, etc.) I'd much rather the bundled version be the default, rather than whatever "six" module happens to be floating around on the user's system which could be broken or not even the right thing (this is less of a problem on a more managed system like Debian or RH). For the system package you could either change the order or, if the bundled copy is removed from the source RPM altogether then the check for the bundled copy can be removed entirely as well. Does that sound okay? If there's anything else that can be done to make this easier to tweak I'm all for it, just as long as the main Astropy source defaults to using the bundled copy. |
@embray thanks!, I have merged your PR. For the check order, I'm ok with it. With this configuration, to load the system module I just need to remove six.py from bundled, or change the order of the check with a patch. It's easier than patching than whole package as I was doing |
I have to document several things. For example, if newer features of six are used, the SIX_MEAN_VERSION has to be changed. Other thing worth mentioning is that if you remove |
Maybe just a README directly in astropy/extern would be fine. |
This was marked for 1.0.0 but I moved it to 0.4.1. Things that make system packagers' lives easier can generally go in a bugfix release I think. |
I manually merged this PR via f7a0814 (strange that GitHub doesn't seem to be making the cross reference) to include a changelog entry and the aforementioned README. |
Ups, sorry, I haven't had the time to complete this. @embray thanks for doing it yourself |
Wasn't sure if I should open a new issue for this: is there a reason why the bundled copy of six isn't the most recent version? I was recently testing out a feature involving pickling on Windows and came across an interesting error:
It turns out this is a known issue with six < 1.7.0 -- basically, six used to add |
@amras1 - I think because they release versions fast and we haven't updated in the last few months ;) Feel free to update the bundled version with a PR! |
Okay, sounds good! |
Since six is a bit complicated, this is based on astropy/astropy#2623.
Since six is a bit complicated, this is based on astropy/astropy#2623.
This changes the way astropy.extern.six is imported. When astropy.extern.six is imported, the code in the module tries to import six from system packages. If is found and the version is equal or greater to the version of the bundled copy, then system six and six.moves are inserted in sys.modules, with the keys astropy.extern.six and astropy.six.moves
If it is not found or the version is lesser than the bundled copy, the bundled copy gets inserted in sys.modules instead.
With this PR, packagers of astropy do not have to worry about unbundling six, it will work with the system library if available.
Other bundled libraries will follow if this is approved