Skip to content

Commit d6b47f3

Browse files
authored
Move metadata from setup.py to pyproject.toml (#165)
1 parent d4184e1 commit d6b47f3

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ tomli
55

66
# build and upload
77
build
8-
setuptools
8+
setuptools >= 77.0.3
99
twine
10-
wheel
1110

1211
# tests
1312
mypy

stub_uploader/build_wheel.py

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,40 @@
5252
"""
5353
from setuptools import setup
5454
55+
setup(package_data={package_data})
56+
"""
57+
)
58+
59+
PYPROJECT_TEMPLATE = dedent(
60+
"""
61+
[build-system]
62+
build-backend = "setuptools.build_meta"
63+
requires = ["setuptools>=77.0.3"]
64+
65+
[project]
5566
name = "{stub_distribution}"
67+
version = "{version}"
68+
license = "Apache-2.0"
69+
license-files = ["LICENSE"]
5670
description = "Typing stubs for {distribution}"
57-
long_description = '''
58-
{long_description}
59-
'''.lstrip()
60-
61-
setup(name=name,
62-
version="{version}",
63-
description=description,
64-
long_description=long_description,
65-
long_description_content_type="text/markdown",
66-
url="https://github.com/python/typeshed",
67-
project_urls={{
68-
"GitHub": "https://github.com/python/typeshed",
69-
"Changes": "https://github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/{distribution}.md",
70-
"Issue tracker": "https://github.com/python/typeshed/issues",
71-
"Chat": "https://gitter.im/python/typing",
72-
}},
73-
install_requires={requires},
74-
packages={packages},
75-
package_data={package_data},
76-
license="Apache-2.0",
77-
python_requires="{requires_python}",
78-
classifiers=[
79-
"Programming Language :: Python :: 3",
80-
"Typing :: Stubs Only",
81-
]
82-
)
71+
readme = {{ text = \"\"\"\\\n{long_description}\n\"\"\", content-type = "text/markdown" }}
72+
classifiers = [
73+
"Programming Language :: Python :: 3",
74+
"Typing :: Stubs Only",
75+
]
76+
requires-python = "{requires_python}"
77+
dependencies = {requires}
78+
79+
[project.urls]
80+
"Homepage" = "https://github.com/python/typeshed"
81+
"GitHub" = "https://github.com/python/typeshed"
82+
"Changes" = "https://github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/{distribution}.md"
83+
"Issue tracker" = "https://github.com/python/typeshed/issues"
84+
"Chat" = "https://gitter.im/python/typing"
85+
86+
[tool.setuptools]
87+
packages = {packages}
88+
include-package-data = false
8389
"""
8490
).lstrip()
8591

@@ -339,7 +345,12 @@ def is_ignored_distribution_file(entry: Path) -> bool:
339345
return False
340346

341347

342-
def generate_setup_file(
348+
def generate_setup_file(pkg_data: PackageData) -> str:
349+
"""Auto-generate a setup.py file for given distribution using a template."""
350+
return SETUP_TEMPLATE.format(package_data=pkg_data.package_data)
351+
352+
353+
def generate_pyproject_file(
343354
ts_data: TypeshedData,
344355
build_data: BuildData,
345356
pkg_data: PackageData,
@@ -355,7 +366,7 @@ def generate_setup_file(
355366
if metadata.requires_python is not None
356367
else f">={ts_data.oldest_supported_python}"
357368
)
358-
return SETUP_TEMPLATE.format(
369+
return PYPROJECT_TEMPLATE.format(
359370
distribution=build_data.distribution,
360371
stub_distribution=metadata.stub_distribution,
361372
long_description=generate_long_description(
@@ -364,7 +375,6 @@ def generate_setup_file(
364375
version=version,
365376
requires=all_requirements,
366377
packages=pkg_data.top_level_packages,
367-
package_data=pkg_data.package_data,
368378
requires_python=requires_python,
369379
)
370380

@@ -440,8 +450,9 @@ def main(
440450
else:
441451
tmpdir = Path(tempfile.mkdtemp())
442452

443-
(tmpdir / "setup.py").write_text(
444-
generate_setup_file(ts_data, build_data, pkg_data, metadata, version)
453+
(tmpdir / "setup.py").write_text(generate_setup_file(pkg_data))
454+
(tmpdir / "pyproject.toml").write_text(
455+
generate_pyproject_file(ts_data, build_data, pkg_data, metadata, version)
445456
)
446457
copy_stubs(build_data.stub_dir, tmpdir)
447458
create_py_typed(metadata, pkg_data, tmpdir)

0 commit comments

Comments
 (0)