Skip to content
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

pipx run produces PermissionError when combined with bash process substitution #1292

Open
Bobronium opened this issue Mar 17, 2024 · 0 comments · May be fixed by #1293
Open

pipx run produces PermissionError when combined with bash process substitution #1292

Bobronium opened this issue Mar 17, 2024 · 0 comments · May be fixed by #1293
Labels
awaiting response Awaiting re-engagement by contributor enhancement New feature or request

Comments

@Bobronium
Copy link

Bobronium commented Mar 17, 2024

Describe the bug
Attempting to run a Python script through bash process substitution with pipx results in a PermissionError. The same script runs without issues when executed directly with Python. This indicates a potential issue with how pipx handles file descriptors or temporary files created by process substitution.

How to reproduce
Install pipx==1.4.3

$ pip install pipx-in-pipx
$ pipx inject pipx pipx==1.4.3
$ pipx run <(echo 'print("Hello World!")')
Traceback (most recent call last):
  File "/Users/bobronium/.local/bin/pipx", line 8, in <module>
    sys.exit(cli())
  File "/Users/bobronium/.local/pipx/venvs/pipx/lib/python3.10/site-packages/pipx/main.py", line 921, in cli
    return run_pipx_command(parsed_pipx_args)
  File "/Users/bobronium/.local/pipx/venvs/pipx/lib/python3.10/site-packages/pipx/main.py", line 204, in run_pipx_command
    commands.run(
  File "/Users/bobronium/.local/pipx/venvs/pipx/lib/python3.10/site-packages/pipx/commands/run.py", line 205, in run
    run_package(
  File "/Users/bobronium/.local/pipx/venvs/pipx/lib/python3.10/site-packages/pipx/commands/run.py", line 141, in run_package
    run_pypackage_bin(pypackage_bin_path, app_args)
  File "/Users/bobronium/.local/pipx/venvs/pipx/lib/python3.10/site-packages/pipx/util.py", line 102, in run_pypackage_bin
    exec_app(
  File "/Users/bobronium/.local/pipx/venvs/pipx/lib/python3.10/site-packages/pipx/util.py", line 385, in exec_app
    os.execvpe(str(cmd[0]), [str(x) for x in cmd], env)
  File "/Users/bobronium/.pyenv/versions/3.10.1/lib/python3.10/os.py", line 583, in execvpe
    _execvpe(file, args, env)
  File "/Users/bobronium/.pyenv/versions/3.10.1/lib/python3.10/os.py", line 596, in _execvpe
    exec_func(file, *argrest)
PermissionError: [Errno 13] Permission denied: '/dev/fd/11'

Expected behavior

Pipx should execute the script provided through process substitution, printing "Hello World!" to the console, similar to the direct Python execution:

$ python <(echo 'print("Hello World!")')
Hello World!

Context
Supporting this behaviour would allow to run scripts in-place using a clipboard:

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "requests<3",
#   "rich",
# ]
# ///

import requests
from rich.pretty import pprint

resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])
$ pipx run <(pbpaste)
@Bobronium Bobronium linked a pull request Mar 17, 2024 that will close this issue
1 task
@Gitznik Gitznik added enhancement New feature or request awaiting response Awaiting re-engagement by contributor labels Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Awaiting re-engagement by contributor enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants