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

fix: update to pyproject_metadata 0.9.0b7 #263

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -66,7 +66,9 @@ patches-dir = "scripts/patches"
protected-files = ["__init__.py", "README.md", "vendor.txt"]

[tool.vendoring.transformations]
substitute = []
substitute = [
{match = "import packaging", replace = "import pdm.backend._vendor.packaging"},
]
drop = [
"bin/",
"*.so",
131 changes: 21 additions & 110 deletions scripts/patches/pyproject_metadata.patch
Original file line number Diff line number Diff line change
@@ -1,113 +1,24 @@
diff --git a/src/pdm/backend/_vendor/pyproject_metadata/__init__.py b/src/pdm/backend/_vendor/pyproject_metadata/__init__.py
index 70c452b..6a3af49 100644
index 39ae6e4..283264b 100644
--- a/src/pdm/backend/_vendor/pyproject_metadata/__init__.py
+++ b/src/pdm/backend/_vendor/pyproject_metadata/__init__.py
@@ -20,18 +20,18 @@ if typing.TYPE_CHECKING:
from collections.abc import Generator, Iterable, Mapping
from typing import Any

- from packaging.requirements import Requirement
+ from pdm.backend._vendor.packaging.requirements import Requirement

if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self

-import packaging.markers
-import packaging.requirements
-import packaging.specifiers
-import packaging.utils
-import packaging.version
+import pdm.backend._vendor.packaging.markers as pkg_markers
+import pdm.backend._vendor.packaging.requirements as pkg_requirements
+import pdm.backend._vendor.packaging.specifiers as pkg_specifiers
+import pdm.backend._vendor.packaging.utils as pkg_utils
+import pdm.backend._vendor.packaging.version as pkg_version


__version__ = '0.9.0b4'
@@ -397,8 +397,8 @@ class ProjectFetcher(DataFetcher):
requirements: list[Requirement] = []
for req in requirement_strings:
try:
- requirements.append(packaging.requirements.Requirement(req))
- except packaging.requirements.InvalidRequirement as e:
+ requirements.append(pkg_requirements.Requirement(req))
+ except pkg_requirements.InvalidRequirement as e:
msg = (
'Field "project.dependencies" contains an invalid PEP 508 '
f'requirement string "{req}" ("{e}")'
@@ -439,9 +439,9 @@ class ProjectFetcher(DataFetcher):
raise ConfigurationError(msg)
try:
requirements_dict[extra].append(
- packaging.requirements.Requirement(req)
+ pkg_requirements.Requirement(req)
)
- except packaging.requirements.InvalidRequirement as e:
+ except pkg_requirements.InvalidRequirement as e:
msg = (
f'Field "project.optional-dependencies.{extra}" contains '
f'an invalid PEP 508 requirement string "{req}" ("{e}")'
@@ -501,12 +501,12 @@ class Readme:
@dataclasses.dataclass
class StandardMetadata:
name: str
- version: packaging.version.Version | None = None
+ version: pkg_version.Version | None = None
description: str | None = None
license: License | str | None = None
license_files: list[pathlib.Path] | None = None
readme: Readme | None = None
- requires_python: packaging.specifiers.SpecifierSet | None = None
+ requires_python: pkg_specifiers.SpecifierSet | None = None
dependencies: list[Requirement] = dataclasses.field(default_factory=list)
optional_dependencies: dict[str, list[Requirement]] = dataclasses.field(
default_factory=dict
@@ -617,7 +617,7 @@ class StandardMetadata:

@property
def canonical_name(self) -> str:
- return packaging.utils.canonicalize_name(self.name)
+ return pkg_utils.canonicalize_name(self.name)

@classmethod
def from_pyproject(
@@ -661,7 +661,7 @@ class StandardMetadata:

version_string = fetcher.get_str('project.version')
requires_python_string = fetcher.get_str('project.requires-python')
- version = packaging.version.Version(version_string) if version_string else None
+ version = pkg_version.Version(version_string) if version_string else None

if version is None and 'version' not in dynamic:
msg = 'Field "project.version" missing and "version" not specified in "project.dynamic"'
@@ -673,7 +673,7 @@ class StandardMetadata:
description = fetcher.get_str('project.description')

requires_python = (
- packaging.specifiers.SpecifierSet(requires_python_string)
+ pkg_specifiers.SpecifierSet(requires_python_string)
if requires_python_string
else None
)
@@ -791,15 +791,15 @@ class StandardMetadata:
requirement = copy.copy(requirement)
if requirement.marker:
if 'or' in requirement.marker._markers:
- requirement.marker = packaging.markers.Marker(
+ requirement.marker = pkg_markers.Marker(
f'({requirement.marker}) and extra == "{extra}"'
)
else:
- requirement.marker = packaging.markers.Marker(
+ requirement.marker = pkg_markers.Marker(
f'{requirement.marker} and extra == "{extra}"'
)
else:
- requirement.marker = packaging.markers.Marker(f'extra == "{extra}"')
+ requirement.marker = pkg_markers.Marker(f'extra == "{extra}"')
return requirement


@@ -63,6 +63,7 @@ if typing.TYPE_CHECKING:

from .project_table import Dynamic, PyProjectTable

+import pdm.backend._vendor.packaging as packaging
import packaging.markers
import packaging.specifiers
import packaging.utils
diff --git a/src/pdm/backend/_vendor/pyproject_metadata/pyproject.py b/src/pdm/backend/_vendor/pyproject_metadata/pyproject.py
index d1822e1..a85f9a1 100644
--- a/src/pdm/backend/_vendor/pyproject_metadata/pyproject.py
+++ b/src/pdm/backend/_vendor/pyproject_metadata/pyproject.py
@@ -13,6 +13,7 @@ import pathlib
import re
import typing

+import pdm.backend._vendor.packaging as packaging
import packaging.requirements

from .errors import ErrorCollector
1,060 changes: 450 additions & 610 deletions src/pdm/backend/_vendor/pyproject_metadata/__init__.py

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions src/pdm/backend/_vendor/pyproject_metadata/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# SPDX-License-Identifier: MIT

"""
Constants for the pyproject_metadata package, collected here to make them easy
to update. These should be considered mostly private.
"""

from __future__ import annotations

__all__ = [
"KNOWN_BUILD_SYSTEM_FIELDS",
"KNOWN_METADATA_FIELDS",
"KNOWN_METADATA_VERSIONS",
"KNOWN_METADATA_VERSIONS",
"KNOWN_MULTIUSE",
"KNOWN_PROJECT_FIELDS",
"KNOWN_TOPLEVEL_FIELDS",
"PRE_SPDX_METADATA_VERSIONS",
"PROJECT_TO_METADATA",
]


def __dir__() -> list[str]:
return __all__


KNOWN_METADATA_VERSIONS = {"2.1", "2.2", "2.3", "2.4"}
PRE_SPDX_METADATA_VERSIONS = {"2.1", "2.2", "2.3"}

PROJECT_TO_METADATA = {
"authors": frozenset(["Author", "Author-Email"]),
"classifiers": frozenset(["Classifier"]),
"dependencies": frozenset(["Requires-Dist"]),
"description": frozenset(["Summary"]),
"dynamic": frozenset(),
"entry-points": frozenset(),
"gui-scripts": frozenset(),
"keywords": frozenset(["Keywords"]),
"license": frozenset(["License", "License-Expression"]),
"license-files": frozenset(["License-File"]),
"maintainers": frozenset(["Maintainer", "Maintainer-Email"]),
"name": frozenset(["Name"]),
"optional-dependencies": frozenset(["Provides-Extra", "Requires-Dist"]),
"readme": frozenset(["Description", "Description-Content-Type"]),
"requires-python": frozenset(["Requires-Python"]),
"scripts": frozenset(),
"urls": frozenset(["Project-URL"]),
"version": frozenset(["Version"]),
}

KNOWN_TOPLEVEL_FIELDS = {"build-system", "project", "tool"}
KNOWN_BUILD_SYSTEM_FIELDS = {"backend-path", "build-backend", "requires"}
KNOWN_PROJECT_FIELDS = set(PROJECT_TO_METADATA)

KNOWN_METADATA_FIELDS = {
"author",
"author-email",
"classifier",
"description",
"description-content-type",
"download-url", # Not specified via pyproject standards
"dynamic", # Can't be in dynamic
"home-page", # Not specified via pyproject standards
"keywords",
"license",
"license-expression",
"license-file",
"maintainer",
"maintainer-email",
"metadata-version",
"name", # Can't be in dynamic
"obsoletes", # Deprecated
"obsoletes-dist", # Rarely used
"platform", # Not specified via pyproject standards
"project-url",
"provides", # Deprecated
"provides-dist", # Rarely used
"provides-extra",
"requires", # Deprecated
"requires-dist",
"requires-external", # Not specified via pyproject standards
"requires-python",
"summary",
"supported-platform", # Not specified via pyproject standards
"version", # Can't be in dynamic
}

KNOWN_MULTIUSE = {
"dynamic",
"platform",
"provides-extra",
"supported-platform",
"license-file",
"classifier",
"requires-dist",
"requires-external",
"project-url",
"provides-dist",
"obsoletes-dist",
"requires", # Deprecated
"obsoletes", # Deprecated
"provides", # Deprecated
}
119 changes: 119 additions & 0 deletions src/pdm/backend/_vendor/pyproject_metadata/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# SPDX-License-Identifier: MIT

"""
This module defines exceptions and error handling utilities. It is the
recommend path to access ``ConfiguratonError``, ``ConfigurationWarning``, and
``ExceptionGroup``. For backward compatibility, ``ConfigurationError`` is
re-exported in the top-level package.
"""

from __future__ import annotations

import builtins
import contextlib
import dataclasses
import sys
import typing
import warnings

__all__ = [
"ConfigurationError",
"ConfigurationWarning",
"ExceptionGroup",
]


def __dir__() -> list[str]:
return __all__


class ConfigurationError(Exception):
"""Error in the backend metadata. Has an optional key attribute, which will be non-None
if the error is related to a single key in the pyproject.toml file."""

def __init__(self, msg: str, *, key: str | None = None):
super().__init__(msg)
self._key = key

@property
def key(self) -> str | None: # pragma: no cover
return self._key


class ConfigurationWarning(UserWarning):
"""Warnings about backend metadata."""


if sys.version_info >= (3, 11):
ExceptionGroup = builtins.ExceptionGroup
else:

class ExceptionGroup(Exception):
"""A minimal implementation of `ExceptionGroup` from Python 3.11.
Users can replace this with a more complete implementation, such as from
the exceptiongroup backport package, if better error messages and
integration with tooling is desired and the addition of a dependency is
acceptable.
"""

message: str
exceptions: list[Exception]

def __init__(self, message: str, exceptions: list[Exception]) -> None:
self.message = message
self.exceptions = exceptions

def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.message!r}, {self.exceptions!r})"


@dataclasses.dataclass
class ErrorCollector:
"""
Collect errors and raise them as a group at the end (if collect_errors is True),
otherwise raise them immediately.
"""

collect_errors: bool
errors: list[Exception] = dataclasses.field(default_factory=list)

def config_error(
self,
msg: str,
*,
key: str | None = None,
got: typing.Any = None,
got_type: type[typing.Any] | None = None,
warn: bool = False,
**kwargs: typing.Any,
) -> None:
"""Raise a configuration error, or add it to the error list."""
msg = msg.format(key=f'"{key}"', **kwargs)
if got is not None:
msg = f"{msg} (got {got!r})"
if got_type is not None:
msg = f"{msg} (got {got_type.__name__})"

if warn:
warnings.warn(msg, ConfigurationWarning, stacklevel=3)
elif self.collect_errors:
self.errors.append(ConfigurationError(msg, key=key))
else:
raise ConfigurationError(msg, key=key)

def finalize(self, msg: str) -> None:
"""Raise a group exception if there are any errors."""
if self.errors:
raise ExceptionGroup(msg, self.errors)

@contextlib.contextmanager
def collect(self) -> typing.Generator[None, None, None]:
"""Support nesting; add any grouped errors to the error list."""
if self.collect_errors:
try:
yield
except ExceptionGroup as error:
self.errors.extend(error.exceptions)
else:
yield
118 changes: 118 additions & 0 deletions src/pdm/backend/_vendor/pyproject_metadata/project_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# SPDX-License-Identifier: MIT

"""
This module contains type definitions for the tables used in the
``pyproject.toml``. You should either import this at type-check time only, or
make sure ``typing_extensions`` is available for Python 3.10 and below.
Documentation notice: the fields with hyphens are not shown due to a sphinx-autodoc bug.
"""

from __future__ import annotations

import sys
from typing import Any, Dict, List, Union

if sys.version_info < (3, 11):
from typing_extensions import Required
else:
from typing import Required

if sys.version_info < (3, 8):
from typing_extensions import Literal, TypedDict
else:
from typing import Literal, TypedDict


__all__ = [
"BuildSystemTable",
"ContactTable",
"Dynamic",
"LicenseTable",
"ProjectTable",
"PyProjectTable",
"ReadmeTable",
]


def __dir__() -> list[str]:
return __all__


class ContactTable(TypedDict, total=False):
name: str
email: str


class LicenseTable(TypedDict, total=False):
text: str
file: str


ReadmeTable = TypedDict(
"ReadmeTable", {"file": str, "text": str, "content-type": str}, total=False
)

Dynamic = Literal[
"authors",
"classifiers",
"dependencies",
"description",
"dynamic",
"entry-points",
"gui-scripts",
"keywords",
"license",
"maintainers",
"optional-dependencies",
"readme",
"requires-python",
"scripts",
"urls",
"version",
]

ProjectTable = TypedDict(
"ProjectTable",
{
"name": Required[str],
"version": str,
"description": str,
"license": Union[LicenseTable, str],
"license-files": List[str],
"readme": Union[str, ReadmeTable],
"requires-python": str,
"dependencies": List[str],
"optional-dependencies": Dict[str, List[str]],
"entry-points": Dict[str, Dict[str, str]],
"authors": List[ContactTable],
"maintainers": List[ContactTable],
"urls": Dict[str, str],
"classifiers": List[str],
"keywords": List[str],
"scripts": Dict[str, str],
"gui-scripts": Dict[str, str],
"dynamic": List[Dynamic],
},
total=False,
)

BuildSystemTable = TypedDict(
"BuildSystemTable",
{
"build-backend": str,
"requires": List[str],
"backend-path": List[str],
},
total=False,
)

PyProjectTable = TypedDict(
"PyProjectTable",
{
"build-system": BuildSystemTable,
"project": ProjectTable,
"tool": Dict[str, Any],
},
total=False,
)
451 changes: 451 additions & 0 deletions src/pdm/backend/_vendor/pyproject_metadata/pyproject.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/pdm/backend/_vendor/vendor.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packaging==24.1
tomli==2.0.1
tomli_w==1.0.0
pyproject-metadata==0.9.0b4
pyproject-metadata==0.9.0b7
editables==0.5