Repository: pdm-project/pdm

Issue:
Regression in PDM 2.2.0 using dynamic version and Hatch build backend
- [x] 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

<!--Describe the minimized example of how to reproduce the bug-->

I have a package using PDM for its dependencies, Hatch for its PEP-517 build backend. The project also uses `dynamic = ["version"]` for deriving version information from Git, and has a maximum Python version.

Note that all of the above seem to be necessary to reproduce the issue; I couldn't reproduce it with pdm-pep517, without dynamic version, and I couldn't reproduce it if `requires_python` only had a minimum python version and no maximum.

In PDM 2.1.5, this worked fine. In PDM 2.2.0, I can no longer install as it appears to be trying to calculate a dynamic version, but the `setuptools_scm` dependency for dynamic version generation isn't installed in that environment.

Here's a minimal example `pyproject.toml`:

```toml
[project]
name = "pdm-pep517-regression"
dynamic = ["version"]
description = ""
authors = [
    {name = "Brian Campbell", email = "brcampbell@beta.team"},
]
requires-python = ">=3.9, <3.10"
readme = "README.md"
license = {text = "MIT"}
dependencies = []

[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "vcs"
```

## Actual behavior

<!--A clear and concise description the result of the above steps-->

```
[brcampbell@beta-0535 pdm-pep517-regression]$ pdm install -v
All packages are synced to date, nothing to do.
Installing the project as an editable package...
pdm.termui: Preparing isolated env for PEP 517 build...
pdm.termui: Running PEP 517 backend to build a wheel for <Link file:///home/brcampbell/tmp/pdm-pep517-regression (from None)>
pdm.termui: ======== Start resolving requirements ========
pdm.termui:   hatch-vcs
pdm.termui:   hatchling
pdm.termui:   python>=3.9.14,<3.9.15
pdm.termui:   Adding requirement hatch-vcs
pdm.termui:   Adding requirement hatchling
pdm.termui:   Adding requirement python>=3.9.14,<3.9.15
pdm.termui: ======== Starting round 0 ========
pdm.termui: Pinning: python None
pdm.termui: ======== Ending round 0 ========
pdm.termui: ======== Starting round 1 ========
pdm.termui:   Adding requirement hatchling>=0.21.0(from hatch-vcs 0.2.0)
pdm.termui: Pinning: hatch-vcs 0.2.0
pdm.termui: ======== Ending round 1 ========
pdm.termui: ======== Starting round 2 ========
pdm.termui:   Adding requirement editables>=0.3(from hatchling 1.11.1)
pdm.termui:   Adding requirement packaging>=21.3(from hatchling 1.11.1)
pdm.termui:   Adding requirement pathspec>=0.10.1(from hatchling 1.11.1)
pdm.termui:   Adding requirement pluggy>=1.0.0(from hatchling 1.11.1)
pdm.termui:   Adding requirement tomli>=1.2.2; python_version < "3.11"(from hatchling 1.11.1)
pdm.termui: Pinning: hatchling 1.11.1
pdm.termui: ======== Ending round 2 ========
pdm.termui: ======== Starting round 3 ========
pdm.termui: Pinning: editables 0.3
pdm.termui: ======== Ending round 3 ========
pdm.termui: ======== Starting round 4 ========
pdm.termui:   Adding requirement pyparsing!=3.0.5,>=2.0.2(from packaging 21.3)
pdm.termui: Pinning: packaging 21.3
pdm.termui: ======== Ending round 4 ========
pdm.termui: ======== Starting round 5 ========
pdm.termui: Pinning: pathspec 0.10.1
pdm.termui: ======== Ending round 5 ========
pdm.termui: ======== Starting round 6 ========
pdm.termui: Pinning: pluggy 1.0.0
pdm.termui: ======== Ending round 6 ========
pdm.termui: ======== Starting round 7 ========
pdm.termui: Pinning: tomli 2.0.1
pdm.termui: ======== Ending round 7 ========
pdm.termui: ======== Starting round 8 ========
pdm.termui: Pinning: pyparsing 3.0.9
pdm.termui: ======== Ending round 8 ========
pdm.termui: ======== Starting round 9 ========
pdm.termui: ======== Resolution Result ========
pdm.termui: Stable pins:
pdm.termui:      python None
pdm.termui:   hatch-vcs 0.2.0
pdm.termui:   hatchling 1.11.1
pdm.termui:   editables 0.3
pdm.termui:   packaging 21.3
pdm.termui:    pathspec 0.10.1
pdm.termui:      pluggy 1.0.0
pdm.termui:       tomli 2.0.1
pdm.termui:   pyparsing 3.0.9
pdm.termui: Installing hatch-vcs 0.2.0
unearth: Downloading <Link https://files.pythonhosted.org/packages/7d/47/73ff0d30c4fa8b175db04a104a55dbe7d2050632262575efe02b8e2c8e2b/hatch_vcs-0.2.0-py2.py3-none-any.whl (from None)> to /tmp/pdm-build-zyl05vck/hatch_vcs-0.2.0-py2.py3-none-any.whl
pdm.termui: Installing hatchling 1.11.1
unearth: Downloading <Link https://files.pythonhosted.org/packages/d3/af/8feac1326463c275d431e7331695f24a34b508fa046288bad289ff0967f2/hatchling-1.11.1-py3-none-any.whl (from None)> to /tmp/pdm-build-lg0g71u6/hatchling-1.11.1-py3-none-any.whl
pdm.termui: Installing editables 0.3
unearth: Downloading <Link https://files.pythonhosted.org/packages/ef/8c/87276afb1ba3193c4c05be83965a1e69b8a14821ce6d688464071b179383/editables-0.3-py3-none-any.whl (from None)> to /tmp/pdm-build-mvylnj0m/editables-0.3-py3-none-any.whl
pdm.termui: Installing packaging 21.3
unearth: Downloading <Link https://files.pythonhosted.org/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl (from None)> to /tmp/pdm-build-c69qzhy2/packaging-21.3-py3-none-any.whl
pdm.termui: Installing pathspec 0.10.1
unearth: Downloading <Link https://files.pythonhosted.org/packages/63/82/2179fdc39bc1bb43296f638ae1dfe2581ec2617b4e87c28b0d23d44b997f/pathspec-0.10.1-py3-none-any.whl (from None)> to /tmp/pdm-build-our8rrpx/pathspec-0.10.1-py3-none-any.whl
pdm.termui: Installing pluggy 1.0.0
unearth: Downloading <Link https://files.pythonhosted.org/packages/9e/01/f38e2ff29715251cf25532b9082a1589ab7e4f571ced434f98d0139336dc/pluggy-1.0.0-py2.py3-none-any.whl (from None)> to /tmp/pdm-build-1zjn565s/pluggy-1.0.0-py2.py3-none-any.whl
pdm.termui: Installing tomli 2.0.1
unearth: Downloading <Link https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl (from None)> to /tmp/pdm-build-2i5l6inz/tomli-2.0.1-py3-none-any.whl
pdm.termui: Installing pyparsing 3.0.9
unearth: Downloading <Link https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl (from None)> to /tmp/pdm-build-xzxzqz01/pyparsing-3.0.9-py3-none-any.whl
pdm.termui: Traceback (most recent call last):
pdm.termui:   File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pep517/in_process/_in_process.py", line 351, in <module>
pdm.termui:     main()
pdm.termui:   File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pep517/in_process/_in_process.py", line 333, in main
pdm.termui:     json_out['return_val'] = hook(**hook_input['kwargs'])
pdm.termui:   File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pep517/in_process/_in_process.py", line 271, in build_editable
pdm.termui:     return hook(wheel_directory, config_settings, metadata_directory)
pdm.termui:   File "/tmp/pdm-build-env-_76vc51l-shared/lib/python3.9/site-packages/hatchling/build.py", line 61, in build_editable
pdm.termui:     return os.path.basename(next(builder.build(wheel_directory, ['editable'])))
pdm.termui:   File "/tmp/pdm-build-env-_76vc51l-shared/lib/python3.9/site-packages/hatchling/builders/plugin/interface.py", line 80, in build
pdm.termui:     self.metadata.validate_fields()
pdm.termui:   File "/tmp/pdm-build-env-_76vc51l-shared/lib/python3.9/site-packages/hatchling/metadata/core.py", line 214, in validate_fields
pdm.termui:     _ = self.version
pdm.termui:   File "/tmp/pdm-build-env-_76vc51l-shared/lib/python3.9/site-packages/hatchling/metadata/core.py", line 102, in version
pdm.termui:     self._set_version()
pdm.termui:   File "/tmp/pdm-build-env-_76vc51l-shared/lib/python3.9/site-packages/hatchling/metadata/core.py", line 195, in _set_version
pdm.termui:     version = self.hatch.version.cached
pdm.termui:   File "/tmp/pdm-build-env-_76vc51l-shared/lib/python3.9/site-packages/hatchling/metadata/core.py", line 1277, in cached
pdm.termui:     raise type(e)(f'Error getting the version from source `{self.source.PLUGIN_NAME}`: {e}') from None
pdm.termui: ModuleNotFoundError: Error getting the version from source `vcs`: No module named 'setuptools_scm'
  ✖ Install pdm-pep517-regression None failed
Traceback (most recent call last):
  File "/home/brcampbell/.local/bin/pdm", line 8, in <module>
    sys.exit(main())
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/core.py", line 258, in main
    return Core().main(args)
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/core.py", line 190, in main
    raise cast(Exception, err).with_traceback(traceback)
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/core.py", line 185, in main
    f(project, options)
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/cli/commands/install.py", line 62, in handle
    actions.do_sync(
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/cli/actions.py", line 218, in do_sync
    handler.synchronize()
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/installers/synchronizers.py", line 426, in synchronize
    self.install_candidate(self_key, progress)
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/installers/synchronizers.py", line 225, in install_candidate
    self.manager.install(can)
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/installers/manager.py", line 39, in install
    installer(str(prepared.build()), self.environment, prepared.direct_url())
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/models/candidates.py", line 377, in build
    builder.build(build_dir, metadata_directory=self._metadata_dir)
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/builders/editable.py", line 53, in build
    filename = self._hook.build_editable(
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pep517/wrappers.py", line 262, in build_editable
    return self._call_hook('build_editable', {
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pep517/wrappers.py", line 309, in _call_hook
    self._subprocess_runner(
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/builders/base.py", line 245, in subprocess_runner
    return log_subprocessor(cmd, cwd, extra_environ=env)
  File "/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pdm/builders/base.py", line 84, in log_subprocessor
    raise BuildError(
pdm.exceptions.BuildError: Call command ['/home/brcampbell/tmp/pdm-pep517-regression/.venv/bin/python', '/home/brcampbell/.local/pipx/venvs/pdm/lib64/python3.10/site-packages/pep517/in_process/_in_process.py', 'build_editable', '/tmp/tmpkvobvkl7'] return non-zero status(1). Make sure the package is PEP 517-compliant, or you can add `--no-isolation` to the command.
```

## Expected behavior

<!--A clear and concise description of what you expected to happen.-->

I'd expect to be able to install this package. Here is how it worked under PDM 2.1.5:

```
[brcampbell@beta-0535 pdm-pep517-regression]$ pipx run --spec "pdm==2.1.5" pdm install -v
⚠️  pdm is already on your PATH and installed at /home/brcampbell/.local/bin/pdm. Downloading and running anyway.
All packages are synced to date, nothing to do.
Installing the project as an editable package...
pdm.termui: Preparing isolated env for PEP 517 build...
pdm.termui: Running PEP 517 backend to build a wheel for <Link file:///home/brcampbell/tmp/pdm-pep517-regression (from None)>
pdm.termui: Using pip 22.3 from /home/brcampbell/.local/pipx/shared/lib/python3.10/site-packages/pip (python 3.9)
pdm.termui: Collecting hatchling
pdm.termui:   Using cached hatchling-1.11.1-py3-none-any.whl (73 kB)
pdm.termui: Collecting hatch-vcs
pdm.termui:   Using cached hatch_vcs-0.2.0-py2.py3-none-any.whl (6.1 kB)
pdm.termui: Collecting pluggy>=1.0.0
pdm.termui:   Using cached pluggy-1.0.0-py2.py3-none-any.whl (13 kB)
pdm.termui: Collecting tomli>=1.2.2
pdm.termui:   Using cached tomli-2.0.1-py3-none-any.whl (12 kB)
pdm.termui: Collecting pathspec>=0.10.1
pdm.termui:   Using cached pathspec-0.10.1-py3-none-any.whl (27 kB)
pdm.termui: Collecting editables>=0.3
pdm.termui:   Using cached editables-0.3-py3-none-any.whl (4.7 kB)
pdm.termui: Collecting packaging>=21.3
pdm.termui:   Using cached packaging-21.3-py3-none-any.whl (40 kB)
pdm.termui: Collecting setuptools-scm>=6.4.0
pdm.termui:   Using cached setuptools_scm-7.0.5-py3-none-any.whl (42 kB)
pdm.termui: Collecting pyparsing!=3.0.5,>=2.0.2
pdm.termui:   Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
pdm.termui: Collecting setuptools
pdm.termui:   Using cached setuptools-65.5.0-py3-none-any.whl (1.2 MB)
pdm.termui: Collecting typing-extensions
pdm.termui:   Using cached typing_extensions-4.4.0-py3-none-any.whl (26 kB)
pdm.termui: Installing collected packages: typing-extensions, tomli, setuptools, pyparsing, pluggy, pathspec, editables, packaging, setuptools-scm, hatchling, hatch-vcs
pdm.termui:   Creating /tmp/pdm-build-env-7p2f07ov-shared/bin
pdm.termui:   changing mode of /tmp/pdm-build-env-7p2f07ov-shared/bin/hatchling to 755
pdm.termui: Successfully installed editables-0.3 hatch-vcs-0.2.0 hatchling-1.11.1 packaging-21.3 pathspec-0.10.1 pluggy-1.0.0 pyparsing-3.0.9 setuptools-65.5.0 setuptools-scm-7.0.5 tomli-2.0.1 typing-extensions-4.4.0
  ✔ Install pdm-pep517-regression None successful

🎉 All complete!

PDM 2.1.5 is installed, while 2.2.0 is available.
Please run `/home/brcampbell/.local/pipx/.cache/3367fbccf40c1df/bin/python -m pip install -U pdm` to upgrade.
Run `pdm config check_update false` to disable the check.
```

It also works as expected in PDM 2.2.0 if I remove the max Python version constraint (so, `requires-python = ">=3.9"`); we see that in this case it resolved the `setuptools_scm` requirement:

```
[brcampbell@beta-0535 pdm-pep517-regression]$ pdm install -v
Lock file hash doesn't match pyproject.toml, packages may be outdated
Updating the lock file...
pdm.termui: ======== Start resolving requirements ========
pdm.termui:   python>=3.9
pdm.termui:   Adding requirement python>=3.9
pdm.termui: ======== Starting round 0 ========
pdm.termui: Pinning: python None
pdm.termui: ======== Ending round 0 ========
pdm.termui: ======== Starting round 1 ========
pdm.termui: ======== Resolution Result ========
pdm.termui: Stable pins:
pdm.termui:   python None
🔒 Lock successful
Changes are written to pdm.lock.
All packages are synced to date, nothing to do.
Installing the project as an editable package...
pdm.termui: Removing distribution pdm-pep517-regression
pdm.termui: Preparing isolated env for PEP 517 build...
pdm.termui: Running PEP 517 backend to build a wheel for <Link file:///home/brcampbell/tmp/pdm-pep517-regression (from None)>
pdm.termui: ======== Start resolving requirements ========
pdm.termui:   hatchling
pdm.termui:   hatch-vcs
pdm.termui:   python>=3.9.14,<3.9.15
pdm.termui:   Adding requirement hatchling
pdm.termui:   Adding requirement hatch-vcs
pdm.termui:   Adding requirement python>=3.9.14,<3.9.15
pdm.termui: ======== Starting round 0 ========
pdm.termui: Pinning: python None
pdm.termui: ======== Ending round 0 ========
pdm.termui: ======== Starting round 1 ========
pdm.termui:   Adding requirement hatchling>=0.21.0(from hatch-vcs 0.2.0)
pdm.termui:   Adding requirement setuptools-scm>=6.4.0; python_version > "3"(from hatch-vcs 0.2.0)
pdm.termui: Pinning: hatch-vcs 0.2.0
pdm.termui: ======== Ending round 1 ========
pdm.termui: ======== Starting round 2 ========
pdm.termui:   Adding requirement editables>=0.3(from hatchling 1.11.1)
pdm.termui:   Adding requirement packaging>=21.3(from hatchling 1.11.1)
pdm.termui:   Adding requirement pathspec>=0.10.1(from hatchling 1.11.1)
pdm.termui:   Adding requirement pluggy>=1.0.0(from hatchling 1.11.1)
pdm.termui:   Adding requirement tomli>=1.2.2; python_version < "3.11"(from hatchling 1.11.1)
pdm.termui: Pinning: hatchling 1.11.1
pdm.termui: ======== Ending round 2 ========
pdm.termui: ======== Starting round 3 ========
pdm.termui: Pinning: editables 0.3
pdm.termui: ======== Ending round 3 ========
pdm.termui: ======== Starting round 4 ========
pdm.termui:   Adding requirement pyparsing!=3.0.5,>=2.0.2(from packaging 21.3)
pdm.termui: Pinning: packaging 21.3
pdm.termui: ======== Ending round 4 ========
pdm.termui: ======== Starting round 5 ========
pdm.termui: Pinning: pathspec 0.10.1
pdm.termui: ======== Ending round 5 ========
pdm.termui: ======== Starting round 6 ========
pdm.termui: Pinning: pluggy 1.0.0
pdm.termui: ======== Ending round 6 ========
pdm.termui: ======== Starting round 7 ========
pdm.termui:   Adding requirement packaging>=20.0(from setuptools-scm 7.0.5)
pdm.termui:   Adding requirement setuptools(from setuptools-scm 7.0.5)
pdm.termui:   Adding requirement tomli>=1.0.0(from setuptools-scm 7.0.5)
pdm.termui:   Adding requirement typing-extensions(from setuptools-scm 7.0.5)
pdm.termui: Pinning: setuptools-scm 7.0.5
pdm.termui: ======== Ending round 7 ========
pdm.termui: ======== Starting round 8 ========
pdm.termui: Pinning: tomli 2.0.1
pdm.termui: ======== Ending round 8 ========
pdm.termui: ======== Starting round 9 ========
pdm.termui: Pinning: pyparsing 3.0.9
pdm.termui: ======== Ending round 9 ========
pdm.termui: ======== Starting round 10 ========
pdm.termui: Pinning: setuptools 65.5.0
pdm.termui: ======== Ending round 10 ========
pdm.termui: ======== Starting round 11 ========
pdm.termui: Pinning: typing-extensions 4.4.0
pdm.termui: ======== Ending round 11 ========
pdm.termui: ======== Starting round 12 ========
pdm.termui: ======== Resolution Result ========
pdm.termui: Stable pins:
pdm.termui:              python None
pdm.termui:           hatch-vcs 0.2.0
pdm.termui:           hatchling 1.11.1
pdm.termui:           editables 0.3
pdm.termui:           packaging 21.3
pdm.termui:            pathspec 0.10.1
pdm.termui:              pluggy 1.0.0
pdm.termui:      setuptools-scm 7.0.5
pdm.termui:               tomli 2.0.1
pdm.termui:           pyparsing 3.0.9
pdm.termui:          setuptools 65.5.0
pdm.termui:   typing-extensions 4.4.0
pdm.termui: Installing hatch-vcs 0.2.0
unearth: Downloading <Link https://files.pythonhosted.org/packages/7d/47/73ff0d30c4fa8b175db04a104a55dbe7d2050632262575efe02b8e2c8e2b/hatch_vcs-0.2.0-py2.py3-none-any.whl (from None)> to /tmp/pdm-build-nzfw_329/hatch_vcs-0.2.0-py2.py3-none-any.whl
pdm.termui: Installing hatchling 1.11.1
unearth: Downloading <Link https://files.pythonhosted.org/packages/d3/af/8feac1326463c275d431e7331695f24a34b508fa046288bad289ff0967f2/hatchling-1.11.1-py3-none-any.whl (from None)> to /tmp/pdm-build-zxuwvsmf/hatchling-1.11.1-py3-none-any.whl
pdm.termui: Installing editables 0.3
unearth: Downloading <Link https://files.pythonhosted.org/packages/ef/8c/87276afb1ba3193c4c05be83965a1e69b8a14821ce6d688464071b179383/editables-0.3-py3-none-any.whl (from None)> to /tmp/pdm-build-kpjuapb3/editables-0.3-py3-none-any.whl
pdm.termui: Installing packaging 21.3
unearth: Downloading <Link https://files.pythonhosted.org/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl (from None)> to /tmp/pdm-build-dj09xz2p/packaging-21.3-py3-none-any.whl
pdm.termui: Installing pathspec 0.10.1
unearth: Downloading <Link https://files.pythonhosted.org/packages/63/82/2179fdc39bc1bb43296f638ae1dfe2581ec2617b4e87c28b0d23d44b997f/pathspec-0.10.1-py3-none-any.whl (from None)> to /tmp/pdm-build-e_b8yggg/pathspec-0.10.1-py3-none-any.whl
pdm.termui: Installing pluggy 1.0.0
unearth: Downloading <Link https://files.pythonhosted.org/packages/9e/01/f38e2ff29715251cf25532b9082a1589ab7e4f571ced434f98d0139336dc/pluggy-1.0.0-py2.py3-none-any.whl (from None)> to /tmp/pdm-build-vfozscog/pluggy-1.0.0-py2.py3-none-any.whl
pdm.termui: Installing setuptools-scm 7.0.5
unearth: Downloading <Link https://files.pythonhosted.org/packages/01/ed/75a20e7b075e8ecb1f84e8debf833917905d8790b78008915bd68dddd5c4/setuptools_scm-7.0.5-py3-none-any.whl (from None)> to /tmp/pdm-build-bofv6sks/setuptools_scm-7.0.5-py3-none-any.whl
pdm.termui: Installing tomli 2.0.1
unearth: Downloading <Link https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl (from None)> to /tmp/pdm-build-1uwnj7ic/tomli-2.0.1-py3-none-any.whl
pdm.termui: Installing pyparsing 3.0.9
unearth: Downloading <Link https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl (from None)> to /tmp/pdm-build-cqjw5gg4/pyparsing-3.0.9-py3-none-any.whl
pdm.termui: Installing setuptools 65.5.0
unearth: Downloading <Link https://files.pythonhosted.org/packages/41/82/7f54bbfe5c247a8c9f78d8d1d7c051847bcb78843c397b866dba335c1e88/setuptools-65.5.0-py3-none-any.whl (from None)> to /tmp/pdm-build-jcd9d9k5/setuptools-65.5.0-py3-none-any.whl
pdm.termui: Installing typing-extensions 4.4.0
unearth: Downloading <Link https://files.pythonhosted.org/packages/0b/8e/f1a0a5a76cfef77e1eb6004cb49e5f8d72634da638420b9ea492ce8305e8/typing_extensions-4.4.0-py3-none-any.whl (from None)> to /tmp/pdm-build-9qjg1yu6/typing_extensions-4.4.0-py3-none-any.whl
  ✔ Update pdm-pep517-regression 0.1.dev1+g4c6fd4d.d20221031 -> None successful

🎉 All complete!
```

## Environment Information

```bash
[brcampbell@beta-0535 pdm-pep517-regression]$ pdm info && pdm info --env
PDM version:
  2.2.0
Python Interpreter:
  /home/brcampbell/tmp/pdm-pep517-regression/.venv/bin/python (3.9)
Project Root:
  /home/brcampbell/tmp/pdm-pep517-regression
Project Packages:
  None
{
  "implementation_name": "cpython",
  "implementation_version": "3.9.14",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.19.8-200.fc36.x86_64",
  "platform_system": "Linux",
  "platform_version": "#1 SMP PREEMPT_DYNAMIC Thu Sep 8 19:02:21 UTC 2022",
  "python_full_version": "3.9.14",
  "platform_python_implementation": "CPython",
  "python_version": "3.9",
  "sys_platform": "linux"
}
```


Discussion:

Patch:
diff --git a/news/1471.feature.md b/news/1471.feature.md
new file mode 100644
index 00000000..811dc3a4
--- /dev/null
+++ b/news/1471.feature.md
@@ -0,0 +1,1 @@
+Make `sitecustomize.py` respect the `PDM_PROJECT_MAX_DEPTH` environment variable
diff --git a/news/1484.bugfix.md b/news/1484.bugfix.md
new file mode 100644
index 00000000..7e1397c6
--- /dev/null
+++ b/news/1484.bugfix.md
@@ -0,0 +1,1 @@
+Fix the comparison of `python_version` in the environment marker. When the version contains only one digit, the result was incorrect.
diff --git a/src/pdm/models/markers.py b/src/pdm/models/markers.py
index 723f799e..d2ec9c64 100644
--- a/src/pdm/models/markers.py
+++ b/src/pdm/models/markers.py
@@ -136,6 +136,8 @@ def _build_pyspec_from_marker(markers: List[Any]) -> PySpecSet:
             if key == "python_version":
                 if op == ">":
                     int_versions = [int(ver) for ver in version.split(".")]
+                    if len(int_versions) < 2:
+                        int_versions.append(0)
                     int_versions[-1] += 1
                     version = ".".join(str(v) for v in int_versions)
                     op = ">="
diff --git a/src/pdm/pep582/sitecustomize.py b/src/pdm/pep582/sitecustomize.py
index 2b083503..e7e36fdb 100644
--- a/src/pdm/pep582/sitecustomize.py
+++ b/src/pdm/pep582/sitecustomize.py
@@ -3,13 +3,13 @@ import site
 import sys
 
 
-def get_pypackages_path(maxdepth=5):
+def get_pypackages_path():
     def find_pypackage(path, version):
         if not os.path.exists(path):
             return None
 
         packages_name = f"__pypackages__/{version}/lib"
-        for _ in range(maxdepth):
+        for _ in range(int(os.getenv("PDM_PROJECT_MAX_DEPTH", "5"))):
             if os.path.exists(os.path.join(path, packages_name)):
                 return os.path.join(path, packages_name)
             if os.path.dirname(path) == path:


Test patch:
diff --git a/tests/models/test_marker.py b/tests/models/test_marker.py
index 9285fd89..7250f12f 100644
--- a/tests/models/test_marker.py
+++ b/tests/models/test_marker.py
@@ -1,6 +1,6 @@
 import pytest
 
-from pdm.models.markers import split_marker_extras
+from pdm.models.markers import Marker, split_marker_extras
 
 
 @pytest.mark.parametrize(
@@ -31,3 +31,29 @@ from pdm.models.markers import split_marker_extras
 def test_split_marker_extras(original, extras, rest):
     result = split_marker_extras(original)
     assert result == (extras, rest)
+
+
+@pytest.mark.parametrize(
+    "original,marker,py_spec",
+    [
+        ("python_version > '3'", None, ">=3.1"),
+        ("python_version > '3.8'", None, ">=3.9"),
+        ("python_version != '3.8'", None, "!=3.8.*"),
+        ("python_version == '3.7'", None, ">=3.7,<3.8"),
+        ("python_version in '3.6 3.7'", None, ">=3.6,<3.8"),
+        ("python_full_version >= '3.6.0'", None, ">=3.6"),
+        ("python_full_version not in '3.8.3'", None, "!=3.8.3"),
+        # mixed marker and python version
+        ("python_version > '3.7' and os_name == 'nt'", 'os_name == "nt"', ">=3.8"),
+        (
+            "python_version > '3.7' or os_name == 'nt'",
+            'python_version > "3.7" or os_name == "nt"',
+            "",
+        ),
+    ],
+)
+def test_split_pyspec(original, marker, py_spec):
+    m = Marker(original)
+    a, b = m.split_pyspec()
+    assert marker == (str(a) if a is not None else None)
+    assert py_spec == str(b)