Skip to content

Commit

Permalink
display change on stub check failure
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-dupre committed Feb 3, 2025
1 parent 89dc9a1 commit bea01aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ jobs:
run: poetry run ./check-version.py

# ---
# --- Check that python stubs are up to date
# --- Check that python stub file is up to date
# ---

check-stubs:
check-stub:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -92,7 +92,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Check that Python stubs are up to date
- name: Check that Python stub file is up to date
run: cargo run --bin stub_gen -- check

# ---
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Python

- Add auto-generated Python stubs.
- Add auto-generated Python stub file.

## 1.0.0

Expand Down
14 changes: 12 additions & 2 deletions opening-hours-py/src/bin/stub_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,26 @@ fn main() -> pyo3_stub_gen::Result<()> {
std::process::Command::new("poetry")
.args(["run", "ruff", "format", STUB_SOURCE_PATH])
.output()
.expect("failed to format stubs with ruff");
.expect("failed to format stub with ruff");

let changed = load_file(STUB_SOURCE_PATH) != load_file(STUB_TARGET_PATH);

if changed {
if is_subcommand_check {
println!(
"--- SOURCE:\n{}",
String::from_utf8_lossy(&load_file(STUB_SOURCE_PATH))
);

println!(
"--- TARGET:\n{}",
String::from_utf8_lossy(&load_file(STUB_TARGET_PATH))
);

std::fs::remove_file(STUB_SOURCE_PATH).expect("could not remove stub file");
panic!("File changed!");
} else {
println!("Installing new stubs.");
println!("Installing new stub file to {STUB_TARGET_PATH}.");

std::fs::rename(STUB_SOURCE_PATH, STUB_TARGET_PATH)
.expect("could not move stub to project's root");
Expand Down

0 comments on commit bea01aa

Please sign in to comment.