-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
python module: add option to specify a python environment to install to #9788
python module: add option to specify a python environment to install to #9788
Conversation
/cc @rgommers @tristan957 for expressing interest in the topic |
Codecov Report
@@ Coverage Diff @@
## master #9788 +/- ##
==========================================
+ Coverage 66.55% 67.76% +1.21%
==========================================
Files 400 402 +2
Lines 85122 85550 +428
Branches 18750 18821 +71
==========================================
+ Hits 56651 57976 +1325
+ Misses 24075 23072 -1003
- Partials 4396 4502 +106
Continue to review full report at Codecov.
|
@jpakkane what are your thoughts on merging this for 0.61? Although it's past rc1, I forgot to submit this first... :( and it is behavior-preserving but should make things a lot more comfortable for python modules adopting meson, e.g. script. I believe that this change should not cause surprises or breakage as it's very narrowly scoped. But it should definitely go in an rc2 first. |
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.
Thanks @eli-schwartz! This works like a charm. It'd be great to get this in 61.0
, because it makes it possible to install a Python package into site-packages correctly without manually setting the prefix to the active Python interpreter's lib
directory.
I've tested all four options within a conda
environment on Arch Linux, and it all works as expected.
It also takes care of avoiding these warnings in my development workflow:
WARNING: Python files installed by Meson might not be found by python interpreter.
This warning can be avoided by setting "python.platlibdir" option.
WARNING: Python files installed by Meson might not be found by python interpreter.
This warning can be avoided by setting "python.purelibdir" option.
My only code review comment (not large/blocking) is to make the description of system
somewhat clearer.
Two other thoughts/questions:
What do you think about this superceding the separate purelibdir
/platlibdir
options? I'm not sure there's a use for them after this feature lands, and they're badly thought out and Linux-specific concepts to begin with.
Regarding the default, it's understandable (but a little unfortunate) that it has to be prefix
because of backwards compat. For any Python package that's always wrong (hence auto
will never select prefix
). But given that most Python devs will not be using the meson
CLI but pip install .
or some such thing, it's hopefully not too much of a problem in practice.
It is now possible to specify `-Dpython.install_env` and choose how python modules are installed. | ||
|
||
- `venv`: assume that a virtualenv is active and install to that | ||
- `system`: install to the global site-packages |
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 may be hard to understand (it could be the conda/homebrew/etc one or the actual system provided one - you mean the former here). How about something like "install to the site-packages of the active Python interpreter (if a virtualenv, this means the Python it is derived from)"?
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 think maybe I was thinking of that when I used the word "global", which has the connotation, to me, of "non-venv" but still within the interpreter.
What about this change?
-- `system`: install to the global site-packages
+- `system`: install to the global site-packages of the selected interpreter
+ (the one that the venv module calls --system-site-packages)
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.
That looks good, it's quite clear.
docs/markdown/Builtin-options.md
Outdated
|
||
*Since 0.61.0* The `python.install_env` option is used to detect the correct | ||
installation path. Setting to `system` will avoid making the paths relative to | ||
`prefix`. Setting to `venv` will instead use the paths for the virtualenv the |
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 needs explanation of what system
actually does do (see my comment on line 6 of python_module_env.md
).
bad841d
to
622c530
Compare
I'm not entirely sure what the precise use case for them would be either. Although I guess in theory they serve a similar role as --prefix and friends if you want to control install paths with absolute precision.
I'd be willing to discuss changing the default in the future. But I do think that we need the option in the end, because users may use |
Yes I agree that |
Policy says that after rc1 only bug fixes are allowed, no new features. So sadly this will have to wait until the next release. |
I think they are still needed for the case you install into prefix, which is still what you want on Linux. It is not linux-only neither, as long as you know to set PYTHONPATH when running your app, it's fine to install into your app's prefix even on Windows. I personally would even recommend doing that TBH. |
I'm talking about I think you are talking here about the regular purelib/platlib specified as |
They could be relative to prefix too, IIRC. But seems that's not actually documented that way... |
install_dir can always be absolute or relative, and in the latter case it is relative to prefix. And I am pretty sure all path options other than prefix either can be relative or must be relative, and do so in relation to prefix. As I said above,
Perhaps users are baking an installer package whose launcher sets up PYTHONPATH, idk. I haven't given much thought to it yet. |
I use Okay, since it's not directly related to this PR, I'll shut up about it now. I just know I'm going to have to talk about Meson to a ton of people over the next year, so 2 out of 3 Python specific CLI options (after this PR is merged) being irrelevant to all of those people is not too helpful. |
This whole situation and the band-aids on top of it are irrelevant in my opinion because Meson shouldn't be in the business of warning people about where they are installing files. Meson going out of its way to make bad Python distributors happy is only hurting Meson. Python developers/users are well aware of PYTHONPATH and can use it appropriately when installing outside of places that the Python interpreter can't, by default, see. Is there anyone outside of Debian who has even complained about this? I still don't even understand the necessity. Is there a bug report I can read? |
NGL, I really am incredibly tempted to remove the warning altogether. Especially given that ever since commit 05b5a1e we should not be getting this wrong (or not any more so on Debian than any environment in which install_env=prefix is problematic). So it really feels like the warning has run its course. |
We should just force Debian to keep a Meson patch to fix this. Let them live with their decisions. |
@FRidh could confirm it, but my understanding is that NixOS also needs the status quo behavior or explicit e.g. https://github.com/pradyunsg/installer/issues/98 |
That seems correct to me. sysconfig does not contain the correct prefix for us so we need to replace it with a prefix whenever we install something into a Nix store path. See e.g. the following solution https://github.com/NixOS/nixpkgs/pull/105714/files#diff-6845adc675c162d94bec555a24f0486cb2688af7fdd7f7627a25dd53a9a7a23fR75. |
…ified Needed to check exclusivity of module options.
The default behavior of installing relative to prefix may be unexpected, and is definitely wrong in many cases. Give users control in order to specify that yes, they actually want to install to a venv. This is particularly useful for projects that use meson as a build system for a python module, where *all* files shall be installed into the python site-packages.
0e60f05
to
78945fb
Compare
xclaesse gave a lgtm via IRC. |
The default behavior of installing relative to prefix may be unexpected, and is definitely wrong in many cases.
Give users control in order to specify that yes, they actually want to install to a venv.
This is particularly useful for projects that use meson as a build system for a python module, where all files shall be installed into the python site-packages.