Skip to content

Commit

Permalink
[PEP 771]
Browse files Browse the repository at this point in the history
  • Loading branch information
DEKHTIARJonathan committed Jan 14, 2025
1 parent fb7f3d3 commit d92218e
Show file tree
Hide file tree
Showing 14 changed files with 548 additions and 146 deletions.
171 changes: 171 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# PyPI configuration file
.pypirc
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ keywords = "setuptools.dist:Distribution._finalize_setup_keywords"
eager_resources = "setuptools.dist:assert_string_list"
namespace_packages = "setuptools.dist:check_nsp"
extras_require = "setuptools.dist:check_extras"
default_extras_require = "setuptools.dist:check_default_extras_require"
install_requires = "setuptools.dist:check_requirements"
setup_requires = "setuptools.dist:check_requirements"
python_requires = "setuptools.dist:check_specifier"
Expand Down
6 changes: 5 additions & 1 deletion setuptools/_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def get_metadata_version(self):
mv = getattr(self, 'metadata_version', None)
if mv is None:
mv = Version('2.2')
mv = Version('2.5')
self.metadata_version = mv
return mv

Expand Down Expand Up @@ -223,6 +223,9 @@ def _write_requirements(self, file):
for req in _reqs.parse(self.install_requires):
file.write(f"Requires-Dist: {req}\n")

for req in _reqs.parse(self.default_extras_require):
file.write(f"Default-Extra: {req}\n")

processed_extras = {}
for augmented_extra, reqs in self.extras_require.items():
# Historically, setuptools allows "augmented extras": `<extra>:<condition>`
Expand Down Expand Up @@ -311,6 +314,7 @@ def _distribution_fullname(name: str, version: str) -> str:
"project-url": "project_urls",
"provides": "provides",
# "provides-dist": "provides_dist", # NOT USED
"default-extra": "default_extras_require",
"provides-extra": "extras_require",
"requires": "requires",
"requires-dist": "install_requires",
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_importlib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

if sys.version_info < (3, 10):
if sys.version_info < (3, 10) or True:
import importlib_metadata as metadata # pragma: no cover
else:
import importlib.metadata as metadata # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions setuptools/_vendor/importlib_metadata/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Message(email.message.Message):
'Platform',
'Project-URL',
'Provides-Dist',
'Default-Extra'
'Provides-Extra',
'Requires-Dist',
'Requires-External',
Expand Down
14 changes: 12 additions & 2 deletions setuptools/_vendor/packaging/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class RawMetadata(TypedDict, total=False):
license_expression: str
license_files: list[str]

# Metadata 2.5 - PEP 771
default_extra: list[str]


_STRING_FIELDS = {
"author",
Expand Down Expand Up @@ -253,6 +256,7 @@ def _get_payload(msg: email.message.Message, source: bytes | str) -> str:
"author-email": "author_email",
"classifier": "classifiers",
"description": "description",
"default-extra": "default_extra",
"description-content-type": "description_content_type",
"download-url": "download_url",
"dynamic": "dynamic",
Expand Down Expand Up @@ -463,8 +467,8 @@ def parse_email(data: bytes | str) -> tuple[RawMetadata, dict[str, list[str]]]:


# Keep the two values in sync.
_VALID_METADATA_VERSIONS = ["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4"]
_MetadataVersion = Literal["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4"]
_VALID_METADATA_VERSIONS = ["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4", "2.5"]
_MetadataVersion = Literal["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4", "2.5"]

_REQUIRED_ATTRS = frozenset(["metadata_version", "name", "version"])

Expand Down Expand Up @@ -861,3 +865,9 @@ def from_email(cls, data: bytes | str, *, validate: bool = True) -> Metadata:
"""``Provides`` (deprecated)"""
obsoletes: _Validator[list[str] | None] = _Validator(added="1.1")
"""``Obsoletes`` (deprecated)"""
# PEP 771 lets us define a default `extras_require` if none is passed by the
# user.
default_extra: _Validator[list[utils.NormalizedName] | None] = _Validator(
added="2.5",
)
""":external:ref:`core-metadata-default-extra`"""
4 changes: 2 additions & 2 deletions setuptools/_vendor/wheel/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ def generate_requirements(

def pkginfo_to_metadata(egg_info_path: str, pkginfo_path: str) -> Message:
"""
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
Convert .egg-info directory with PKG-INFO to the Metadata 2.5 format
"""
with open(pkginfo_path, encoding="utf-8") as headers:
pkg_info = Parser().parse(headers)

pkg_info.replace_header("Metadata-Version", "2.1")
pkg_info.replace_header("Metadata-Version", "2.5")
# Those will be regenerated from `requires.txt`.
del pkg_info["Provides-Extra"]
del pkg_info["Requires-Dist"]
Expand Down
10 changes: 10 additions & 0 deletions setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ def _dependencies(dist: Distribution, val: list, _root_dir: StrPath | None):
dist.install_requires = val


def _default_optional_dependencies(dist: Distribution, val: dict, _root_dir: StrPath | None):
if getattr(dist, "default_extras_require", None):
msg = "`default_extras_require` overwritten in `pyproject.toml` (default-optional-dependencies)"
SetuptoolsWarning.emit(msg)
dist.default_extras_require = val


def _optional_dependencies(dist: Distribution, val: dict, _root_dir: StrPath | None):
if getattr(dist, "extras_require", None):
msg = "`extras_require` overwritten in `pyproject.toml` (optional-dependencies)"
Expand Down Expand Up @@ -396,6 +403,7 @@ def _acessor(obj):
"urls": _project_urls,
"dependencies": _dependencies,
"optional_dependencies": _optional_dependencies,
"default_optional_dependencies": _default_optional_dependencies,
"requires_python": _python_requires,
}

Expand Down Expand Up @@ -441,6 +449,7 @@ def _acessor(obj):
"scripts": _get_previous_scripts,
"gui-scripts": _get_previous_gui_scripts,
"dependencies": _attrgetter("install_requires"),
"default-optional-dependencies": _attrgetter("default_extras_require"),
"optional-dependencies": _attrgetter("extras_require"),
}

Expand All @@ -458,6 +467,7 @@ def _acessor(obj):
"scripts": _static.EMPTY_DICT,
"gui-scripts": _static.EMPTY_DICT,
"dependencies": _static.EMPTY_LIST,
"default-optional-dependencies": _static.EMPTY_LIST,
"optional-dependencies": _static.EMPTY_DICT,
}

Expand Down
32 changes: 31 additions & 1 deletion setuptools/config/_validate_pyproject/extra_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class RedefiningStaticFieldAsDynamic(ValidationError):
)


class IncludedDependencyGroupMustExist(ValidationError):
_DESC = """An included dependency group must exist and must not be cyclic.
"""
__doc__ = _DESC
_URL = "https://peps.python.org/pep-0735/"


def validate_project_dynamic(pyproject: T) -> T:
project_table = pyproject.get("project", {})
dynamic = project_table.get("dynamic", [])
Expand All @@ -49,4 +56,27 @@ def validate_project_dynamic(pyproject: T) -> T:
return pyproject


EXTRA_VALIDATIONS = (validate_project_dynamic,)
def validate_include_depenency(pyproject: T) -> T:
dependency_groups = pyproject.get("dependency-groups", {})
for key, value in dependency_groups.items():
for each in value:
if (
isinstance(each, dict)
and (include_group := each.get("include-group"))
and include_group not in dependency_groups
):
raise IncludedDependencyGroupMustExist(
message=f"The included dependency group {include_group} doesn't exist",
value=each,
name=f"data.dependency_groups.{key}",
definition={
"description": cleandoc(IncludedDependencyGroupMustExist._DESC),
"see": IncludedDependencyGroupMustExist._URL,
},
rule="PEP 735",
)
# TODO: check for `include-group` cycles (can be conditional to graphlib)
return pyproject


EXTRA_VALIDATIONS = (validate_project_dynamic, validate_include_depenency)
377 changes: 242 additions & 135 deletions setuptools/config/_validate_pyproject/fastjsonschema_validations.py

Large diffs are not rendered by default.

Loading

0 comments on commit d92218e

Please sign in to comment.