Skip to content

Commit

Permalink
Support dot version environment names for env_list ordering (#218)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
gaborbernat and pre-commit-ci[bot] authored Sep 13, 2024
1 parent 552edc1 commit 3216527
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 33 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ jobs:
- "3.9"
- "3.8"
steps:
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: setup python for tox
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: install tox
run: python -m pip install tox-uv
run: uv pip install --system tox-uv
- uses: actions/checkout@v4
- name: setup python for test ${{ matrix.py }}
uses: actions/setup-python@v5
Expand All @@ -56,13 +61,18 @@ jobs:
- readme
steps:
- uses: actions/checkout@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: install tox
run: python -m pip install tox-uv
- name: run check for ${{ matrix.tox_env }}
run: python -m tox -e ${{ matrix.tox_env }}
env:
UPGRADE_ADVISORY: "yes"
run: uv pip install --system tox-uv
- name: setup test suite
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.tox_env }}
- name: run test suite
run: tox run --skip-pkg-install -e ${{ matrix.tox_env }}
13 changes: 9 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ jobs:
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/tox-ini-fmt
url: https://pypi.org/p/platformdirs
permissions:
id-token: write
steps:
- name: Setup python to build package
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build
run: python -m pip install build
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build package
run: pyproject-build -s -w . -o dist
run: uv build --sdist --wheel . --out-dir dist
- name: Publish to PyPI
uses: pypa/[email protected]
with:
attestations: true
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ repos:
rev: "v3.3.3"
hooks:
- id: prettier
additional_dependencies:
- [email protected]
- "@prettier/[email protected]"
args: ["--print-width=120", "--prose-wrap=always"]
- repo: meta
hooks:
- id: check-hooks-apply
Expand Down
33 changes: 17 additions & 16 deletions src/tox_ini_fmt/formatter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
from collections import defaultdict
from functools import partial
from typing import TYPE_CHECKING, Callable, Mapping
from typing import TYPE_CHECKING, Callable, Mapping, TypedDict, cast

from .requires import requires

Expand Down Expand Up @@ -81,9 +81,6 @@ def is_substitute(value: str) -> bool:
return False


_MATCHER = re.compile(r"^([a-zA-Z]*)(\d*)$")


def to_list_of_env_values(pin_toxenvs: list[str], payload: str) -> str:
"""
Expand list of tox envs.
Expand Down Expand Up @@ -133,21 +130,25 @@ def to_list_of_env_values(pin_toxenvs: list[str], payload: str) -> str:
return "\n{}".format("\n".join(f"{v}" for v in values))


def _get_py_version(pin_toxenvs: list[str], env_list: str) -> tuple[int, int]:
_TOX_ENV_MATCHER = re.compile(r"((?P<major>\d)([.](?P<minor>\d+))?)|(?P<name>[a-zA-Z]*)(?P<version>\d*)")


class _ToxMatch(TypedDict):
name: str
version: int
major: int
minor: int


def _get_py_version(pin_toxenvs: list[str], env_list: str) -> tuple[int, ...]:
for element in env_list.split("-"):
if element in pin_toxenvs:
return len(element) - pin_toxenvs.index(element), 0
match = _MATCHER.match(element)
if match is not None:
name, version = match.groups()
name = name.lower()
if name == "py":
main = 0
elif name == "pypy":
main = -1
else:
main = -2
return main, int(version) if version else 0
if match := _TOX_ENV_MATCHER.fullmatch(element):
got = cast(_ToxMatch, {k: (v if k == "name" else int(v or 0)) for k, v in match.groupdict().items()})
main = {"py": 0, "pypy": -1}.get(got.get("name") or "", -2)
version: list[int] = [got["major"], got["minor"]] if got["major"] else [got["version"]]
return main, *version
return -3, 0


Expand Down
6 changes: 6 additions & 0 deletions tests/formatter/test_tox_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def test_format_env_list_simple(tox_ini: Path) -> None:
assert outcome == "[tox]\nrequires =\n tox>=4.2\nenv_list =\n py39\n py38\n"


def test_format_env_list_dot_version(tox_ini: Path) -> None:
tox_ini.write_text("[tox]\nenv_list=3,3.13,3.9\n")
outcome = format_tox_ini(tox_ini)
assert outcome == "[tox]\nrequires =\n tox>=4.2\nenv_list =\n 3.13\n 3.9\n 3\n"


def test_format_env_list_start_newline(tox_ini: Path) -> None:
ok = "[tox]\nrequires =\n tox>=4.2\nenv_list =\n py39\n py38\n"
tox_ini.write_text(ok)
Expand Down
10 changes: 6 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ commands =

[testenv:readme]
description = check that the long description is valid
package = skip
skip_install = true
deps =
build[virtualenv]>=1.2.2
check-wheel-contents>=0.6
twine>=5.1.1
uv>=0.4.7
commands =
python -m build --sdist --wheel -o {env_tmp_dir} .
twine check {env_tmp_dir}/*
uv build --sdist --wheel --out-dir {envtmpdir} .
twine check {envtmpdir}{/}*
check-wheel-contents --no-config {envtmpdir}

[testenv:dev]
description = generate a DEV environment
Expand Down

0 comments on commit 3216527

Please sign in to comment.