Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1545)
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] authored Dec 6, 2022
1 parent dbba52a commit b12989e
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: codespell # See setup.cfg for args

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -24,7 +24,7 @@ repos:
- id: isort

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.991
hooks:
- id: mypy
args: [src]
Expand Down
12 changes: 7 additions & 5 deletions src/pdm/builders/editable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import os
from pathlib import Path
from typing import Any, Mapping, Optional, Union
from typing import Any, Mapping

from pyproject_hooks import HookMissing

Expand All @@ -17,7 +19,7 @@ class EditableBuilder(EnvBuilder):
"requires": ["setuptools_pep660"],
}

def __init__(self, src_dir: Union[str, Path], environment: Environment) -> None:
def __init__(self, src_dir: str | Path, environment: Environment) -> None:
super().__init__(src_dir, environment)
if self._hook.build_backend.startswith(
"pdm.pep517"
Expand All @@ -26,7 +28,7 @@ def __init__(self, src_dir: Union[str, Path], environment: Environment) -> None:
self.init_build_system(self.FALLBACK_BACKEND)

def prepare_metadata(
self, out_dir: str, config_settings: Optional[Mapping[str, Any]] = None
self, out_dir: str, config_settings: Mapping[str, Any] | None = None
) -> str:
self.install(self._requires, shared=True)
try:
Expand All @@ -43,8 +45,8 @@ def prepare_metadata(
def build(
self,
out_dir: str,
config_settings: Optional[Mapping[str, Any]] = None,
metadata_directory: Optional[str] = None,
config_settings: Mapping[str, Any] | None = None,
metadata_directory: str | None = None,
) -> str:
self.install(self._requires, shared=True)
try:
Expand Down
8 changes: 5 additions & 3 deletions src/pdm/builders/sdist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import os
from typing import Any, Mapping, Optional
from typing import Any, Mapping

from pdm.builders.base import EnvBuilder

Expand All @@ -10,8 +12,8 @@ class SdistBuilder(EnvBuilder):
def build(
self,
out_dir: str,
config_settings: Optional[Mapping[str, Any]] = None,
metadata_directory: Optional[str] = None,
config_settings: Mapping[str, Any] | None = None,
metadata_directory: str | None = None,
) -> str:
self.install(self._requires, shared=True)
requires = self._hook.get_requires_for_build_sdist(config_settings)
Expand Down
10 changes: 6 additions & 4 deletions src/pdm/builders/wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import os
from typing import Any, Mapping, Optional
from typing import Any, Mapping

from pdm.builders.base import EnvBuilder

Expand All @@ -8,7 +10,7 @@ class WheelBuilder(EnvBuilder):
"""Build wheel in isolated env with managed Python."""

def prepare_metadata(
self, out_dir: str, config_settings: Optional[Mapping[str, Any]] = None
self, out_dir: str, config_settings: Mapping[str, Any] | None = None
) -> str:
self.install(self._requires, shared=True)
requires = self._hook.get_requires_for_build_wheel(config_settings)
Expand All @@ -19,8 +21,8 @@ def prepare_metadata(
def build(
self,
out_dir: str,
config_settings: Optional[Mapping[str, Any]] = None,
metadata_directory: Optional[str] = None,
config_settings: Mapping[str, Any] | None = None,
metadata_directory: str | None = None,
) -> str:
self.install(self._requires, shared=True)
requires = self._hook.get_requires_for_build_wheel(config_settings)
Expand Down
12 changes: 7 additions & 5 deletions src/pdm/cli/commands/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import argparse
from argparse import _SubParsersAction
from typing import Any, List, Optional
from typing import Any

from pdm.cli.options import Option, global_option, project_option, verbose_option
from pdm.cli.utils import PdmFormatter
Expand All @@ -11,12 +13,12 @@ class BaseCommand:
"""A CLI subcommand"""

# The subcommand's name
name: Optional[str] = None
name: str | None = None
# The subcommand's help string, if not given, __doc__ will be used.
description: Optional[str] = None
description: str | None = None
# A list of pre-defined options which will be loaded on initializing
# Rewrite this if you don't want the default ones
arguments: List[Option] = [verbose_option, global_option, project_option]
arguments: list[Option] = [verbose_option, global_option, project_option]

def __init__(self, parser: argparse.ArgumentParser) -> None:
for arg in self.arguments:
Expand All @@ -25,7 +27,7 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:

@classmethod
def register_to(
cls, subparsers: _SubParsersAction, name: Optional[str] = None, **kwargs: Any
cls, subparsers: _SubParsersAction, name: str | None = None, **kwargs: Any
) -> None:
"""Register a subcommand to the subparsers,
with an optional name of the subcommand.
Expand Down
5 changes: 3 additions & 2 deletions src/pdm/cli/commands/completion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import argparse
import importlib.resources
import sys
from typing import List

from pdm.cli.commands.base import BaseCommand
from pdm.cli.options import Option
Expand All @@ -12,7 +13,7 @@
class Command(BaseCommand):
"""Generate completion scripts for the given shell"""

arguments: List[Option] = []
arguments: list[Option] = []
SUPPORTED_SHELLS = ("bash", "zsh", "fish", "powershell", "pwsh")

def add_arguments(self, parser: argparse.ArgumentParser) -> None:
Expand Down
5 changes: 3 additions & 2 deletions src/pdm/cli/commands/search.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import argparse
import sys
import textwrap
from shutil import get_terminal_size
from typing import Optional

from pdm import termui
from pdm._types import SearchResult
Expand All @@ -17,7 +18,7 @@ def print_results(
ui: termui.UI,
hits: SearchResult,
working_set: WorkingSet,
terminal_width: Optional[int] = None,
terminal_width: int | None = None,
) -> None:
if not hits:
return
Expand Down
5 changes: 3 additions & 2 deletions src/pdm/cli/commands/venv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import argparse
from typing import List

from pdm.project import Project
from pdm.cli.commands.base import BaseCommand
Expand All @@ -15,7 +16,7 @@ class Command(BaseCommand):
"""Virtualenv management"""

name = "venv"
arguments: List[Option] = []
arguments: list[Option] = []

def add_arguments(self, parser: argparse.ArgumentParser) -> None:
subparser = parser.add_subparsers()
Expand Down
26 changes: 14 additions & 12 deletions src/pdm/cli/commands/venv/backends.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import abc
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Any, Iterable, List, Mapping, Optional, Tuple, Type
from typing import Any, Iterable, Mapping

from pdm import termui
from pdm.cli.commands.venv.utils import get_venv_prefix
Expand All @@ -20,7 +22,7 @@ class VirtualenvCreateError(ProjectError):
class Backend(abc.ABC):
"""The base class for virtualenv backends"""

def __init__(self, project: Project, python: Optional[str]) -> None:
def __init__(self, project: Project, python: str | None) -> None:
self.project = project
self.python = python

Expand Down Expand Up @@ -56,7 +58,7 @@ def ident(self) -> str:
"""
return self._resolved_interpreter.identifier

def subprocess_call(self, cmd: List[str], **kwargs: Any) -> None:
def subprocess_call(self, cmd: list[str], **kwargs: Any) -> None:
self.project.core.ui.echo(
f"Run command: [success]{cmd}[/]",
verbosity=termui.Verbosity.DETAIL,
Expand All @@ -82,19 +84,19 @@ def _ensure_clean(self, location: Path, force: bool = False) -> None:
)
shutil.rmtree(location)

def get_location(self, name: Optional[str]) -> Path:
def get_location(self, name: str | None) -> Path:
venv_parent = Path(self.project.config["venv.location"])
if not venv_parent.is_dir():
venv_parent.mkdir(exist_ok=True, parents=True)
return venv_parent / f"{get_venv_prefix(self.project)}{name or self.ident}"

def create(
self,
name: Optional[str] = None,
args: Tuple[str, ...] = (),
name: str | None = None,
args: tuple[str, ...] = (),
force: bool = False,
in_project: bool = False,
prompt: Optional[str] = None,
prompt: str | None = None,
with_pip: bool = False,
) -> Path:
if in_project:
Expand All @@ -113,7 +115,7 @@ def create(
return location

@abc.abstractmethod
def perform_create(self, location: Path, args: Tuple[str, ...]) -> None:
def perform_create(self, location: Path, args: tuple[str, ...]) -> None:
pass


Expand All @@ -123,7 +125,7 @@ def pip_args(self, with_pip: bool) -> Iterable[str]:
return ()
return ("--no-pip", "--no-setuptools", "--no-wheel")

def perform_create(self, location: Path, args: Tuple[str, ...]) -> None:
def perform_create(self, location: Path, args: tuple[str, ...]) -> None:
cmd = [
sys.executable,
"-m",
Expand All @@ -142,7 +144,7 @@ def pip_args(self, with_pip: bool) -> Iterable[str]:
return ()
return ("--without-pip",)

def perform_create(self, location: Path, args: Tuple[str, ...]) -> None:
def perform_create(self, location: Path, args: tuple[str, ...]) -> None:
cmd = [
str(self._resolved_interpreter.executable),
"-m",
Expand All @@ -167,7 +169,7 @@ def pip_args(self, with_pip: bool) -> Iterable[str]:
return ("pip",)
return ()

def perform_create(self, location: Path, args: Tuple[str, ...]) -> None:
def perform_create(self, location: Path, args: tuple[str, ...]) -> None:
if self.python:
python_ver = self.python
else:
Expand All @@ -188,7 +190,7 @@ def perform_create(self, location: Path, args: Tuple[str, ...]) -> None:
self.subprocess_call(cmd)


BACKENDS: Mapping[str, Type[Backend]] = {
BACKENDS: Mapping[str, type[Backend]] = {
"virtualenv": VirtualenvBackend,
"venv": VenvBackend,
"conda": CondaBackend,
Expand Down
12 changes: 7 additions & 5 deletions src/pdm/cli/commands/venv/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import base64
import hashlib
import sys
from pathlib import Path
from typing import Iterable, Optional, Tuple, Type, TypeVar
from typing import Iterable, TypeVar
from findpython import PythonVersion

from findpython.providers import BaseProvider
Expand All @@ -20,7 +22,7 @@ def hash_path(path: str) -> str:
).decode()[:8]


def get_in_project_venv_python(root: Path) -> Optional[Path]:
def get_in_project_venv_python(root: Path) -> Path | None:
"""Get the python interpreter path of venv-in-project"""
for possible_dir in (".venv", "venv", "env"):
venv_python = get_venv_python(root / possible_dir)
Expand All @@ -36,7 +38,7 @@ def get_venv_prefix(project: Project) -> str:
return f"{path.name}-{name_hash}-"


def iter_venvs(project: Project) -> Iterable[Tuple[str, Path]]:
def iter_venvs(project: Project) -> Iterable[tuple[str, Path]]:
"""Return an iterable of venv paths associated with the project"""
in_project_venv_python = get_in_project_venv_python(project.root)
if in_project_venv_python is not None:
Expand All @@ -54,7 +56,7 @@ def get_venv_python(venv: Path) -> Path:
return venv / BIN_DIR / f"python{suffix}"


def iter_central_venvs(project: Project) -> Iterable[Tuple[str, Path]]:
def iter_central_venvs(project: Project) -> Iterable[tuple[str, Path]]:
"""Return an iterable of all managed venvs and their paths."""
venv_parent = Path(project.config["venv.location"])
for venv in venv_parent.glob("*"):
Expand All @@ -72,7 +74,7 @@ def __init__(self, project: Project) -> None:
self.project = project

@classmethod
def create(cls: Type[T]) -> Optional[T]: # pragma: no cover
def create(cls: type[T]) -> T | None: # pragma: no cover
return None

def find_pythons(self) -> Iterable[PythonVersion]:
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
self,
name: str,
is_mutually_exclusive: bool = False,
required: bool = None,
required: bool | None = None,
) -> None:
self.name = name
self.options: list[Option] = []
Expand Down
4 changes: 2 additions & 2 deletions src/pdm/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def build_forward_dependency_json_subtree(
root: Package,
project: Project,
graph: DirectedGraph[Package | None],
required_by: Package = None,
required_by: Package | None = None,
visited: frozenset[str] = frozenset(),
) -> dict:
if not package_is_project(root, project):
Expand Down Expand Up @@ -390,7 +390,7 @@ def build_reverse_dependency_json_subtree(
root: Package,
project: Project,
graph: DirectedGraph[Package | None],
requires: Package = None,
requires: Package | None = None,
visited: frozenset[str] = frozenset(),
) -> dict:
parents = graph.iter_parents(root) if root.name not in visited else []
Expand Down
4 changes: 2 additions & 2 deletions src/pdm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def create_project(

def main(
self,
args: list[str] = None,
prog_name: str = None,
args: list[str] | None = None,
prog_name: str | None = None,
obj: Project | None = None,
**extra: Any,
) -> None:
Expand Down
4 changes: 3 additions & 1 deletion src/pdm/formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
_T = TypeVar("_T", bound=Callable)


def convert_from(field: str = None, name: str = None) -> Callable[[_T], _T]:
def convert_from(
field: str | None = None, name: str | None = None
) -> Callable[[_T], _T]:
def wrapper(func: _T) -> _T:
func._convert_from = field # type: ignore
func._convert_to = name # type: ignore
Expand Down
Loading

0 comments on commit b12989e

Please sign in to comment.