diff --git a/README.md b/README.md index 2fd1da9..020c2b6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,21 @@ -# black-pre-commit-mirror +# formattex-pre-commit-mirror -mypyc wheels go brr +A [pre-commit](https://pre-commit.com/) hook for +[formattex](https://pypi.org/project/formattex/) and +[formatbibtex](https://pypi.org/project/formatbibtex/). -For example `pre-commit` configs, please see the [black VCS integration docs][1] -[1]: https://black.readthedocs.io/en/stable/integrations/source_version_control.html +## Usage + +Add the following to your `.pre-commit-config.yaml`: + +```yaml +- repo: https://github.com/fluiddyn/formattex-pre-commit + # Formattex version. + rev: 0.1.4 + hooks: + # Run the formatter for tex files. + - id: formattex + # Run the formatter for bibtex files. + - id: formatbibtex +``` diff --git a/mirror.py b/mirror.py index 33dcc4d..940bed9 100644 --- a/mirror.py +++ b/mirror.py @@ -12,18 +12,19 @@ def main(): with open(Path(__file__).parent / "pyproject.toml", "rb") as f: pyproject = tomli.load(f) - # get current version of black + # get current version of formattex deps = pyproject["project"]["dependencies"] + # TODO: work on update for formatbibtex assert len(deps) == 1 - black_dep = Requirement(deps[0]) - assert black_dep.name == "black" - black_specs = list(black_dep.specifier) - assert len(black_specs) == 1 - assert black_specs[0].operator == "==" - current_version = Version(black_specs[0].version) - - # get all versions of black from PyPI - resp = urllib3.request("GET", "https://pypi.org/pypi/black/json") + formattex_dep = Requirement(deps[0]) + assert formattex_dep.name == "formattex" + formattex_specs = list(formattex_dep.specifier) + assert len(formattex_specs) == 1 + assert formattex_specs[0].operator == "==" + current_version = Version(formattex_specs[0].version) + + # get all versions of formattex from PyPI + resp = urllib3.request("GET", "https://pypi.org/pypi/formattex/json") if resp.status != 200: raise RuntimeError @@ -32,11 +33,11 @@ def main(): versions.sort() for version in versions: - pyproject["project"]["dependencies"] = [f"black=={version}"] + pyproject["project"]["dependencies"] = [f"formattex=={version}"] with open(Path(__file__).parent / "pyproject.toml", "wb") as f: tomli_w.dump(pyproject, f) subprocess.run(["git", "add", "pyproject.toml"]) - subprocess.run(["git", "commit", "-m", f"black {version}"]) + subprocess.run(["git", "commit", "-m", f"formattex {version}"]) subprocess.run(["git", "tag", f"{version}"]) diff --git a/pyproject.toml b/pyproject.toml index aebd4be..3b3dec5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,15 @@ [project] -name = "black-pre-commit-mirror" +name = "formattex-pre-commit" version = "0.1.0" dependencies = [ - "black==23.12.1", + "formattex==0.1.4", + "formatbibtex==0.0.2", ] [project.optional-dependencies] -jupyter = [ - "black[jupyter]", +dev = [ + "tomli", + "tomli_w", + "urllib3", + "packaging" ]