Skip to content

Commit

Permalink
Use nox for scraping book types instead of an overcomplicated command
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed Aug 31, 2024
1 parent d8f0641 commit 8732b91
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ jobs:
- uses: object-Object/ci/setup@v0
with:
python-version: 3.11
python-packages: .[runtime] --find-links ./vendor
python-packages: nox

- name: Scrape book types
run: |
python scripts/github/scrape_book_types.py > book_types.py.new
mv book_types.py.new src/HexBug/utils/book_types.py
ruff format src/HexBug/utils/book_types.py
ruff check --select=I --fix src/HexBug/utils/book_types.py
run: nox --session scrape_book_types

- name: Fail if book types need to be updated
run: git diff --exit-code
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A Discord bot for the Hex Casting mod. `buildpatterns.py`, `revealparser.py`, an
## Scraping web book types
Run `python scripts/github/scrape_book_types.py | tee src/HexBug/utils/book_types.py && ruff format src/HexBug/utils/book_types.py && ruff check --select=I --fix src/HexBug/utils/book_types.py`.
Run `nox -s scrape_book_types`.
## Depending on HexBug
Expand Down
26 changes: 26 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import shutil
import sys
from pathlib import Path

import nox
from nox.command import CommandFailed

Expand Down Expand Up @@ -49,6 +53,28 @@ def health_check(session: nox.Session):
# fmt: on


@nox.session
def scrape_book_types(session: nox.Session):
session.install("-e", ".[runtime]", "--find-links=./vendor")

tmp_file = Path("out/book_types.py")
with tmp_file.open("w", encoding="utf-8") as f:
session.run(
"python",
"scripts/github/scrape_book_types.py",
stdout=f,
stderr=sys.stderr,
)

if not tmp_file.read_text("utf-8").strip():
session.error("No output printed by script.")

session.run("ruff", "format", tmp_file)
session.run("ruff", "check", "--select=I", "--fix", tmp_file)

shutil.move(tmp_file, "src/HexBug/utils/book_types.py")


# helper functions


Expand Down

0 comments on commit 8732b91

Please sign in to comment.