install-wheel: add support for specifying python startup flags#13
install-wheel: add support for specifying python startup flags#13eli-schwartz wants to merge 1 commit into
Conversation
2d14514 to
8c7405b
Compare
mgorny
left a comment
There was a problem hiding this comment.
Please don't forget to handle updates to your "prerequirement" upstream PR and finally file this as a PR for upstream.
| from installer.sources import WheelFile | ||
| from installer.utils import get_launcher_kind | ||
|
|
||
| from .scheme import Gpep517WheelDestination |
There was a problem hiding this comment.
I don't use relative imports. Be consistent.
| from __future__ import annotations | ||
|
|
||
| import contextlib, io, os, shlex, zipfile | ||
| import typing as T |
There was a problem hiding this comment.
Again, all this does is make files longer and more annoying to read, since most type annotations suddenly gain an additional 5 characters of overhead towards the max line length.
Either that or you spend more time managing individual from typing import Foo, Bar, Baz imports than you spend coding.
There was a problem hiding this comment.
In preparation for rebasing... I'd still like an answer about this.
I've found when reading and contributing to many python codebases that usage of symbols from the typing module tend to shift around a lot.
Importing typing and referencing typing.Iterable leads to overly long lines that are cramped and hard to read, especially if a line has more than one typing symbol on a single line (multiple parameters to a function definition, use of Union, container types such as Dict and List and Mapping that have other symbols inside). Tonaid in readability, I was introduced to, and gratefully started using myself, the convention to import typing as T which saves a lot of space. "T" is very recognizable and there aren't a lot of use cases for a one-character symbol other than that. The main other use case is for loop iteration, but that is usually "i" or "k, v". And anyways, the use of upper case is a well established convention for global constants, and the typing module is global and contains constants, so... :)
I think it's a good convention and it aids in readability, so if possible I'd like to be able to come to an agreement that this "as" import can stay and perhaps be used in other files as well.
There was a problem hiding this comment.
I've never done it in this project, or any of the other of my projects, and I never had a real need to. Hence, I don't see the point of suddenly changing this now.
| # with minor tweaks where classes don't have hooks to control their | ||
| # internals. | ||
|
|
||
| from __future__ import annotations |
There was a problem hiding this comment.
It is required to make if T.TYPE_CHECKING imports not be runtime errors. It is also a small performance improvement for all code that has type annotations, period.
Type annotations are not needed at runtime unless you're using something like beartype or pydantic. Building them into code objects and discarding them is a bit wasteful.
The import is equivalent to surrounding all type annotations with quotes. I find the future import to be more ergonomic, and could add it to other files if you like... ?
There was a problem hiding this comment.
Yeah, feel free to add them everywhere.
3e79825 to
2b65308
Compare
``` gpep517 install-wheel --shebang-flags='-s' ``` will cause all /usr/bin scripts to pass `-s` to the interpreter in its shebang. Useful for ensuring that system commands do not import mismatched modules from `pip install --user`. Also useful in theory to produce programs that run via -OO, something the python ecosystem rarely remembers is possible because scripts cannot be easily fine-tuned and short of changing the entrypoint script you cannot activate -O. Perhaps we could change that.
2b65308 to
07241af
Compare
|
Updated. |
|
Any update on what I should do here? Upstream PyPA/installer hasn't merged any PRs in months other than pre-commit.ci spam and isn't responsive to requests for review. Are we still waiting on them or is it fine to reimplement functionality locally? Are there any responses to the answers I gave on review comments where I disagreed with the review? |
|
@mgorny mind explaining why this PR was closed? I see a request for further comments from the author, with no replies. A little bit of more explanation would be nice. |
|
OP was requested to submit the pull request upstream. Nothing new has happened. |
|
It took ages for pypa/installer#200 to be merged and no answer was given to the questions directed to you above, including whether there's a need to wait for installer to merge every single change (which may take years) or not. Nor the other parts. |
|
The PR was merged eventually. |
|
Yes, eventually. pypa/installer#276 seems stuck now too. Let's please not wait on installer (where we've had various issues before, like with --prefix). Can you review this again? |
|
I'm also in support for not waiting for upstream, I suspect it would be easier to drop support when they do accept it (in some years). I would recommend to mention in the script docs, and the special argument passed, that they are temporary until upstream merges, so non-Gentoo projects that use gpep517 know this might break in the future. |
mgorny
left a comment
There was a problem hiding this comment.
Sure, I can live with it. Still, it needs to be rebased and the new code needs to follow the same coding style as the existing code.
|
|
||
| if forlauncher or simple: | ||
| shebang = '#!' + executable + post_interp_ | ||
| else: |
There was a problem hiding this comment.
Do we actually need this? I don't think we really expect Gentoo Python executables that long, or support spaces in EPREFIX. I get that it's upstream code, but since we're duplicating it, better duplicate less of it.
There was a problem hiding this comment.
I think so. There are people outside of Gentoo that use gpep517, e.g. on the distro side Alpine. But also I've mentioned it a few times to people in #python and similar when the topic of installing wheels without pip has come up, and they have found it interesting and useful.
| # gpep517: use build_shebang | ||
| new_stream.write(build_shebang(interpreter, False, flags) + b'\n') | ||
| # copy the rest of the stream | ||
| stream.seek(0) |
There was a problem hiding this comment.
Is this really necessary? Logically saying, we've just read #!python without the newline, so readline() without seeking should yield the same result.
There was a problem hiding this comment.
Indeed, I think you're correct. It's a small saving but correct to avoid. I suppose the installer sources copied it from the else branch (where it is necessary to rewind to the beginning) but I'm still not sure why. :D
| while True: | ||
| buf = stream.read(_COPY_BUFSIZE) | ||
| if not buf: | ||
| break | ||
| new_stream.write(buf) |
There was a problem hiding this comment.
This looks like reinventing shutil.copyfileobj().
There was a problem hiding this comment.
Yes... I quite agree. It appears to be blindly copied from copyfileobj_with_hashing, another function from the installer codebase which at least had a good reason to exist.
Yup, I see that since 4d9f6e9 the code I modified has made other changes that lead to merge conflicts. (Same basic idea though -- applying our own scheme handler.) After the weekend I will see about finding time to sort that out, and update the PR to base itself off of that.
I'm not sure what you mean by that. We don't -- never have and probably never will -- import upstream's I don't see any reason to mark a gpep517 CLI argument as temporary. Upstream changes will only affect our ability to reuse new library APIs instead of designing them ourselves. |
will cause all /usr/bin scripts to pass
-sto the interpreter in its shebang. Useful for ensuring that system commands do not import mismatched modules frompip install --user.Also useful in theory to produce programs that run via -OO, something the python ecosystem rarely remembers is possible because scripts cannot be easily fine-tuned and short of changing the entrypoint script you cannot activate -O. Perhaps we could change that.