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

Too much isolation with pdm run #733

Closed
1 task done
pawamoy opened this issue Nov 11, 2021 · 2 comments · Fixed by #734
Closed
1 task done

Too much isolation with pdm run #733

pawamoy opened this issue Nov 11, 2021 · 2 comments · Fixed by #734
Labels
🐛 bug Something isn't working

Comments

@pawamoy
Copy link
Contributor

pawamoy commented Nov 11, 2021

  • I have searched the issue tracker and believe that this is not a duplicate.

Following #708, it seems that the addition of the NO_SITE_PACKAGES does a bit too much.
What I understood is that Python packages installed in the interpreter or user site-packages would not be found.
But in practice, it seems that behavior leaks even in other virtualenvs, breaking compatibility with pipx for example.

Steps to reproduce

% pipx install -f pdm==1.10.0
Installing to existing venv 'pdm'
  installed package pdm 1.10.0, Python 3.9.7
  These apps are now globally available
    - pdm
done! ✨ 🌟 ✨

% pdm run pdm                
Usage: pdm [OPTIONS] [COMMANDS] ...

PDM - Python Development Master

Commands:
  {add,build,cache,completion,config,export,import,info,init,install,list,lock,plugin,remove,run,search,show,sync,update,use}
    add                 Add package(s) to pyproject.toml and install them
    build               Build artifacts for distribution
    cache               Control the caches of PDM
    completion          Generate completion scripts for the given shell
    config              Display the current configuration
    export              Export the locked packages set to other formats
    import              Import project metadata from other formats
    info                Show the project information
    init                Initialize a pyproject.toml for PDM
    install             Install dependencies from lock file
    list                List packages installed in the current working set
    lock                Resolve and lock dependencies
    plugin              Manage the PDM plugins
    remove              Remove packages from pyproject.toml
    run                 Run commands or scripts with local packages loaded
    search              Search for PyPI packages
    show                Show the package information
    sync                Synchronize the current working set with lock file
    update              Update package(s) in pyproject.toml
    use                 Use the given python version or path as base interpreter

Optional Arguments:
  -h, --help            show this help message and exit
  -V, --version         show the version and exit
  -v, --verbose         -v for detailed output and -vv for more detailed
  -I, --ignore-python   Ignore the Python path saved in the pdm.toml config
  --pep582 [SHELL]      Print the command line to be eval'd by the shell


% pipx install -f pdm==1.10.1
Installing to existing venv 'pdm'
  installed package pdm 1.10.1, Python 3.9.7
  These apps are now globally available
    - pdm
done! ✨ 🌟 ✨


% pdm run pdm                
Traceback (most recent call last):
  File "/home/pawamoy/.local/bin/pdm", line 5, in <module>
    from pdm.core import main
ModuleNotFoundError: No module named 'pdm'

The use of pdm here as the command is purely arbitrary. I get the same result with any tool installed through pipx, for example pdm run safety.

Actual behavior

When running a Python tool that is on the PATH, and that uses a virtualenv, a ModuleNotFoundError is raised.

Expected behavior

External Python tools (using completely separated virtualenvs) should not be impacted by this isolation. They are on the PATH after all.

Environment Information

# Paste the output of `pdm info && pdm info --env` below:
PDM version:        1.10.1
Python Interpreter: /home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.7.12/bin/python3.7 (3.7)
Project Root:       /media/data/dev/aria2p
Project Packages:   /media/data/dev/aria2p/__pypackages__/3.7
{
  "implementation_name": "cpython",
  "implementation_version": "3.7.12",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.14.16-arch1-1",
  "platform_system": "Linux",
  "platform_version": "#1 SMP PREEMPT Tue, 02 Nov 2021 22:22:59 +0000",
  "python_full_version": "3.7.12",
  "platform_python_implementation": "CPython",
  "python_version": "3.7",
  "sys_platform": "linux"
}
@pawamoy pawamoy added the 🐛 bug Something isn't working label Nov 11, 2021
@frostming
Copy link
Collaborator

You don't need pdm run if the executable is on the PATH. Maybe a flag will be added to pdm run but the default behavior is to load local packages only.

@pawamoy
Copy link
Contributor Author

pawamoy commented Nov 12, 2021

I don't need it, but it is applied anyway in the subcommands of a task runner for example.

# the task runner exec is in __pypackages__/*/bin, I need pdm run
pdm run TASKRUNNER COMMAND

...

# the task runner command runs pdm in a subprocess
requirements = ctx.run(["pdm", "export", "-f", "requirements", "--without-hashes"])
# but isolation is applied, so it ends up with a ModuleNotFoundError

Anyway, thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants