Skip to content

Commit 5a38795

Browse files
committed
Add new "requires_python" config option which maps to Requires-Python in Core Metadata
1 parent 166b516 commit 5a38795

File tree

8 files changed

+58
-10
lines changed

8 files changed

+58
-10
lines changed

repo_helper/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def write_metadata(self, metadata_file: PathPlus):
364364
for classifier in self.config["classifiers"]:
365365
metadata["Classifier"] = classifier
366366

367-
metadata["Requires-Python"] = str(Specifier(f">={self.config['min_py_version']}"))
367+
metadata["Requires-Python"] = str(Specifier(f">={self.config['requires_python']}"))
368368
metadata["Description-Content-Type"] = "text/x-rst"
369369

370370
for requirement in sorted(combine_requirements(read_requirements(self.repo_dir / "requirements.txt")[0])):

repo_helper/configuration/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
default_python_versions,
129129
python_deploy_version,
130130
python_versions,
131+
requires_python,
131132
third_party_version_matrix
132133
)
133134
from repo_helper.configuration.testing import (
@@ -201,6 +202,7 @@
201202
"pypi_name",
202203
"python_deploy_version",
203204
"python_versions",
205+
"requires_python",
204206
"repo_name",
205207
"rtfd_author",
206208
"setup_pre",
@@ -326,6 +328,13 @@ def custom_parsing(
326328
# Python Versions
327329
versions = no_dev_versions(parsed_config_vars["python_versions"])
328330
parsed_config_vars["min_py_version"] = min_py_version = versions[0]
331+
332+
if parsed_config_vars["requires_python"] is None:
333+
if min_py_version in {"3.6", 3.6}:
334+
parsed_config_vars["requires_python"] = "3.6.1"
335+
else:
336+
parsed_config_vars["requires_python"] = min_py_version
337+
329338
smallest_py_version = Version.from_str(min_py_version)
330339
for py_version in versions:
331340
try:

repo_helper/configuration/python_versions_.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@
2828

2929
# 3rd party
3030
from configconfig.configvar import ConfigVar
31+
from configconfig.utils import RawConfigVarsType
32+
from natsort import natsorted
3133

32-
__all__ = ["python_deploy_version", "default_python_versions", "python_versions", "third_party_version_matrix"]
34+
__all__ = [
35+
"python_deploy_version",
36+
"requires_python",
37+
"default_python_versions",
38+
"python_versions",
39+
"third_party_version_matrix"
40+
]
3341

3442

3543
class python_deploy_version(ConfigVar): # noqa
@@ -49,6 +57,32 @@ class python_deploy_version(ConfigVar): # noqa
4957
category: str = "python versions"
5058

5159

60+
class requires_python(ConfigVar): # noqa
61+
"""
62+
The minimum required version of Python.
63+
64+
Example:
65+
66+
.. code-block:: yaml
67+
68+
requires_python: 3.6.1
69+
70+
.. versionadded:: $VERSION
71+
"""
72+
73+
dtype = Union[str, float]
74+
rtype = str
75+
default = None
76+
category: str = "python versions"
77+
78+
@classmethod
79+
def validate(cls, raw_config_vars: Optional[RawConfigVarsType] = None) -> Any:
80+
if cls.__name__ in raw_config_vars:
81+
return super().validate(raw_config_vars)
82+
else:
83+
return None
84+
85+
5286
def default_python_versions(raw_config_vars: Optional[Dict[str, Any]]) -> List[str]:
5387
"""
5488
Function to return the default value for :conf:`python_versions`.
@@ -81,7 +115,7 @@ class python_versions(ConfigVar): # noqa
81115

82116
@classmethod
83117
def validator(cls, value: Iterable[str]) -> List[str]: # noqa: D102
84-
return [str(ver) for ver in value if ver]
118+
return natsorted(str(ver) for ver in value if ver)
85119

86120

87121
class third_party_version_matrix(ConfigVar): # noqa

repo_helper/files/packaging.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,7 @@ def options(self):
245245
``[options]``.
246246
"""
247247

248-
if self["min_py_version"] in {"3.6", 3.6}:
249-
min_py_version = "3.6.1"
250-
else:
251-
min_py_version = self["min_py_version"]
252-
253-
self._ini["options"]["python_requires"] = f">={min_py_version}"
248+
self._ini["options"]["python_requires"] = f">={self['requires_python']}"
254249
self._ini["options"]["zip_safe"] = False
255250
self._ini["options"]["include_package_data"] = True
256251
if self["stubs_package"]:

repo_helper/repo_helper_schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@
320320
"type": "string",
321321
"description": "The name of GitHub repository, if different to :conf:`modname`."
322322
},
323+
"requires_python": {
324+
"type": [
325+
"string",
326+
"number"
327+
],
328+
"description": "The minimum required version of Python."
329+
},
323330
"rtfd_author": {
324331
"type": "string",
325332
"description": "The name of the author to show on ReadTheDocs, if different."

repo_helper/testing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def demo_environment() -> jinja2.Environment:
119119
"short_desc": "a short description",
120120
"on_pypi": true,
121121
"docs_fail_on_warning": false,
122+
"requires_python": "3.6.1",
122123
"third_party_version_matrix": {}
123124
}
124125
@@ -152,6 +153,7 @@ def test(demo_environment):
152153
enable_conda=True,
153154
enable_releases=True,
154155
python_deploy_version="3.6",
156+
requires_python="3.6.1",
155157
min_py_version="3.6",
156158
modname="hello-world",
157159
repo_name="hello-world",

tests/test_cli/test_builder_/test_write_metadata

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: 3.7
2626
Classifier: Programming Language :: Python :: 3.8
2727
Classifier: Programming Language :: Python :: Implementation :: CPython
2828
Classifier: Topic :: Utilities
29-
Requires-Python: >=3.6
29+
Requires-Python: >=3.6.1
3030
Description-Content-Type: text/x-rst
3131
Requires-Dist: alabaster>=0.7.12
3232
Requires-Dist: autodocsumm>=0.2.0

tests/test_configuration_/test_parse_yaml.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ python_versions:
8888
- '3.8'
8989
- 3.9-dev
9090
repo_name: repo_helper_demo
91+
requires_python: 3.6.1
9192
rtfd_author: Dominic Davis-Foster
9293
setup_pre: []
9394
short_desc: Update multiple configuration files, build scripts etc. from a single

0 commit comments

Comments
 (0)