Skip to content

Commit

Permalink
- use a default value mapping for pyproject.toml generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Sep 7, 2024
1 parent 1879842 commit 5c3dcc0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
35 changes: 16 additions & 19 deletions config/config-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from shared.packages import MANYLINUX_PYTHON_VERSION
from shared.packages import MANYLINUX_X86_64
from shared.packages import OLDEST_PYTHON_VERSION
from shared.packages import PYPROJECT_TOML_DEFAULTS
from shared.packages import PYPY_VERSION
from shared.packages import SETUPTOOLS_VERSION_SPEC
from shared.path import change_dir
Expand Down Expand Up @@ -553,28 +554,24 @@ def manifest_in(self):
def pyproject_toml(self):
"""Modify pyproject.toml with meta options."""
pyproject_toml_path = self.path / 'pyproject.toml'
pyproject_data = {}

if pyproject_toml_path.exists():
with open(pyproject_toml_path, 'rb') as fp:
pyproject_data = tomlkit.load(fp)
pyproject_toml = collections.defaultdict(dict, **pyproject_data)
else:
pyproject_toml = collections.defaultdict(dict)

buildsystem_cfg = pyproject_toml['build-system']

# Insert sane default for build-system:requires
requires = buildsystem_cfg.get('requires', [])
setuptools_requirement = [
x for x in requires if x.startswith('setuptools')]
for setuptools_req in setuptools_requirement:
requires.remove(setuptools_req)
requires.append(f'setuptools{SETUPTOOLS_VERSION_SPEC}')
buildsystem_cfg['requires'] = sorted(requires)

# Insert sane default for build-system:build-backend
build_backend = buildsystem_cfg.get('build-backend', '')
if not build_backend:
buildsystem_cfg['build-backend'] = 'setuptools.build_meta'
pyproject_toml = collections.defaultdict(dict, **pyproject_data)
old_requires = pyproject_toml['build-system'].get('requires', [])

# Update/overwrite existing values with our defaults
pyproject_toml.update(PYPROJECT_TOML_DEFAULTS)

# Add prior requires values back
if old_requires:
setuptools_requirement = [
x for x in old_requires if x.startswith('setuptools')]
for setuptools_req in setuptools_requirement:
old_requires.remove(setuptools_req)
pyproject_toml['build-system']['requires'].extend(old_requires)

# Remove empty sections before writing to disk
pyproject_toml = {k: v for k, v in pyproject_toml.items() if v}
Expand Down
6 changes: 6 additions & 0 deletions config/shared/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
MANYLINUX_AARCH64 = 'manylinux2014_aarch64'
MANYLINUX_I686 = 'manylinux2014_i686'
MANYLINUX_X86_64 = 'manylinux2014_x86_64'
PYPROJECT_TOML_DEFAULTS = {
'build-system': {
'requires': [f'setuptools{SETUPTOOLS_VERSION_SPEC}'],
'build-backend': 'setuptools.build_meta',
},
}


def list_packages(path: pathlib.Path) -> list:
Expand Down

0 comments on commit 5c3dcc0

Please sign in to comment.