Skip to content

Commit

Permalink
Add new "requires_python" config option which maps to Requires-Python…
Browse files Browse the repository at this point in the history
… in Core Metadata
  • Loading branch information
domdfcoding committed Feb 17, 2021
1 parent 166b516 commit 5a38795
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion repo_helper/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def write_metadata(self, metadata_file: PathPlus):
for classifier in self.config["classifiers"]:
metadata["Classifier"] = classifier

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

for requirement in sorted(combine_requirements(read_requirements(self.repo_dir / "requirements.txt")[0])):
Expand Down
9 changes: 9 additions & 0 deletions repo_helper/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
default_python_versions,
python_deploy_version,
python_versions,
requires_python,
third_party_version_matrix
)
from repo_helper.configuration.testing import (
Expand Down Expand Up @@ -201,6 +202,7 @@
"pypi_name",
"python_deploy_version",
"python_versions",
"requires_python",
"repo_name",
"rtfd_author",
"setup_pre",
Expand Down Expand Up @@ -326,6 +328,13 @@ def custom_parsing(
# Python Versions
versions = no_dev_versions(parsed_config_vars["python_versions"])
parsed_config_vars["min_py_version"] = min_py_version = versions[0]

if parsed_config_vars["requires_python"] is None:
if min_py_version in {"3.6", 3.6}:
parsed_config_vars["requires_python"] = "3.6.1"
else:
parsed_config_vars["requires_python"] = min_py_version

smallest_py_version = Version.from_str(min_py_version)
for py_version in versions:
try:
Expand Down
38 changes: 36 additions & 2 deletions repo_helper/configuration/python_versions_.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@

# 3rd party
from configconfig.configvar import ConfigVar
from configconfig.utils import RawConfigVarsType
from natsort import natsorted

__all__ = ["python_deploy_version", "default_python_versions", "python_versions", "third_party_version_matrix"]
__all__ = [
"python_deploy_version",
"requires_python",
"default_python_versions",
"python_versions",
"third_party_version_matrix"
]


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


class requires_python(ConfigVar): # noqa
"""
The minimum required version of Python.
Example:
.. code-block:: yaml
requires_python: 3.6.1
.. versionadded:: $VERSION
"""

dtype = Union[str, float]
rtype = str
default = None
category: str = "python versions"

@classmethod
def validate(cls, raw_config_vars: Optional[RawConfigVarsType] = None) -> Any:
if cls.__name__ in raw_config_vars:
return super().validate(raw_config_vars)
else:
return None


def default_python_versions(raw_config_vars: Optional[Dict[str, Any]]) -> List[str]:
"""
Function to return the default value for :conf:`python_versions`.
Expand Down Expand Up @@ -81,7 +115,7 @@ class python_versions(ConfigVar): # noqa

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


class third_party_version_matrix(ConfigVar): # noqa
Expand Down
7 changes: 1 addition & 6 deletions repo_helper/files/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@ def options(self):
``[options]``.
"""

if self["min_py_version"] in {"3.6", 3.6}:
min_py_version = "3.6.1"
else:
min_py_version = self["min_py_version"]

self._ini["options"]["python_requires"] = f">={min_py_version}"
self._ini["options"]["python_requires"] = f">={self['requires_python']}"
self._ini["options"]["zip_safe"] = False
self._ini["options"]["include_package_data"] = True
if self["stubs_package"]:
Expand Down
7 changes: 7 additions & 0 deletions repo_helper/repo_helper_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@
"type": "string",
"description": "The name of GitHub repository, if different to :conf:`modname`."
},
"requires_python": {
"type": [
"string",
"number"
],
"description": "The minimum required version of Python."
},
"rtfd_author": {
"type": "string",
"description": "The name of the author to show on ReadTheDocs, if different."
Expand Down
2 changes: 2 additions & 0 deletions repo_helper/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def demo_environment() -> jinja2.Environment:
"short_desc": "a short description",
"on_pypi": true,
"docs_fail_on_warning": false,
"requires_python": "3.6.1",
"third_party_version_matrix": {}
}
Expand Down Expand Up @@ -152,6 +153,7 @@ def test(demo_environment):
enable_conda=True,
enable_releases=True,
python_deploy_version="3.6",
requires_python="3.6.1",
min_py_version="3.6",
modname="hello-world",
repo_name="hello-world",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_builder_/test_write_metadata
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Utilities
Requires-Python: >=3.6
Requires-Python: >=3.6.1
Description-Content-Type: text/x-rst
Requires-Dist: alabaster>=0.7.12
Requires-Dist: autodocsumm>=0.2.0
Expand Down
1 change: 1 addition & 0 deletions tests/test_configuration_/test_parse_yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ python_versions:
- '3.8'
- 3.9-dev
repo_name: repo_helper_demo
requires_python: 3.6.1
rtfd_author: Dominic Davis-Foster
setup_pre: []
short_desc: Update multiple configuration files, build scripts etc. from a single
Expand Down

0 comments on commit 5a38795

Please sign in to comment.