From 7ff742f906507011da6067fb5ff85182700c2b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Thu, 24 Oct 2024 09:29:57 -0700 Subject: [PATCH] Move to action to share code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor --- .github/workflows/check.yaml | 25 +-------- .github/workflows/mirror.yaml | 13 +---- pyproject.toml | 103 ---------------------------------- tasks/mirror.py | 56 ------------------ tests/test_mirror.py | 64 --------------------- tox.toml | 55 ------------------ 6 files changed, 6 insertions(+), 310 deletions(-) delete mode 100644 tasks/mirror.py delete mode 100644 tests/test_mirror.py delete mode 100644 tox.toml diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 94b65ca..d6f26c4 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -17,32 +17,13 @@ jobs: strategy: fail-fast: false matrix: - env: + python: - "3.13" - "3.12" - "3.11" - "3.10" - "3.9" - - type - - dev steps: - - uses: actions/checkout@v4 + - uses: tox-dev/action-pre-commit-mirrorer/check@main with: - fetch-depth: 0 - - name: Install the latest version of uv - uses: astral-sh/setup-uv@v3 - with: - enable-cache: true - cache-dependency-glob: "pyproject.toml" - - name: Install tox - run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv - - name: Install Python - if: startsWith(matrix.env, '3.') && matrix.env != '3.13' - run: uv python install --python-preference only-managed ${{ matrix.env }} - - name: Setup test suite - run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.env }} - - name: Run test suite - run: tox run --skip-pkg-install -e ${{ matrix.env }} - env: - PYTEST_ADDOPTS: "-vv --durations=20" - DIFF_AGAINST: HEAD + python: "${{ matrix.python }}" diff --git a/.github/workflows/mirror.yaml b/.github/workflows/mirror.yaml index ceeeefa..758bb88 100644 --- a/.github/workflows/mirror.yaml +++ b/.github/workflows/mirror.yaml @@ -19,14 +19,7 @@ jobs: name: mirror runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: tox-dev/action-pre-commit-mirrorer/mirror@main with: - fetch-depth: 0 - token: ${{ secrets.PA_TOKEN }} - - name: Install the latest version of uv - uses: astral-sh/setup-uv@v3 - with: - enable-cache: true - cache-dependency-glob: "pyproject.toml" - - name: Run mirroring - run: uv run tasks/mirror.py '${{ github.ref == 'refs/heads/main' }}' + project: "pyproject-fmt" + token: "${{ secrets.PA_TOKEN }}" diff --git a/pyproject.toml b/pyproject.toml index 56135b3..cd64b8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,108 +36,5 @@ dependencies = [ [tool.hatch] build.targets.wheel.bypass-selection = true -[tool.ruff] -line-length = 120 -format.preview = true -format.docstring-code-line-length = 100 -format.docstring-code-format = true -lint.select = [ - "ALL", -] -lint.ignore = [ - "ANN101", # no type annotation for self - "ANN401", # allow Any as type annotation - "COM812", # Conflict with formatter - "CPY", # No copyright statements - "D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible - "D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible - "DOC", # not supported - "DOC501", # not working with Sphinx - "ISC001", # Conflict with formatter - "S104", # Possible binding to all interfaces -] -lint.per-file-ignores."tasks/**/*.py" = [ - "D", # don't care about documentation in tsask files - "INP001", # not a package - "S", # no security concerns in mirror - "T201", # prints are alloowed -] -lint.per-file-ignores."tests/**/*.py" = [ - "D", # don't care about documentation in tests - "FBT", # don't care about booleans as positional arguments in tests - "INP001", # no implicit namespace - "PLC2701", # private import - "PLR0913", # any number of arguments in tests - "PLR0917", # any number of arguments in tests - "PLR2004", # Magic value used in comparison, consider replacing with a constant variable - "S", # no security concerns in tests -] -lint.isort = { known-first-party = [ ], required-imports = [ - "from __future__ import annotations", -] } -lint.preview = true - -[tool.codespell] -builtin = "clear,usage,en-GB_to_en-US" -count = true - [tool.pyproject-fmt] max_supported_python = "3.13" - -[tool.pytest] -ini_options.testpaths = [ - "tests", -] -ini_options.verbosity_assertions = 2 - -[tool.coverage] -html.show_contexts = true -html.skip_covered = false -paths.source = [ - "src", - ".tox/*/.venv/lib/*/site-packages", - ".tox\\*\\.venv\\Lib\\site-packages", - ".tox/*/lib/*/site-packages", - ".tox\\*\\Lib\\site-packages", - "**/src", - "**\\src", -] -report.fail_under = 100 -run.parallel = true -run.plugins = [ - "covdefaults", -] -covdefaults.subtract_omit = "*/__main__.py" - -[tool.mypy] -show_error_codes = true -strict = true - -[dependency-groups] -dev = [ - { include-group = "tasks" }, - { include-group = "test" }, - { include-group = "type" }, -] -fix = [ - "pre-commit-uv>=4.1.3", -] -tasks = [ - "gitpython>=3.1.43", - "httpx>=0.27.2", - "packaging>=24.1", -] -test = [ - "covdefaults>=2.3", - "pygments>=2.18", - "pytest>=8.3.2", - "pytest-cov>=5", - { include-group = "fix" }, -] -type = [ - "mypy==1.11.2", - "types-cachetools>=5.5.0.20240820", - "types-chardet>=5.0.4.6", - { include-group = "test" }, - { include-group = "tasks" }, -] diff --git a/tasks/mirror.py b/tasks/mirror.py deleted file mode 100644 index 9268e98..0000000 --- a/tasks/mirror.py +++ /dev/null @@ -1,56 +0,0 @@ -# /// script -# requires-python = ">=3.12" -# dependencies = [ -# "gitpython>=3.1.43", -# "httpx>=0.27.2", -# "packaging>=24.1", -# ] -# /// -"""Mirror missing tags.""" - -from __future__ import annotations - -import os -import re -import sys -from pathlib import Path -from subprocess import check_call, check_output - -import httpx -from packaging.version import Version - -ROOT = Path(__file__).parents[1] - - -def run() -> None: - existing_tags = set(check_output(["git", "tag"], text=True).splitlines()) - response = httpx.get("https://pypi.org/pypi/pyproject-fmt/json") - response.raise_for_status() - released_tags = set(response.json()["releases"].keys()) - - missing_tags = sorted(Version(i) for i in released_tags - existing_tags) - - if missing_tags and os.environ.get("GITHUB_ACTIONS"): - check_call(["git", "config", "--global", "user.email", "gaborjbernat@gmail.com"]) - check_call(["git", "config", "--global", "user.name", "Bernat Gabor"]) - toml = ROOT / "pyproject.toml" - - for tag in missing_tags: - print(f"\n\nMirror {tag}") - text = toml.read_text(encoding="utf-8") - text = re.sub(r'version = ".*?"', f'version = "{tag}"', text) - text = re.sub(r'"pyproject-fmt==.*"', f'"pyproject-fmt=={tag}"', text) - toml.write_text(text, encoding="utf-8") - check_call(["git", "add", "pyproject.toml"]) - check_call(["git", "diff", "HEAD", "-u"]) - check_call(["git", "commit", "-m", f"Mirror {tag}"]) - check_call(["git", "tag", str(tag)]) - - if missing_tags and sys.argv[1] == "true": - print("\n\nPush") - check_call(["git", "push", "--tags", "-f"]) - check_call(["git", "push"]) - - -if __name__ == "__main__": - run() diff --git a/tests/test_mirror.py b/tests/test_mirror.py deleted file mode 100644 index c094c80..0000000 --- a/tests/test_mirror.py +++ /dev/null @@ -1,64 +0,0 @@ -from __future__ import annotations - -import os -import sys -from pathlib import Path -from subprocess import call, check_call, check_output -from textwrap import dedent - -import pytest - - -@pytest.fixture(scope="session") -def root() -> Path: - return Path(__file__).parents[1] - - -def test_last_tag(tmp_path: Path, root: Path, monkeypatch: pytest.MonkeyPatch) -> None: - # test this project against its latest tag - ver = check_output(["git", "describe", "--tags", "--abbrev=0"], text=True).strip() - print(f"Using version {ver}") # noqa: T201 - - pre_commit_home = tmp_path / "h" - pre_commit_home.mkdir() - monkeypatch.setenv("PRE_COMMIT_HOME", str(pre_commit_home)) - - project = tmp_path / "p" - project.mkdir() - monkeypatch.chdir(project) - (project / ".pre-commit-config.yaml").write_text( - dedent(f""" - repos: - - repo: file://{root} - rev: "{ver}" - hooks: - - id: pyproject-fmt - language_version: {sys.executable} - """) - ) - toml = project / "pyproject.toml" - toml.write_text("[project]\nrequires-python='>=3.13'") - - if os.environ.get("GITHUB_ACTIONS"): # pragma: no branch - check_call(["git", "config", "--global", "init.defaultBranch", "main"]) # pragma: no cover - check_call(["git", "config", "--global", "user.email", "e@a.com"]) # pragma: no cover - check_call(["git", "config", "--global", "user.name", "A B"]) # pragma: no cover - - check_call(["git", "init"]) - check_call(["git", "add", "."]) - check_call(["git", "commit", "-m", "Initial commit"]) - check_call(["ls", "-alth"]) - - pre_commit = Path(sys.executable).parent / "pre-commit" - - check_call([pre_commit, "install-hooks"]) - assert list(pre_commit_home.iterdir()) - - code = call([pre_commit, "run", "--all-files"]) - assert code == 1 - - assert toml.read_text().splitlines() == [ - "[project]", - 'requires-python = ">=3.13"', - 'classifiers = [ "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.13" ]', - ] diff --git a/tox.toml b/tox.toml deleted file mode 100644 index 55c2fd0..0000000 --- a/tox.toml +++ /dev/null @@ -1,55 +0,0 @@ -requires = ["tox>=4.22"] -env_list = ["fix", "3.13", "3.12", "3.11", "3.10", "3.9", "type"] -skip_missing_interpreters = true - -[env_run_base] -description = "run the tests with pytest under {env_name}" -package = "wheel" -wheel_build_env = ".pkg" -dependency_groups = ["test"] -pass_env = ["PYTEST_*", "SSL_CERT_FILE", "GITHUB_ACTIONS"] -set_env.COVERAGE_FILE = { replace = "env", name = "COVERAGE_FILE", default = "{work_dir}{/}.coverage.{env_name}" } -set_env.COVERAGE_FILECOVERAGE_PROCESS_START = "{tox_root}{/}pyproject.toml" -commands = [ - [ - "pytest", - { replace = "posargs", extend = true, default = [ - "--durations", - "5", - "--junitxml", - "{work_dir}{/}junit.{env_name}.xml", - "--no-cov-on-fail", - "--cov", - "{tox_root}{/}tests", - "--cov-config", - "{tox_root}{/}pyproject.toml", - "--cov-context", - "test", - "--cov-report", - "term-missing:skip-covered", - "--cov-report", - "html:{env_tmp_dir}{/}htmlcov", - "--cov-report", - "xml:{work_dir}{/}coverage.{env_name}.xml", - "tests", - ] }, - ], -] - -[env.fix] -description = "format the code base to adhere to our styles, and complain about what we cannot do automatically" -skip_install = true -dependency_groups = ["fix"] -pass_env = [{ replace = "ref", of = ["env_run_base", "pass_env"], extend = true }, "PROGRAMDATA"] -commands = [["pre-commit", "run", "--all-files", "--show-diff-on-failure", { replace = "posargs", extend = true }]] - -[env.type] -description = "run type check on code base" -dependency_groups = ["type"] -commands = [["mypy", "tasks", "tests"]] - -[env.dev] -description = "dev environment with all deps at {envdir}" -package = "editable" -dependency_groups = ["dev"] -commands = [["uv", "pip", "tree"], ["python", "-c", 'print(r"{env_python}")']]