From cae69c410038ddd25a76a314c5183b7626f3dc37 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 1/2] 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 | 11 +--- pyproject.toml | 103 ---------------------------------- tasks/mirror.py | 56 ------------------ tests/test_mirror.py | 64 --------------------- tox.toml | 55 ------------------ 6 files changed, 5 insertions(+), 309 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..d382a26 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 + project: "pyproject-fmt" 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' }}' 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}")']] From 5df199fa89136881c7ab7adbfe9c3180bca37752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Thu, 24 Oct 2024 10:56:12 -0700 Subject: [PATCH 2/2] Use pre-commit-mirror-maker instead rolling our own 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 | 29 ------------------------- .github/workflows/main.yml | 29 +++++++++++++++++++++++++ .github/workflows/mirror.yaml | 25 ---------------------- .pre-commit-config.yaml | 11 ---------- README.md | 19 ++++++++++++----- pyproject.toml | 40 ----------------------------------- setup.py | 10 +++++++++ 7 files changed, 53 insertions(+), 110 deletions(-) delete mode 100644 .github/workflows/check.yaml create mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/mirror.yaml delete mode 100644 pyproject.toml create mode 100644 setup.py diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml deleted file mode 100644 index d6f26c4..0000000 --- a/.github/workflows/check.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Test -on: - workflow_dispatch: - push: - branches: ["main"] - pull_request: - schedule: - - cron: "0 8 * * *" - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python: - - "3.13" - - "3.12" - - "3.11" - - "3.10" - - "3.9" - steps: - - uses: tox-dev/action-pre-commit-mirrorer/check@main - with: - python: "${{ matrix.python }}" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..f4595f7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: Mirror +on: + push: + branches: [main] + pull_request: + schedule: + - cron: "30 8 * * *" + +jobs: + build: + name: Mirror + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: git config --global user.name 'Github Actions' + - run: git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v3 + with: + version: "latest" + - run: >- + uvx --from pre-commit-mirror-maker pre-commit-mirror -p 3.13 . \ + --language=python --package-name=pyproject-fmt --files-regex '(^|/)pyproject\.toml$' + - run: | + git remote set-url origin https://x-access-token:$GH_TOKEN@github.com/$GITHUB_REPOSITORY + git push origin HEAD:refs/heads/main --tags + if: ${{ github.ref == 'refs/heads/main' }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/mirror.yaml b/.github/workflows/mirror.yaml deleted file mode 100644 index d382a26..0000000 --- a/.github/workflows/mirror.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Mirror -on: - workflow_dispatch: - push: - branches: ["main"] - pull_request: - schedule: - - cron: "0 8 * * *" - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - -jobs: - mirror: - permissions: - contents: write - environment: - name: mirror - runs-on: ubuntu-latest - steps: - - uses: tox-dev/action-pre-commit-mirrorer/mirror@main - with: - project: "pyproject-fmt" - token: ${{ secrets.PA_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d7c3f07..05b579b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,17 +14,6 @@ repos: hooks: - id: codespell additional_dependencies: ["tomli>=2.0.1"] - - repo: https://github.com/tox-dev/pyproject-fmt - rev: "2.4.3" - hooks: - - id: pyproject-fmt - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.7.0" - hooks: - - id: ruff-format - args: ["--config", "pyproject.toml"] - - id: ruff - args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix", "--config", "pyproject.toml"] - repo: https://github.com/rbubley/mirrors-prettier rev: "v3.3.3" hooks: diff --git a/README.md b/README.md index 687b54b..ff0eb10 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,17 @@ # pyproject-fmt mirror -[![Mirror](https://github.com/tox-dev/pyproject-fmt/actions/workflows/mirror.yaml/badge.svg)](https://github.com/tox-dev/pyproject-fmt/actions/workflows/mirror.yaml) -[![Test](https://github.com/tox-dev/pyproject-fmt/actions/workflows/check.yaml/badge.svg)](https://github.com/tox-dev/pyproject-fmt/actions/workflows/check.yaml) +[![Main](https://github.com/tox-dev/pyproject-fmt/actions/workflows/main.yaml/badge.svg)](https://github.com/tox-dev/pyproject-fmt/actions/workflows/main.yaml) -The source code for this project now lives inside -[toml-fmt](https://github.com/tox-dev/toml-fmt/tree/main/pyproject-fmt), this repository serves only as a mirror for -pre-commit. +Mirror of [`pyproject-fmt`](https://github.com/tox-dev/toml-fmt/tree/main/pyproject-fmt) for +[pre-commit](https://github.com/pre-commit/pre-commit). + +### Using `pyproject-fmt` with pre-commit + +Add it to your `.pre-commit-config.yaml`: + +```yaml +- repo: https://github.com/pre-commit/pyproject-fmt + rev: "" # Use the sha / tag you want to point at + hooks: + - id: pyproject-fmt +``` diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index cd64b8a..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,40 +0,0 @@ -[build-system] -build-backend = "hatchling.build" -requires = [ - "hatchling>=1.25", -] - -[project] -name = "pyproject-fmt-mirror" -version = "2.4.3" -description = "Format your pyproject.toml file" -readme = "README.md" -keywords = [ - "format", - "pyproject", -] -license.file = "LICENSE.txt" -authors = [ - { name = "Bernat Gabor", email = "gaborjbernat@gmail.com" }, -] -requires-python = ">=3.9" -classifiers = [ - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", -] -dependencies = [ - "pyproject-fmt==2.4.3", -] - -[tool.hatch] -build.targets.wheel.bypass-selection = true - -[tool.pyproject-fmt] -max_supported_python = "3.13" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..aec6e71 --- /dev/null +++ b/setup.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +from setuptools import setup + + +setup( + name="pre_commit_placeholder_package", + version="0.0.0", + install_requires=["pyproject-fmt==2.4.3"], +)