Repository: pdm-project/pdm
Pull request #1485 (2022-11-01 00:10:04)

[pre-commit.ci] pre-commit autoupdate
<!--pre-commit.ci start-->
updates:
- [github.com/psf/black: 22.8.0 → 22.10.0](https://github.com/psf/black/compare/22.8.0...22.10.0)
- [github.com/codespell-project/codespell: v2.2.1 → v2.2.2](https://github.com/codespell-project/codespell/compare/v2.2.1...v2.2.2)
- [github.com/pre-commit/mirrors-mypy: v0.981 → v0.982](https://github.com/pre-commit/mirrors-mypy/compare/v0.981...v0.982)
<!--pre-commit.ci end-->


Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 07514793..0706b6d4 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -2,12 +2,12 @@ ci:
   autoupdate_schedule: monthly
 repos:
   - repo: https://github.com/psf/black
-    rev: 22.8.0
+    rev: 22.10.0
     hooks:
       - id: black
 
   - repo: https://github.com/codespell-project/codespell
-    rev: v2.2.1
+    rev: v2.2.2
     hooks:
       - id: codespell  # See setup.cfg for args
 
@@ -24,7 +24,7 @@ repos:
       - id: isort
 
   - repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v0.981
+    rev: v0.982
     hooks:
       - id: mypy
         args: [src]
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)