Skip to content

Commit

Permalink
Correctly handle projects which only support PyPy
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Apr 12, 2021
1 parent 5fc3fb6 commit cffdb8a
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 6 deletions.
38 changes: 35 additions & 3 deletions repo_helper/configuration/__init__.py
Expand Up @@ -26,8 +26,22 @@
# stdlib
import json
import re
from contextlib import suppress
from io import StringIO
from typing import Any, Callable, Dict, Iterable, List, Mapping, MutableMapping, Optional, Sequence, Set, Union
from typing import (
Any,
Callable,
Dict,
Iterable,
Iterator,
List,
Mapping,
MutableMapping,
Optional,
Sequence,
Set,
Union
)

# 3rd party
import click
Expand All @@ -38,6 +52,7 @@
from domdf_python_tools.paths import PathPlus
from domdf_python_tools.typing import PathLike
from domdf_python_tools.versions import Version
from first import first
from natsort import natsorted
from ruamel.yaml import YAML

Expand Down Expand Up @@ -329,7 +344,7 @@ 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]
parsed_config_vars["min_py_version"] = min_py_version = first(_pure_version_numbers(*versions))

if parsed_config_vars["requires_python"] is None:
if min_py_version in {"3.6", 3.6}:
Expand All @@ -338,7 +353,7 @@ def custom_parsing(
parsed_config_vars["requires_python"] = min_py_version

smallest_py_version = Version.from_str(min_py_version)
for py_version in versions:
for py_version in _pure_version_numbers(*versions):
try:
if Version.from_str(py_version) < smallest_py_version:
smallest_py_version = Version.from_str(py_version)
Expand Down Expand Up @@ -507,3 +522,20 @@ def sort_func(values):
self.dump_to_file(data, filename, mode='w')
else:
self.dump_to_file({key: sort_func(new_value)}, filename, mode='a') # type: ignore


_pypy_version_re = re.compile(r"pypy3([0-9])", flags=re.IGNORECASE)


def _pure_version_numbers(*version_numbers) -> Iterator[str]:
for version in version_numbers:

pypy_version_match = _pypy_version_re.match(version)

if isinstance(version, (float, int)):
yield str(version_numbers)
elif pypy_version_match:
yield f"3.{pypy_version_match.group(1)}"
else:
with suppress(ValueError):
yield str(float(version))
13 changes: 10 additions & 3 deletions repo_helper/files/packaging.py
Expand Up @@ -29,7 +29,7 @@
import posixpath
import re
import textwrap
from typing import Any, Dict, List, Tuple, TypeVar
from typing import Any, Dict, Iterable, List, Tuple, TypeVar

# 3rd party
import dom_toml
Expand All @@ -42,6 +42,7 @@
# this package
import repo_helper.files
from repo_helper.configupdater2 import ConfigUpdater
from repo_helper.configuration import _pypy_version_re
from repo_helper.configuration.utils import get_version_classifiers
from repo_helper.files import management
from repo_helper.utils import IniConfigurator, indent_join, indent_with_tab, license_lookup, reformat_file
Expand Down Expand Up @@ -119,6 +120,9 @@ def make_manifest(repo_path: pathlib.Path, templates: jinja2.Environment) -> Lis
return [file.name]


pre_release_re = re.compile(".*(-dev|alpha|beta)", re.IGNORECASE)


@management.register("pyproject")
def make_pyproject(repo_path: pathlib.Path, templates: jinja2.Environment) -> List[str]:
"""
Expand Down Expand Up @@ -235,15 +239,18 @@ def make_pyproject(repo_path: pathlib.Path, templates: jinja2.Environment) -> Li
for py_version in templates.globals["python_versions"]:
py_version = str(py_version)

if re.match(".*(-dev|alpha|beta)", py_version):
if pre_release_re.match(py_version):
continue

pypy_version_m = _pypy_version_re.match(py_version)

if py_version.startswith('3'):
python_versions.add(py_version)
python_implementations.add("CPython")

elif py_version.lower().startswith("pypy"):
elif pypy_version_m:
python_implementations.add("PyPy")
python_versions.add(f"3.{pypy_version_m.group(1)}")

data["tool"]["whey"]["python-versions"] = sorted(python_versions)
data["tool"]["whey"]["python-implementations"] = sorted(python_implementations)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -8,6 +8,7 @@ dom-toml>=0.2.2
domdf-python-tools>=2.7.0
dulwich>=0.19.16
email-validator==1.1.2
first>=2.0.2
idna==2.10
isort>=5.0.0
jinja2>=2.11.2
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_show_/test_requirements_3_10__.tree
Expand Up @@ -87,6 +87,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_show_/test_requirements_3_6_.tree
Expand Up @@ -122,6 +122,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_show_/test_requirements_3_7_.tree
Expand Up @@ -110,6 +110,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_show_/test_requirements_3_8_.tree
Expand Up @@ -101,6 +101,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_show_/test_requirements_3_9_.tree
Expand Up @@ -89,6 +89,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
Expand Up @@ -87,6 +87,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
Expand Up @@ -122,6 +122,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
Expand Up @@ -110,6 +110,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
Expand Up @@ -101,6 +101,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down
Expand Up @@ -89,6 +89,7 @@ repo_helper==2020.12.18
├── email-validator==1.1.2
│ ├── dnspython>=1.15.0
│ └── idna>=2.0.0
├── first>=2.0.2
├── idna==2.10
├── isort>=5.0.0
├── jinja2>=2.11.2
Expand Down

0 comments on commit cffdb8a

Please sign in to comment.