├── .github └── workflows │ └── mirror.yml ├── .pre-commit-hooks.yaml ├── README.md ├── mirror.py └── pyproject.toml /.github/workflows/mirror.yml: -------------------------------------------------------------------------------- 1 | name: main 2 | on: 3 | push: 4 | branches: [main] 5 | workflow_dispatch: 6 | schedule: 7 | - cron: '43 5 * * *' 8 | 9 | jobs: 10 | build: 11 | name: main 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions/setup-python@v4 16 | - run: python -m pip install "urllib3>=2" tomli-w tomli packaging 17 | - run: git config --global user.name 'Github Actions' 18 | - run: git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' 19 | - run: python mirror.py 20 | - run: | 21 | git remote set-url origin https://x-access-token:$GH_TOKEN@github.com/$GITHUB_REPOSITORY 22 | git push origin HEAD:refs/heads/main --tags 23 | env: 24 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 25 | -------------------------------------------------------------------------------- /.pre-commit-hooks.yaml: -------------------------------------------------------------------------------- 1 | - id: black 2 | name: black 3 | description: "Black: The uncompromising Python code formatter" 4 | entry: black 5 | language: python 6 | minimum_pre_commit_version: 2.9.2 7 | require_serial: true 8 | types_or: [python, pyi] 9 | - id: black-jupyter 10 | name: black-jupyter 11 | description: 12 | "Black: The uncompromising Python code formatter (with Jupyter Notebook support)" 13 | entry: black 14 | language: python 15 | minimum_pre_commit_version: 2.9.2 16 | require_serial: true 17 | types_or: [python, pyi, jupyter] 18 | additional_dependencies: [".[jupyter]"] 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # black-pre-commit-mirror 2 | 3 | mypyc wheels go brr 4 | 5 | For example `pre-commit` configs, please see the [black VCS integration docs][1] 6 | 7 | [1]: https://black.readthedocs.io/en/stable/integrations/source_version_control.html 8 | -------------------------------------------------------------------------------- /mirror.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | from pathlib import Path 3 | 4 | import tomli 5 | import tomli_w 6 | import urllib3 7 | from packaging.requirements import Requirement 8 | from packaging.version import Version 9 | 10 | 11 | def main(): 12 | with open(Path(__file__).parent / "pyproject.toml", "rb") as f: 13 | pyproject = tomli.load(f) 14 | 15 | # get current version of black 16 | deps = pyproject["project"]["dependencies"] 17 | assert len(deps) == 1 18 | black_dep = Requirement(deps[0]) 19 | assert black_dep.name == "black" 20 | black_specs = list(black_dep.specifier) 21 | assert len(black_specs) == 1 22 | assert black_specs[0].operator == "==" 23 | current_version = Version(black_specs[0].version) 24 | 25 | # get all versions of black from PyPI 26 | resp = urllib3.request("GET", "https://pypi.org/pypi/black/json") 27 | if resp.status != 200: 28 | raise RuntimeError 29 | 30 | versions = [Version(release) for release in resp.json()["releases"]] 31 | versions = [v for v in versions if v > current_version and not v.is_prerelease] 32 | versions.sort() 33 | 34 | for version in versions: 35 | pyproject["project"]["dependencies"] = [f"black=={version}"] 36 | with open(Path(__file__).parent / "pyproject.toml", "wb") as f: 37 | tomli_w.dump(pyproject, f) 38 | subprocess.run(["git", "add", "pyproject.toml"]) 39 | subprocess.run(["git", "commit", "-m", f"black {version}"]) 40 | subprocess.run(["git", "tag", f"{version}"]) 41 | 42 | 43 | if __name__ == "__main__": 44 | main() 45 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "black-pre-commit-mirror" 3 | version = "0.1.0" 4 | dependencies = [ 5 | "black==25.1.0", 6 | ] 7 | 8 | [project.optional-dependencies] 9 | jupyter = [ 10 | "black[jupyter]", 11 | ] 12 | --------------------------------------------------------------------------------