-
-
Notifications
You must be signed in to change notification settings - Fork 236
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
Use reusable venvs #199
base: main
Are you sure you want to change the base?
Use reusable venvs #199
Conversation
3bc32f9
to
e20c4a3
Compare
e20c4a3
to
6a26af9
Compare
The next step IMO is to add a cli subcommand for creating a hacked venv, before running a full build. This involves splitting the build process a bit, enough to decompress the standalone Python distribution to disk so it can be used for the venvs. I was working on this, but that section of code was being heavily revised so I dropped it in order to get this PR up. |
Here is the macOS failure with |
73733b1
to
583cc48
Compare
814309a
to
5fea374
Compare
While I can get farther in my problems with #202 it's not a complete solution. I have to put the same |
I think supporting reusing a virtualenv makes sense. But I'm going to hold off reviewing and landing this because I'm overhauling how the config files work and it will be much easier to do advanced things once that work is done. My plan is to leverage Starlark as a "scripting" language and for the config files to more resemble Python scripts than static data structures. e.g. the packaging rules will be attached to the |
@indygreg , I'm almost finished getting cryptography working on all platforms, and need a bit of time to tidy up and re-push here. Please could you please avoid conflicting me by fiddling in the same part of the codebase. It causes useless merge conflicts for me, and the changes you are making do not help solve the problem. The real problems are not here -- they are indygreg/python-build-standalone#19 and indygreg/python-build-standalone#22 - I have workarounds for those, but real fixes for those are desperately needed. |
Don't worry about resolving the merge conflicts: I will rebase your PRs for you. |
120aa64
to
6a1fd91
Compare
@indygreg , I'd rather do the rebasing myself, and have purple PRs in my history than lots of red ones and need to go figure out what changes you've made to my code. |
I've done a quick push of what I have. There are still some bits that are no longer needed, to be removed. I'll lightly annotate it now. |
- ${{ if eq(parameters.name, 'Linux') }}: | ||
- script: | | ||
cargo run --bin pyoxidizer -- init --pip-install cryptography ~/pyapp | ||
cat ci/pyapp.py | cargo run --bin pyoxidizer -- run ~/pyapp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#208 is needed for all of these enhancements to the sample app CI. This approach is taken because otherwise the lines are very long, and also to avoid horrid Windows CMD quoting problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix included in #200
displayName: Build Oxidized Application | ||
|
||
- ${{ if eq(parameters.name, 'macOS') }}: | ||
- script: brew install [email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unnecessary, as it is pre-installed, but it is only a few seconds. Happy to remove it though.
- ${{ if eq(parameters.name, 'Windows') }}: | ||
- task: UsePythonVersion@0 | ||
inputs: | ||
versionSpec: '3.7' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is necessary because the windows job needs a functional Python, mostly due to indygreg/python-build-standalone#22
indygreg/python-build-standalone#19 is also problematic, but it can be worked around by using virtualenv
instead of venv
. Currently the code in the PR does use virtualenv
because I was initially attempting to use the standalone python, but cffi put a halt to that plan, so I am going to rip that out so that all OS use venv
, simplifying a few areas of the changes.
@@ -0,0 +1,15 @@ | |||
import cryptography.fernet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is copied from jamesabel/spafit#2
It is a good smoketest for basic cryptography.
.unwrap() | ||
.display() | ||
.to_string(); | ||
if site_packages_s.starts_with("\\\\?\\") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prefix is added by Path.canonicalize
, and I wasnt sure if Python could handle it.
I'm not sure if this is necessary. Need to try removing it.
Also it seems I need to set PYTHONHOME
. I've seen warnings that it wasnt set whilst pip is installing stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read venv bin/activate
again, and I am not sure about PYTHONHOME
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message I had seen is appearing on macOS only, and is
...
modifying distutils/unixccompiler.py for oxidation
creating venv /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pyoxidizer-temp-venv.TMkXswfSsJy9/venv
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Collecting gevent
Downloading ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we are seeing some effects of https://bugs.python.org/issue22213 - when I used virtualenv
instead of venv
, the problem goes away.
fs::create_dir_all(&python_paths.pyoxidizer_state_dir).unwrap(); | ||
|
||
extra_envs.insert( | ||
"PYOXIDIZER_DISTUTILS_STATE_DIR".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is moved out of distutils.rs because most of the venv environ stuff is here, and it feels a bit odd to getting only a single path returned from prepare_hacked_distutils
and that value does not need to be any specific value for the distutils hack to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also being able to run commands in the venv outside of PyOxidizer provides a lot of flexibility not currently possible with the config file. For that to happen either:
- the distutils hacking pushes the state directory name into the .py files, or
- the distutils .py and rust code both use the same state directory path
I have opt for the latter, as that seems to be more appropriate in a venv which has a 'prefix'
@@ -694,6 +955,8 @@ pub fn analyze_python_distribution_data( | |||
}; | |||
} | |||
|
|||
let venv_base = dist_dir.parent().unwrap().join("hacked_base"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"hacked_base" probably should be given a better name
); | ||
|
||
let orig_distutils_path = dist.stdlib_path.join("distutils"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a separate bug, but it doesnt seem useful to split it off to a separate commit: distutils can not be anywhere - it must be the real one, as setuptools hunts for the real one, even navigating through a venv to find it.
296b083
to
13e08f6
Compare
8f998b7
to
5c5ac33
Compare
5e0524b
to
789c62e
Compare
Replace pip install --target with venvs.
As setuptools breakes out of the venv to load distutils build_ext
command, first create a copy of the Python distribution and hack
it.
This also has the benefit that the venv can be used to build
extensions outside of PyOxidizer.
Also add venv_path to PipRequirementsFile, allowing the same
venv to be incrementally populated in multiple rules,
and the venv re-used across PyOxidizer build runs.
Fixes #162
Fixes #170
Closes #194