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

Add support for pyproject.toml-style configuration (PEP 621) #2924

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e97fd76
Rename `config` to `config.setupcfg`
abravalheri Dec 1, 2021
e4b1f1f
Extract post-processing functions from config
abravalheri Dec 2, 2021
55c0459
Allow root_dir to be explicit in config.expand functions
abravalheri Dec 2, 2021
5fc5170
Allow single strings in config.expand.read_files
abravalheri Dec 3, 2021
a6a2dea
Extract version normalisation from config to expand
abravalheri Dec 3, 2021
4664442
Extract function to normalise package_data
abravalheri Dec 6, 2021
299632a
Extract function to normalise data_files
abravalheri Dec 6, 2021
925feb9
Remove unused _parse_list_glob
abravalheri Dec 6, 2021
160c3a3
Add cmdclass to expand
abravalheri Dec 6, 2021
92b2a68
Allow cmdclass to be expanded with custom package layouts
abravalheri Dec 7, 2021
9dc0a8f
Add root_dir option to expand.find_packages
abravalheri Dec 7, 2021
17802ef
Add `tomli` as vendorised dependency
abravalheri Dec 2, 2021
029b9c5
Add `validate-pyproject` as a vendored dependency
abravalheri Dec 3, 2021
55a9eb7
Implement read_configuration from pyproject.toml
abravalheri Dec 3, 2021
ae06587
Expand dynamic entry_points from pyproject.toml
abravalheri Dec 9, 2021
a54da74
Add means to apply and compare pyproject.toml metadata
abravalheri Dec 9, 2021
8c5a4b7
Add means to apply and compare options from pyproject.toml
abravalheri Dec 9, 2021
9928786
Handle distutils command options in setuptools.options
abravalheri Dec 9, 2021
39eeeae
Rename setuptools.config.{setupcfg => legacy_setupcfg}
abravalheri Dec 9, 2021
c63c58a
Add `ini2toml` as a vendored dependency
abravalheri Dec 3, 2021
6e86080
Automatically convert `setup.cfg` => `pyproject.toml`
abravalheri Dec 9, 2021
36518e9
Avoid manipulating sys.path in config.expand
abravalheri Dec 9, 2021
3c293b5
Add means to reconstruct metadata dict from dist object
abravalheri Dec 9, 2021
ce32429
Add means to reconstruct options dict from dist
abravalheri Dec 9, 2021
f868ad2
Rename and adapt test_config to test_legacy_setupcfg
abravalheri Dec 9, 2021
d134aaf
Improve circular imports
abravalheri Dec 10, 2021
a316958
Fix config.pyproject attempting to expand already expanded packages
abravalheri Dec 10, 2021
25ddead
Improve setuptools.{metadata,options} conversion and comparison
abravalheri Dec 10, 2021
a307352
Separate read and apply operations in config.legacy_setupcfg
abravalheri Dec 10, 2021
edc8992
Add a way of displaying the diff between 2 objects
abravalheri Dec 10, 2021
c431c06
Add checks to make sure automatic conversion of configs work
abravalheri Dec 10, 2021
045123a
Add a new public API for reading setuptools configuration
abravalheri Dec 10, 2021
38db91c
Ensure examples work with the automatic conversion of setup.cfg
abravalheri Dec 10, 2021
629d26b
Make it possible to ignore `setup.cfg` in dist.parse_config_files
abravalheri Dec 10, 2021
a401091
Clean metadata/options if the file is not being used to configure set…
abravalheri Dec 11, 2021
dabbbf1
Use run_setup to obtain a dist object and apply the new configs
abravalheri Dec 11, 2021
972248f
Use the distribution object to run commands in build_meta
abravalheri Dec 11, 2021
a356376
Replace _get_build_requires by using the dist object
abravalheri Dec 11, 2021
3dd56ed
Change test_build_meta accordingly
abravalheri Dec 11, 2021
373e201
Prevent bootstrap problems with vendored dependencies in config
abravalheri Dec 11, 2021
0c18c78
Prevent tests from copying the .git/.tox and other heavy folders
abravalheri Dec 11, 2021
e128ba4
Add backend test with pyproject.toml-only config
abravalheri Dec 11, 2021
1140792
Make include_package_data=True for `pyproject.toml` configs
abravalheri Dec 11, 2021
b63a56a
Add news fragment
abravalheri Dec 12, 2021
077c2be
Add 'dist_info' to the bootstrap entry-points
abravalheri Dec 12, 2021
3758633
Add 'develop' to the bootstrap entry-points
abravalheri Dec 12, 2021
67f7ef9
Use finalize_requires to process optional-dependencies for editable i…
abravalheri Dec 20, 2021
574cb20
Fix test_bdist_deprecations
abravalheri Dec 20, 2021
30cdd31
Use uuid4 to improve tempfile parallel creation
abravalheri Dec 20, 2021
2c6b144
Adequate tests and code to run on Windows
abravalheri Dec 20, 2021
f765076
Add 'install_scripts' to the bootstrap entry-points
abravalheri Dec 21, 2021
3179349
Add 'install_egg_info' and 'bdist_egg' to the bootstrap entry-points
abravalheri Dec 21, 2021
fb3dc26
[WIP] Attempt to debug failures with cygwin CI
abravalheri Dec 21, 2021
72904ab
[WIP] Attempt to fix problem with cygwin
abravalheri Dec 21, 2021
bfcafd5
Manually add missing license files for vendored projects
abravalheri Dec 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ setuptools.egg-info
.idea/
.pytest_cache/
.mypy_cache/
/setuptools/tests/config/downloads
5 changes: 5 additions & 0 deletions bootstrap.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
egg_info = setuptools.command.egg_info:egg_info
build_py = setuptools.command.build_py:build_py
sdist = setuptools.command.sdist:sdist
dist_info = setuptools.command.dist_info:dist_info
develop = setuptools.command.develop:develop
install_scripts = setuptools.command.install_scripts:install_scripts
bdist_egg = setuptools.command.bdist_egg:bdist_egg
install_egg_info = setuptools.command.install_egg_info:install_egg_info

[distutils.setup_keywords]
include_package_data = setuptools.dist:assert_bool
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/2924.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Removed public class ``SetupRequirementsError`` from the
``setuptools.build_meta`` module.
14 changes: 14 additions & 0 deletions changelog.d/2924.change.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Added **experimental** support for ``pyproject.toml`` configuration
(as introduced by :pep:`621`). Configuration parameters not covered by
standards are handled in the ``[tool.setuptools]`` sub-table.

Existing ``setup.cfg`` configuration is now automatically converted into the
``pyproject.toml`` equivalent before taking effect (as proposed in
:issue:`1688`).
During the transition period, if this conversion results in non compatible
settings, setuptools will fallback to the previous behaviour.

Please note that the legacy backend does not support ``pyproject.toml``
configuration.

-- by :user:`abravalheri`.
5 changes: 5 additions & 0 deletions changelog.d/2924.change.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added vendored dependencies for :pypi:`tomli`,
:pypi:`validate-pyproject` and :pypi:`ini2toml`.

These dependencies are used to read ``pyproject.toml``
or automatically convert existing ``setup.cfg`` files.
3 changes: 3 additions & 0 deletions changelog.d/2924.change.3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changed means of interaction between ``setuptools.build_meta`` and
``setuptools.setup``. Instead of simply executing the script, the backend now
relies on ``distutils.core.run_setup`` to obtain a distribution object.
7 changes: 7 additions & 0 deletions changelog.d/2924.deprecation.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Deprecated ``setuptools.config.read_configuration``,
``setuptools.config.parse_configuration`` and other functions or classes
from ``setuptools.config``.

This API is now replaced by ``setuptools.config.read`` and
``setuptools.config.apply``, which *do not output* the same format of data
(instead they are oriented toward the ``pyproject.toml`` format).
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@
# Add support for linking usernames
github_url = 'https://github.com'
github_sponsors_url = f'{github_url}/sponsors'
repository = f'{github_url}/pypa/setuptools'
extlinks = {
'user': (f'{github_sponsors_url}/%s', '@'), # noqa: WPS323
'issue': (f'{repository}/issues/%s', 'issue #%s'), # noqa: WPS323
'pr': (f'{repository}/pull/%s', 'PR #%s'), # noqa: WPS323
'pypi': ('https://pypi.org/project/%s', '%s'), # noqa: WPS323
}
extensions += ['sphinx.ext.extlinks']

Expand Down
64 changes: 63 additions & 1 deletion pavement.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
import re
import sys
import shutil
import subprocess
import venv
import string
from tempfile import TemporaryDirectory

from paver.easy import task, path as Path
from paver.easy import info, task, path as Path


def remove_all(paths):
Expand Down Expand Up @@ -55,7 +60,9 @@ def install(vendor):
remove_all(vendor.glob('*.dist-info'))
remove_all(vendor.glob('*.egg-info'))
remove_all(vendor.glob('six.py'))
remove_ini2toml_extras(vendor)
(vendor / '__init__.py').write_text('')
(vendor / 'bin').rmtree()


def update_pkg_resources():
Expand All @@ -67,4 +74,59 @@ def update_pkg_resources():
def update_setuptools():
vendor = Path('setuptools/_vendor')
install(vendor)
install_validate_pyproject(vendor)
rewrite_packaging(vendor / 'packaging', 'setuptools.extern')


def install_validate_pyproject(vendor):
"""``validate-pyproject`` can be vendorized to remove all dependencies"""
req = next(
(x for x in (vendor / "vendored.txt").lines() if 'validate-pyproject' in x),
"validate-pyproject[all]"
)

pkg, _, _ = req.strip(string.whitespace + "#").partition("#")
pkg = pkg.strip()

opts = {}
if sys.version_info[:2] >= (3, 10):
opts["ignore_cleanup_errors"] = True

with TemporaryDirectory(**opts) as tmp:
venv.create(tmp, with_pip=True)
path = os.pathsep.join(Path(tmp).glob("*"))
venv_python = shutil.which("python", path=path)
info(f"Temporarily installing {pkg!r}...")
subprocess.check_call([venv_python, "-m", "pip", "install", pkg])
cmd = [
venv_python,
"-m",
"validate_pyproject.vendoring",
"--output-dir",
str(vendor / "_validate_pyproject"),
"--enable-plugins",
"setuptools",
"distutils",
"--very-verbose"
]
subprocess.check_output(cmd)
info(f"{pkg!r} vendorized")


def remove_ini2toml_extras(vendor):
"""Remove unnecessary files from `ini2toml`"""
unecessary = [
"ini2toml/__main__.py",
"ini2toml/api.py",
"ini2toml/cli.py",
"ini2toml/drivers/configupdater.py",
"ini2toml/drivers/full_toml.py",
"ini2toml/drivers/lite_toml.py",
"ini2toml/plugins/coverage.py",
"ini2toml/plugins/isort.py",
"ini2toml/plugins/mypy.py",
"ini2toml/plugins/profile_independent_tasks.py",
"ini2toml/plugins/pytest.py",
"ini2toml/translator.py",
]
remove_all(vendor / file for file in unecessary)