Skip to content

Commit 30cc8b8

Browse files
committed
Update pyproject.toml metadata for setuptools
1 parent 4622f99 commit 30cc8b8

File tree

5 files changed

+105
-25
lines changed

5 files changed

+105
-25
lines changed

repo_helper/files/packaging.py

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def make_pyproject(repo_path: pathlib.Path, templates: Environment) -> List[str]
152152
data = DefaultDict()
153153

154154
data.set_default("build-system", {})
155+
data.set_default("tool", {})
156+
155157
build_backend = "setuptools.build_meta"
156158

157159
build_requirements_ = {
@@ -198,39 +200,56 @@ def make_pyproject(repo_path: pathlib.Path, templates: Environment) -> List[str]
198200
data["project"]["license"] = {"file": "LICENSE"}
199201

200202
if templates.globals["requires_python"] is not None:
201-
data["project"]["dynamic"].pop(0)
203+
data["project"]["dynamic"].remove("requires-python")
202204
data["project"]["requires-python"] = f">={templates.globals['requires_python']}"
203-
204-
url = "https://github.com/{username}/{repo_name}".format_map(templates.globals)
205-
data["project"]["urls"] = {
206-
"Homepage": url,
207-
"Issue Tracker": "https://github.com/{username}/{repo_name}/issues".format_map(templates.globals),
208-
"Source Code": url,
209-
}
210-
211-
if templates.globals["enable_docs"]:
212-
data["project"]["urls"]["Documentation"] = templates.globals["docs_url"]
213-
214-
if templates.globals["use_flit"]:
215-
data["project"]["dynamic"] = []
216-
205+
elif not templates.globals["use_whey"]:
217206
if templates.globals["requires_python"] is None:
218207
if templates.globals["min_py_version"] in {"3.6", 3.6}:
219208
requires_python = "3.6.1"
220209
else:
221210
requires_python = templates.globals["min_py_version"]
222211
else:
223212
requires_python = templates.globals["requires_python"]
213+
if "requires-python" in data["project"]["dynamic"]:
214+
data["project"]["dynamic"].remove("requires-python")
224215

225216
data["project"]["requires-python"] = f">={requires_python}"
217+
elif "requires-python" in data["project"]:
218+
del data["project"]["requires-python"]
219+
220+
if not templates.globals["use_whey"]:
221+
data["project"]["dynamic"] = []
226222
data["project"]["classifiers"] = _get_classifiers(templates.globals)
227-
parsed_requirements, comments, invalid_lines = read_requirements(repo_path / "requirements.txt", include_invalid=True)
228-
if invalid_lines:
229-
raise NotImplementedError(f"Unsupported requirement type(s): {invalid_lines}")
230-
data["project"]["dependencies"] = sorted(parsed_requirements)
231223

232-
# extras-require
224+
if templates.globals["use_flit"]:
225+
parsed_requirements, comments, invalid_lines = read_requirements(repo_path / "requirements.txt", include_invalid=True)
226+
if invalid_lines:
227+
raise NotImplementedError(f"Unsupported requirement type(s): {invalid_lines}")
228+
data["project"]["dependencies"] = sorted(parsed_requirements)
229+
else:
230+
# TODO: currently broken by setuptools; have to omit for it to work
231+
# data["project"]["dynamic"].append("dependencies")
232+
233+
data["tool"].setdefault("setuptools", {})
234+
data["tool"]["setuptools"]["zip-safe"] = False
235+
data["tool"]["setuptools"]["include-package-data"] = True
236+
data["tool"]["setuptools"]["platforms"] = [
237+
"Windows",
238+
"macOS",
239+
"Linux",
240+
]
241+
242+
url = "https://github.com/{username}/{repo_name}".format_map(templates.globals)
243+
data["project"]["urls"] = {
244+
"Homepage": url,
245+
"Issue Tracker": "https://github.com/{username}/{repo_name}/issues".format_map(templates.globals),
246+
"Source Code": url,
247+
}
248+
249+
if templates.globals["enable_docs"]:
250+
data["project"]["urls"]["Documentation"] = templates.globals["docs_url"]
233251

252+
# extras-require
234253
data["project"]["optional-dependencies"] = {}
235254

236255
for extra, dependencies in templates.globals["extras_require"].items():
@@ -253,7 +272,6 @@ def make_pyproject(repo_path: pathlib.Path, templates: Environment) -> List[str]
253272
del data["project"]["entry-points"]
254273

255274
# tool
256-
data.set_default("tool", {})
257275

258276
# tool.mkrecipe
259277
if templates.globals["enable_conda"]:
@@ -311,6 +329,8 @@ def make_pyproject(repo_path: pathlib.Path, templates: Environment) -> List[str]
311329
# templates.globals["source_dir"],
312330
templates.globals["import_name"].split('.', 1)[0],
313331
)
332+
elif "package" in data["tool"]["whey"]:
333+
del data["tool"]["whey"]["package"]
314334

315335
if templates.globals["manifest_additional"]:
316336
data["tool"]["whey"]["additional-files"] = templates.globals["manifest_additional"]

tests/test_files/test_packaging_/test_make_pyproject_docs_no_tests_backend_setuptools_.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ version = "2020.1.1"
88
description = "a short description"
99
readme = "README.rst"
1010
keywords = [ "awesome", "project", "python",]
11-
dynamic = [ "requires-python", "classifiers", "dependencies",]
11+
dynamic = []
12+
requires-python = ">=3.6.1"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
"Operating System :: Microsoft :: Windows",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Programming Language :: Python :: 3.6",
19+
"Programming Language :: Python :: 3.7",
20+
"Programming Language :: Python :: Implementation :: CPython",
21+
]
1222

1323
[[project.authors]]
1424
name = "E. Xample"
@@ -24,6 +34,11 @@ Homepage = "https://github.com/octocat/hello-world"
2434
"Source Code" = "https://github.com/octocat/hello-world"
2535
Documentation = "https://hello-world.readthedocs.io/en/latest"
2636

37+
[tool.setuptools]
38+
zip-safe = false
39+
include-package-data = true
40+
platforms = [ "Windows", "macOS", "Linux",]
41+
2742
[tool.mkrecipe]
2843
conda-channels = []
2944
extras = "none"

tests/test_files/test_packaging_/test_make_pyproject_docs_tests_backend_setuptools_.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ version = "2020.1.1"
88
description = "a short description"
99
readme = "README.rst"
1010
keywords = [ "awesome", "project", "python",]
11-
dynamic = [ "requires-python", "classifiers", "dependencies",]
11+
dynamic = []
12+
requires-python = ">=3.6.1"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
"Operating System :: Microsoft :: Windows",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Programming Language :: Python :: 3.6",
19+
"Programming Language :: Python :: 3.7",
20+
"Programming Language :: Python :: Implementation :: CPython",
21+
]
1222

1323
[[project.authors]]
1424
name = "E. Xample"
@@ -24,6 +34,11 @@ Homepage = "https://github.com/octocat/hello-world"
2434
"Source Code" = "https://github.com/octocat/hello-world"
2535
Documentation = "https://hello-world.readthedocs.io/en/latest"
2636

37+
[tool.setuptools]
38+
zip-safe = false
39+
include-package-data = true
40+
platforms = [ "Windows", "macOS", "Linux",]
41+
2742
[tool.mkrecipe]
2843
conda-channels = []
2944
extras = "none"

tests/test_files/test_packaging_/test_make_pyproject_no_docs_no_tests_backend_setuptools_.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ version = "2020.1.1"
88
description = "a short description"
99
readme = "README.rst"
1010
keywords = [ "awesome", "project", "python",]
11-
dynamic = [ "requires-python", "classifiers", "dependencies",]
11+
dynamic = []
12+
requires-python = ">=3.6.1"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
"Operating System :: Microsoft :: Windows",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Programming Language :: Python :: 3.6",
19+
"Programming Language :: Python :: 3.7",
20+
"Programming Language :: Python :: Implementation :: CPython",
21+
]
1222

1323
[[project.authors]]
1424
name = "E. Xample"
@@ -23,6 +33,11 @@ Homepage = "https://github.com/octocat/hello-world"
2333
"Issue Tracker" = "https://github.com/octocat/hello-world/issues"
2434
"Source Code" = "https://github.com/octocat/hello-world"
2535

36+
[tool.setuptools]
37+
zip-safe = false
38+
include-package-data = true
39+
platforms = [ "Windows", "macOS", "Linux",]
40+
2641
[tool.mkrecipe]
2742
conda-channels = []
2843
extras = "none"

tests/test_files/test_packaging_/test_make_pyproject_no_docs_tests_backend_setuptools_.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ version = "2020.1.1"
88
description = "a short description"
99
readme = "README.rst"
1010
keywords = [ "awesome", "project", "python",]
11-
dynamic = [ "requires-python", "classifiers", "dependencies",]
11+
dynamic = []
12+
requires-python = ">=3.6.1"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
"Operating System :: Microsoft :: Windows",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Programming Language :: Python :: 3.6",
19+
"Programming Language :: Python :: 3.7",
20+
"Programming Language :: Python :: Implementation :: CPython",
21+
]
1222

1323
[[project.authors]]
1424
name = "E. Xample"
@@ -23,6 +33,11 @@ Homepage = "https://github.com/octocat/hello-world"
2333
"Issue Tracker" = "https://github.com/octocat/hello-world/issues"
2434
"Source Code" = "https://github.com/octocat/hello-world"
2535

36+
[tool.setuptools]
37+
zip-safe = false
38+
include-package-data = true
39+
platforms = [ "Windows", "macOS", "Linux",]
40+
2641
[tool.mkrecipe]
2742
conda-channels = []
2843
extras = "none"

0 commit comments

Comments
 (0)