-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
allow --relocatable to work on Windows #401
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
allow --relocatable to work on Windows #401
Conversation
Nice trick. This seems to work with the windows launcher for Python (py.exe) supplied with Python 3.3+. Presumably it also works with setuptools exe wrappers (I haven't tried that, but I assume you have...)? Could you update the patch to remove the comment "Also this does not currently work on Windows." from the documentation? (docs/index.rst) |
Thanks. I'll update that doc file. I haven't yet tried it with 3.3, but I can. I don't see any mention of py.exe in virtualenv.py, am I missing something? |
Nope, Python 3.3 comes with a new py.exe command which runs "the appropriate Python" (see PEP 397 for the gory details). One thing it does is interpret #! lines in Python files. I tested the format you're using and it seems that py.exe works fine with it, so that's a bonus (as I say, I assume your main interest is scripts which use the setuptools exe wrapper). The whole py.exe thing is transparent to virtualenv, so nothing is needed in there. The main point is that your patch will handle more than just setuptools-style scripts, which is good. |
Ah, thank you for the clarification. Yes, I was focusing on the setuptools exe wrappers, which don't currently work correctly with --relocatable because:
I've tested this on XP (32-bit) and Win7 (32-bit and 64-bit) under Python 2.6.6 and 2.7.3 (as well as verifying that the output didn't change under a non-windows install via Mac OS X). If there's something else I should specifically verify please let me know, and if I can, I will. |
Checking further, the whole relocatable feature seems to be broken on Python 3. Maybe if this pull request was updated to include a fix for Python 3 it would be worth another look. Although I have to question how useful the feature is in general, if nobody has even noticed so far that it doesn't work on Python 3... |
Any chance that's as simple as doing this? change: |
Possibly :-) I've had to jump through all sorts of hoops in the past to cover edge cases like encodings, but they are quite possibly not relevant in this case. Presumably the exec(open()) version still works on Python 2? |
I ran the execfile(activate_this, dict(__file__=activate_this)) to exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)) While it seems the output from that should work in 2.x I did see some rumblings about 2.x not working as well with this code as using Unfortunately it doesn't look like calling lib2to3 from python is supported, so I guess this would do: activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); execfile(activate_this, dict(__file__=activate_this)); del os, activate_this"
if sys.version_info[0] > 2:
# ran activate through 2to3 (from 3.3.0)
activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); del os, activate_this" I have tested this let me create a relocatable env under 3.3.0, which I was able to move and still call the scripts in the bin dir as expected. Does this belong in this pull request (which @pnasrat requested in #49), or should I file a separate one? |
I do think |
Indeed if we have a feature it should work or degrade gracefully across all that being said working code can go in, even if incomplete as not all Paul
|
OK, thanks. This looks good now, I'll do a review of the latest changes before applying it. One point is that on Windows, this relies on at least some python being on |
In order to make this testable on Python 3, can you add the execfile fix to the patch? I made the fix manually, and I still hit issues:
Points 1 and 2 are issues with this patch, so should be addressed. Point 3 is more of a general example of the bugginess of relocatable virtualenvs. If you fix points 1 and 2, I'm willing to apply the patch as it at least makes I am considering adding a deprecation warning to |
I knew in order for the suggested python3 fix to work the unit tests need to be updated too. 2 is easy enough to fix. 1 and 3 already exist without this patch ( I have been using a version of this patch combined with #236 for over a year for what it's worth (probably not much). I'll try and see if I can capture some of the cases encountered in some new unit tests. |
The patch to address 3 seems pretty complex, from when I last looked at it, which is why I don't want to complicate this issue with it for now. For 1, if you're not happy providing a fix, I'm willing to leave it as is, and raise it as a separate item. Depending on what we end up implementing, I'll update the docs with some extra caveats/warnings (and I'll add a note that there's a possibility that this feature will be deprecated in future). |
I'll look into 1 and see what, if anything, I can come up with. |
Cool, thanks. As I said, I'd be happy to use |
I'm pretty sure the encoding issue was the only one I saw mentioned as well, so if you feel comfortable, I'll go with that. |
allow --relocatable to work on Windows
OK, I'll merge this then do the other bits of tidy up I mentioned as a followup. |
Addresses #49