-
Notifications
You must be signed in to change notification settings - Fork 190
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
[WIP] Use preferences.jl to set python executable #945
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #945 +/- ##
==========================================
- Coverage 68.33% 67.80% -0.53%
==========================================
Files 20 21 +1
Lines 2018 2047 +29
==========================================
+ Hits 1379 1388 +9
- Misses 639 659 +20
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
TODO:
|
I'd suggest PyPreferences. I think it'd be nice if all the code currently in the @stevengj What do you think? You seemed to prefer merging PyPreferences to PyCall instead, in #835. |
I'd also like to know if dripping pre 1.6 compatibility is on the table. |
I think it's fine to drop 1.6 support going forward. |
667ed10
to
6a92054
Compare
gitignore
remove artifact remove build phase start adapting CI fix ci fix ci fix ci fix ci fix ci conda fixes fix conda ci stop testing on 1.0 remove testers fix fix aot ci fixes dont test build fixes fix venv test refactor PyPreferences use env variable pyprefs project fix fixes stuff test fix conda revert changes fix cng fix python version custom which to work in julia 1.6 make test work with python 2 fixup docs
3218757
to
d9da069
Compare
One problem I encountered is the following: Right now the preference for However, if an user changes the One thing that can be done is to normalise the python executable to a path before storing it in the preferences. A better way would be to add the hash of the current python executable path to the cache invalidation mechanism, so that if the executable changed we trigger a recompile, but I do not know if that is possible (maybe @StefanKarpinski who worked on this knows?).. -- Lastly: I don't have access to a windows machine to test the failures of |
I think @staticfloat would be the person to comment since he implemented Preferences (I consulted on design but didn't do any of the implementation). |
Here's how I would address this: When you save the preference out, you always normalize it to a full path. If the user edits a TOML to change the value to a PATH-relative basename, that will trigger recompilation, and while compiling (e.g. at the top level) you will normalize and save it out again. E.g. something like: function save_python_path(path::String)
if !isabspath(path)
which_path = Sys.which(path)
if which_path === nothing
error("Couldn't find python executable at $(path)")
end
end
@set_preferences!("PYTHON" => path)
end
python_path = @get_preference("PYTHON")
if !isabspath(python_path)
save_python_path(python_path)
end
Base.include_dependency(python_path) So usage might go something like this:
If you want to recompile if the python executable itself changes, the best we can do is to use |
I was trying to test this PR but with no success---do I need a different version of What I tried was |
Ping. What's the status of this PR? This is badly needed. Downstream, several users have ran into bugs in my packages because of this:
|
Im not working in Julia anymore unfortunately, as Jax has captured my attention and that of my colleagues. Feel free to pick it up. I remember there being agreement in the fact that this should be done, but it was hard to get hold of the maintainers... |
Sad to hear you left Julia (why not both 😉?) but thanks for updating me on the PR status. For others needing something like this due to PyCall.jl build issues (e.g., if you change Python version) – you might be interested in a similar workaround to the one implemented in PySR: MilesCranmer/PySR#363. Thanks @mkitti for the idea. Basically: import Pkg
Pkg.activate("pysr..."; shared=true)
ENV["PYTHON"] = "/path/to/python"
Pkg.build("PyCall") will trigger PyCall to rebuild when you switch Python versions. It doesn't fix things if you switch back and forth Python versions, but it's good enough for my target demographic who might upgrade Python once a year and wonder why PySR is breaking. |
This PR is a re-exhumation of #835, and most of the credit goes to @tkf .
An internal package
PyPreferences.jl
exposes a simple API (use_system()
,use_conda()
) to set the current python, and detects version/pythonhome so that this code can be removed from the build phase of PyCall.Since it stores those options using
Preferences.jl
, changing the python executable will trigger a recompilation.Unfortuantely, as Preferences.jl only works on Julia>=1.6, this means that either we leave in place the old build machinery for older Julia versions and switch to the new one only on recent Julia versions, or we drop support for Julia <1.6. This would involve considerable more work and would make testing more complex.
Is dropping support an option?
I'm going to put this up so that I can see how badly CI fails..
Another thing to consider: With respect to
PkgCompiler.jl
, do we wantPyCall
to support changing the executable path/version after compilation or that is not required?