Skip to content

Commit

Permalink
Adapt black -> formattex
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinvis committed Jan 14, 2024
1 parent 3de533c commit 6dedb2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
25 changes: 13 additions & 12 deletions mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}"])


Expand Down
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
]

0 comments on commit 6dedb2c

Please sign in to comment.