Skip to content

Commit

Permalink
feat: Update PDM requirements to Python 3.8
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Dec 1, 2023
1 parent d631edd commit f8ac289
Show file tree
Hide file tree
Showing 26 changed files with 47 additions and 89 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
install-via: [pip]
arch: [x64]
Expand All @@ -54,7 +54,6 @@ jobs:

- name: Set Python 3.7
uses: actions/setup-python@v4
if: matrix.python-version != '3.7'
with:
python-version: 3.7
architecture: ${{ matrix.arch }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
architecture: "x64"
- name: Install Dependencies
run: |
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
exclude: ^(src/pdm/models/in_process/.*\.py|install-pdm\.py)$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.4'
hooks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Unlike Poetry and Hatch, PDM is not limited to a specific build backend; users h

## Installation

PDM requires python version 3.7 or higher.
PDM requires python version 3.8 or higher.

### Via Install Script

Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PDM 也可以像 Pipenv 那样在项目或集中的位置管理 venvs。它从

## 安装

PDM 需要 Python 3.7 或更高版本。
PDM 需要 Python 3.8 或更高版本。

### 通过安装脚本

Expand Down
4 changes: 2 additions & 2 deletions install-pdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from tempfile import TemporaryDirectory
from typing import Sequence

if sys.version_info < (3, 7):
sys.exit("Python 3.7 or above is required to install PDM.")
if sys.version_info < (3, 8):
sys.exit("Python 3.8 or above is required to install PDM.")

_plat = platform.system()
MACOS = _plat == "Darwin"
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
{name = "Frost Ming", email = "[email protected]"},
]
dynamic = ["version"]
requires-python = ">=3.7"
requires-python = ">=3.8"
license = {text = "MIT"}
dependencies = [
"blinker",
Expand Down Expand Up @@ -36,7 +36,6 @@ keywords = ["packaging", "dependency", "workflow"]
classifiers = [
"Topic :: Software Development :: Build Tools",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
8 changes: 0 additions & 8 deletions src/pdm/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,6 @@ def check_update(project: Project) -> None: # pragma: no cover
if project.core.ui.verbosity < termui.Verbosity.NORMAL:
return

if sys.version_info < (3, 8):
project.core.ui.echo(
"Python 3.7 has reached EOL in June 2023 and will be no longer supported starting from PDM 2.11.0. "
"Please upgrade to Python 3.8 or higher.",
err=True,
style="warning",
)

this_version = project.core.version
latest_version = get_latest_version(project)
if latest_version is None or Version(this_version) >= Version(latest_version):
Expand Down
4 changes: 2 additions & 2 deletions src/pdm/cli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pdm.cli.hooks import HookManager
from pdm.cli.options import skip_option, venv_option
from pdm.cli.utils import check_project_file, get_pep582_path
from pdm.compat import sh_join
from pdm.exceptions import PdmUsageError
from pdm.project import Project
from pdm.signals import pdm_signals
Expand Down Expand Up @@ -49,10 +48,11 @@ def exec_opts(*options: TaskOptions | None) -> dict[str, Any]:

def interpolate(script: str, args: Sequence[str]) -> tuple[str, bool]:
"""Interpolate the `{args:[defaults]} placeholder in a string"""
import shlex

def replace(m: re.Match[str]) -> str:
default = m.group("default") or ""
return sh_join(args) if args else default
return shlex.join(args) if args else default

interpolated, count = RE_ARGS_PLACEHOLDER.subn(replace, script)
return interpolated, count > 0
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/cli/commands/venv/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import shutil
import subprocess
import sys
from functools import cached_property
from pathlib import Path
from typing import Any, Iterable, Mapping

from pdm import termui
from pdm.cli.commands.venv.utils import get_venv_prefix
from pdm.compat import cached_property
from pdm.exceptions import PdmUsageError, ProjectError
from pdm.models.python import PythonInfo
from pdm.project import Project
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/cli/filters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

import argparse
from functools import cached_property
from typing import TYPE_CHECKING

from pdm.compat import cached_property
from pdm.exceptions import PdmUsageError

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions src/pdm/cli/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ProjectTemplate:
def __init__(self, path_or_url: str | None) -> None:
self.template = path_or_url

def __enter__(self) -> "ProjectTemplate":
def __enter__(self) -> ProjectTemplate:
self._path = Path(tempfile.mkdtemp(suffix="-template", prefix="pdm-"))
self.prepare_template()
return self
Expand Down Expand Up @@ -156,7 +156,7 @@ def _prepare_git_template(self, url: str) -> None:
else:
extra_args = []
git_command = ["git", "clone", "--recursive", "--depth=1", *extra_args, url, self._path.as_posix()]
result = subprocess.run(git_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
result = subprocess.run(git_command, capture_output=True, text=True)
if result.returncode != 0:
raise PdmException(f"Failed to clone template from git repository {url}: {result.stderr}")
shutil.rmtree(self._path / ".git", ignore_errors=True)
Expand Down
41 changes: 2 additions & 39 deletions src/pdm/compat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import importlib.resources
import sys
from pathlib import Path
from typing import BinaryIO, ContextManager, Iterable
from typing import BinaryIO, ContextManager

if sys.version_info >= (3, 11):
import tomllib
Expand Down Expand Up @@ -30,43 +30,6 @@ def resources_path(package: str, resource: str) -> ContextManager[Path]:
resources_path = importlib.resources.path


if sys.version_info >= (3, 8):
from functools import cached_property
from shlex import join as sh_join
else:
from typing import Any, Callable, Generic, TypeVar, overload

_T = TypeVar("_T")
_C = TypeVar("_C")

class cached_property(Generic[_T]):
def __init__(self, func: Callable[[Any], _T]):
self.func = func
self.attr_name = func.__name__
self.__doc__ = func.__doc__

@overload
def __get__(self: _C, inst: None, cls: Any = ...) -> _C:
...

@overload
def __get__(self, inst: object, cls: Any = ...) -> _T:
...

def __get__(self, inst, cls=None):
if inst is None:
return self
if self.attr_name not in inst.__dict__:
inst.__dict__[self.attr_name] = self.func(inst)
return inst.__dict__[self.attr_name]

def sh_join(split_command: Iterable[str]) -> str:
"""Return a shell-escaped string from *split_command*."""
import shlex

return " ".join(shlex.quote(arg) for arg in split_command)


if sys.version_info >= (3, 10):
import importlib.metadata as importlib_metadata
else:
Expand All @@ -82,4 +45,4 @@ def sh_join(split_command: Iterable[str]) -> str:
Distribution = importlib_metadata.Distribution


__all__ = ["tomllib", "cached_property", "sh_join", "importlib_metadata", "Distribution", "importlib_resources"]
__all__ = ["tomllib", "importlib_metadata", "Distribution", "importlib_resources"]
2 changes: 1 addition & 1 deletion src/pdm/environments/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import sys
import tempfile
from contextlib import contextmanager
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Generator

from pdm.compat import cached_property
from pdm.exceptions import BuildError, PdmUsageError
from pdm.models.in_process import get_pep508_environment, get_python_abi_tag, get_uname
from pdm.models.python import PythonInfo
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/environments/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os
import re
import shlex
from functools import cached_property
from pathlib import Path

from pdm.compat import cached_property
from pdm.environments.base import BaseEnvironment
from pdm.utils import pdm_scheme

Expand Down
7 changes: 3 additions & 4 deletions src/pdm/installers/installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import shutil
import warnings
import zipfile
from functools import lru_cache
from functools import cached_property, lru_cache
from pathlib import Path
from typing import TYPE_CHECKING, Iterator

Expand All @@ -18,7 +18,6 @@
from installer.sources import WheelFile as _WheelFile
from installer.sources import _WheelFileValidationError

from pdm.compat import cached_property
from pdm.exceptions import PDMWarning
from pdm.installers.packages import CachedPackage
from pdm.termui import logger
Expand All @@ -33,7 +32,7 @@
from pdm.environments import BaseEnvironment


@lru_cache()
@lru_cache
def _is_python_package(root: str | Path) -> bool:
for child in Path(root).iterdir():
if (
Expand Down Expand Up @@ -61,7 +60,7 @@ def _is_python_package(root: str | Path) -> bool:
_namespace_package_lines = _namespace_package_lines.union(line.replace("'", '"') for line in _namespace_package_lines)


@lru_cache()
@lru_cache
def _is_namespace_package(root: str) -> bool:
if not _is_python_package(root):
return False
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/installers/synchronizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import multiprocessing
import traceback
from concurrent.futures import Future, ThreadPoolExecutor
from functools import cached_property
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any, Callable, Collection, TypeVar

from rich.progress import SpinnerColumn, TaskProgressColumn

from pdm import termui
from pdm.compat import cached_property
from pdm.environments import BaseEnvironment
from pdm.exceptions import InstallationError
from pdm.installers.manager import InstallManager
Expand Down
3 changes: 1 addition & 2 deletions src/pdm/models/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import re
import warnings
from functools import lru_cache
from functools import cached_property, lru_cache
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Any, cast, no_type_check
Expand All @@ -15,7 +15,6 @@

from pdm import termui
from pdm.builders import EditableBuilder, WheelBuilder
from pdm.compat import cached_property
from pdm.compat import importlib_metadata as im
from pdm.exceptions import BuildError, CandidateNotFound, InvalidPyVersion, PDMWarning
from pdm.models.backends import get_backend, get_backend_by_spec
Expand Down
4 changes: 2 additions & 2 deletions src/pdm/models/in_process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _in_process_script(name: str) -> Generator[str, None, None]:
yield str(script)


@functools.lru_cache()
@functools.lru_cache
def get_python_abi_tag(executable: str) -> str:
with _in_process_script("get_abi_tag.py") as script:
return json.loads(subprocess.check_output(args=[executable, "-EsS", script]))
Expand Down Expand Up @@ -55,7 +55,7 @@ def parse_setup_py(executable: str, path: str) -> dict[str, Any]:
return json.load(fp)


@functools.lru_cache()
@functools.lru_cache
def get_uname(executable: str) -> os.uname_result:
"""Get uname of the system"""
script = "import os, json; print(json.dumps(os.uname()))"
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/models/python.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

import os
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Any

from packaging.version import InvalidVersion, Version

from pdm.compat import cached_property
from pdm.models.venv import VirtualEnv

if TYPE_CHECKING:
Expand Down
Loading

0 comments on commit f8ac289

Please sign in to comment.