Skip to content

Commit

Permalink
🔧 avoid chicken-and-egg situation with generate async hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Ousret committed Nov 20, 2024
1 parent 250c159 commit bcd213e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- "ruff==0.7.4"
- "black==24.10.0"
- "docstrfmt==1.9.0"
- niquests
- "niquests>=3.10,<4"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand Down Expand Up @@ -41,7 +41,7 @@ repos:
hooks:
- id: ruff
args: [ --exit-non-zero-on-fix, --fix ]
files: ^(prawcore/.*)$
files: ^(prawcore/.*.py)$

- repo: https://github.com/psf/black
hooks:
Expand Down
16 changes: 13 additions & 3 deletions tools/generate_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@

def black_reformat(tmp_dir: str) -> list[str]:
"""Simply run black and retrieve which file were reformatted if any."""
process = Popen(f"black {tmp_dir}", shell=True, stdout=PIPE, stderr=PIPE)
process = Popen(
f"black prawcore/_async", shell=True, stdout=PIPE, stderr=PIPE, cwd=tmp_dir
)
stdout, stderr = process.communicate()

stdout, stderr = stdout.decode(), stderr.decode()
Expand All @@ -78,7 +80,13 @@ def black_reformat(tmp_dir: str) -> list[str]:


def docstrfmt_reformat(tmp_dir: str) -> list[str]:
process = Popen(f"docstrfmt {tmp_dir}", shell=True, stdout=PIPE, stderr=PIPE)
process = Popen(
f"docstrfmt prawcore/_async/*.py",
shell=True,
stdout=PIPE,
stderr=PIPE,
cwd=tmp_dir,
)
stdout, stderr = process.communicate()

stdout, stderr = stdout.decode(), stderr.decode()
Expand All @@ -97,7 +105,9 @@ def docstrfmt_reformat(tmp_dir: str) -> list[str]:

def ruff_reformat(tmp_dir: str) -> list[str]:
"""Run Ruff linter and extract unfixable errors if any."""
process = Popen(f"ruff format {tmp_dir}", shell=True, stdout=PIPE, stderr=PIPE)
process = Popen(
f"ruff check --fix", shell=True, stdout=PIPE, stderr=PIPE, cwd=tmp_dir
)
stdout, stderr = process.communicate()

stdout, stderr = stdout.decode(), stderr.decode()
Expand Down

0 comments on commit bcd213e

Please sign in to comment.