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

sitecustomize.py does not respect project_max_depth #1413

Closed
1 task done
xulongwu4 opened this issue Oct 3, 2022 · 2 comments · Fixed by j178/pdm#1
Closed
1 task done

sitecustomize.py does not respect project_max_depth #1413

xulongwu4 opened this issue Oct 3, 2022 · 2 comments · Fixed by j178/pdm#1
Labels
🐛 bug Something isn't working

Comments

@xulongwu4
Copy link
Contributor

xulongwu4 commented Oct 3, 2022

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

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

  1. Create a project with 5 level of sub-folders and then init the project:
$ mkdir -p project/1/2/3/4/5
$ cd project
$ pdm init

I chose python3.7 as the interpreter for this demonstration.

  1. Make sure PEP582 is enabled globally
$ echo $PYTHONPATH
/home/oulongwu/.local/share/pipx/venvs/pdm/lib/python3.10/site-packages/pdm/pep582
  1. Make sure project_max_depth is set to a big value
$ pdm config
Site/default configuration (/usr/share/xdg/pdm/config.toml):
build_isolation = True
cache_dir = /home/oulongwu/.cache/pdm
check_update = True
global_project.fallback = False
global_project.fallback_verbose = True
global_project.path = /home/oulongwu/.config/pdm/global-project
global_project.user_site = False
install.cache = False
install.cache_method = symlink
install.parallel = True
project_max_depth = 5
pypi.json_api = False
pypi.url = https://pypi.org/simple
pypi.verify_ssl = True
python.use_pyenv = True
python.use_venv = True
strategy.resolve_max_rounds = 10000
strategy.save = minimum
strategy.update = reuse
venv.backend = virtualenv
venv.in_project = True
venv.location = /home/oulongwu/.local/share/pdm/venvs

Home configuration (/home/oulongwu/.config/pdm/config.toml):
project_max_depth = 20

Project configuration (/home/oulongwu/Documents/gitlab/Platform/.pdm.toml):
python.path = /home/oulongwu/.local/share/pyenv/shims/python3

I set project_max_depth to 20.

  1. Check sys.path
$ cd 1/2/3/4/5
$ python3.7 -c "import sys; print(sys.path)"
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/lib/python3.7/site-packages']

$ pdm run python3.7 -c "import sys; print(sys.path)"
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/home/oulongwu/tmp/project/__pypackages__/3.7/lib']

Actual behavior

As one can see, when I ran python3.7 directly, I don't get the __pypackages__ folder in my sys.path. However, when I ran pdm run python3.7, __pypackages__ is in my sys.path.

#645 made the project's max depth a configurable parameter. This works well when I invoke the python interpreter with pdm run python3. However, when I enabled PEP582 globally and then ran python3, I found that the project depth is still at its default value (5). This is due to pep582/sitecustomize.py does not take the configured value of project_max_depth.

Expected behavior

I expect the project_max_depth is respected when I enable PEP582 globally.

Environment Information

# Paste the output of `pdm info && pdm info --env` below:

$ pdm info
PDM version:
  2.1.4
Python Interpreter:
  /usr/bin/python3 (3.10)
Project Root:
  /home/oulongwu/tmp/project
Project Packages:
  /home/oulongwu/tmp/project/__pypackages__/3.10

$ pdm info --env
{
  "implementation_name": "cpython",
  "implementation_version": "3.10.6",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.15.68-218.current",
  "platform_system": "Linux",
  "platform_version": "#1 SMP PREEMPT Sat Sep 17 01:51:42 UTC 2022",
  "python_full_version": "3.10.6",
  "platform_python_implementation": "CPython",
  "python_version": "3.10",
  "sys_platform": "linux"
}
@xulongwu4 xulongwu4 added the 🐛 bug Something isn't working label Oct 3, 2022
@frostming
Copy link
Collaborator

This is just for convenience, the original specification of PEP 582 doesn't even allow looking for the parent directories. Moreover, the PDM configuration can't be easily passed to the Python interpreter.

Therefore, stick to pdm run if the depth exceeds 5. We will not improve this, unless the PEP 582 is revised to suggest so.

@frostming frostming closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2022
@xulongwu4
Copy link
Contributor Author

I think it sounds fair that it is not easy to pass PDM config to the python interpreter. However, I do have two suggestions:

  1. Since PDM will read the PROJECT_MAX_DEPTH environment variable, can we let the sitecustomize.py read the same environment variable so that there is one way to sync the maximum depth between the two?
  2. If the above is still impossible, can we set the default depth in sitecustomize.py to a larger value so that it is less likely that people will run into this issue. After all, 5 is a really low value here, and I believe there is a decent chance that a project has more than 5 levels of sub folders.

frostming pushed a commit that referenced this issue Nov 1, 2022
…ronment variable. Resolves #1413. (#1480)

* Make sitecustomize.py respect PDM_PROJECT_MAX_DEPTH

* Add a news entry
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