Skip to content

Assortment of misuse checks - #8570

Merged
bwoodsend merged 5 commits into
pyinstaller:developfrom
bwoodsend:block-admin-misuse
May 30, 2024
Merged

bwoodsend merged 5 commits into
pyinstaller:developfrom
bwoodsend:block-admin-misuse

Conversation

@bwoodsend

Copy link
Copy Markdown
Member

Having to explain each of these on a regular basis makes me question my life choices.

bwoodsend added 3 commits May 28, 2024 17:30
If a regular user uses sudo or *run as admin* to run PyInstaller with
unnecessary privileges, warn them not too, with the intention of turning it
into an error in the next breaking release.
For the users who figured out how to open a terminal as admin but never
learnt the cd command. In practice, these users are likely still doomed
but at least we can prevent them from writing build files into
C:\Windows\system32
@bwoodsend
bwoodsend force-pushed the block-admin-misuse branch from 510aa52 to 4f911e2 Compare May 28, 2024 16:31
@rokm

rokm commented May 28, 2024

Copy link
Copy Markdown
Member

Nice!

There's another idea if you have time: if PyInstaller is invoked as just pyinstaller (or pyinstaller.exe), search PATH, and if there are multiple instances found, tell the user that they should specify a full path to the shim (or invoke as a module with their active python evnironment).

@bwoodsend

Copy link
Copy Markdown
Member Author

Yeah, why not. Just a logger.warning() though, right? I don't want to block people who manage to have pyinstaller in both a global and venv environment without hitting XKCD-1987.

Reckon:

[shutil.which("pyinstaller", path=i) for i in os.environ.get("PATH", "").split(os.pathsep)]

is a close enough approximation of which -a pyinstaller? Strictly speaking, it would miss one if pyinstaller.exe and pyinstaller.bat were in the same directory but we can probably live with that.

@rokm

rokm commented May 29, 2024 •

Copy link
Copy Markdown
Member

Yeah, why not. Just a logger.warning() though, right? I don't want to block people who manage to have pyinstaller in both a global and venv environment without hitting XKCD-1987.

I was actually thinking of eventually raising an error, to force the user to think about the ambiguity and resolve it; either by using full path, by using module invocation, or by sanitizing their PATH.

Or maybe alternatively have them set an I_KNOW_WHAT_I_AM_DOING environment variable to suppress the warning/error.

Reckon:

[shutil.which("pyinstaller", path=i) for i in os.environ.get("PATH", "").split(os.pathsep)]

is a close enough approximation of which -a pyinstaller?

Yeah, that looks like it should do the trick. And is much more elegant that what I had in mind.

Strictly speaking, it would miss one if pyinstaller.exe and pyinstaller.bat were in the same directory but we can probably live with that.

True, but that is not the situation we are trying to catch here.

@bwoodsend

Copy link
Copy Markdown
Member Author

I don't think I can differentiate between someone using a full path and a PATH lookup. sys.argv[0] is always C:\users\brenainn\AppData\Local\Programs\Python\Python311\Scripts\pyinstaller.

@rokm

rokm commented May 29, 2024

Copy link
Copy Markdown
Member

Hmmm, you're right. I was under mistaken impression that argv[0] would behave in the same way as in a C-compiled executable. Don't bother with it, then - the main point of the idea was to catch PATH lookup with multiple candidates.

@bwoodsend

Copy link
Copy Markdown
Member Author

It's also a bit messy with pyenv. With pyenv, you don't add sys.prefix/bin to PATH. Instead you add ~/.pyenv/shims to PATH and there are more shims in there which exec the corresponding shim from the currently active Python environment. Unfortunately, the pyenv shims prepend sys.prefix/bin to PATH before the exec so we always have two shims in PATH – even though one is just a glorified redirect to the other.

> which -a pyinstaller
/home/brenainn/.pyenv/shims/pyinstaller

> pyinstaller
2 WARNING: Found multiple pyinstaller commands installed and in PATH:
['/home/brenainn/.pyenv/versions/3.12.0/bin/pyinstaller',
 '/home/brenainn/.pyenv/shims/pyinstaller']

> ~/.pyenv/versions/3.12.0/bin/pyinstaller
# No warning because only ~/.pyenv/shims is in PATH
usage: pyinstaller [-h]

@rokm

rokm commented May 30, 2024

Copy link
Copy Markdown
Member

Yeah, let's scrap the idea, then.

@bwoodsend
bwoodsend marked this pull request as ready for review May 30, 2024 17:50
@bwoodsend
bwoodsend requested a review from rokm May 30, 2024 17:50
Comment thread PyInstaller/building/build_main.py Resolved
bwoodsend added 2 commits May 30, 2024 22:12
And add some XKCD-1987 themed *current python environment* hints into the
logs.
pytest-dev/pytest#11233 overloaded pytest's summary parameter to make it
also add tracebacks for xfailed tests. This makes finding the real
failures amongst the new xfail error messages painful. Disable this
which unfortunately means that we also loose the xfails and xpasses from
the short test summary.
@bwoodsend
bwoodsend force-pushed the block-admin-misuse branch from 4f911e2 to 54e2112 Compare May 30, 2024 21:13
@bwoodsend
bwoodsend enabled auto-merge (rebase) May 30, 2024 21:28
@bwoodsend
bwoodsend merged commit 3fa8181 into pyinstaller:develop May 30, 2024
@bwoodsend
bwoodsend deleted the block-admin-misuse branch May 31, 2024 08:37
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants