Skip to content

Commit 4d5fafa

Browse files
authored
Add ruff github action (#3)
1 parent 0da1b36 commit 4d5fafa

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

.github/workflows/ruff.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Ruff
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
lint_and_format:
11+
name: Build and Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: astral-sh/ruff-action@v3
16+
- run: ruff check
17+
- run: ruff format --check --diff

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# nhls_py
22

3+
![Rust workflow](https://github.com/TEALab-org/nhls_py/actions/workflows/ruff.yml/badge.svg?branch=main)
4+
35
A python module for utilizing [`nhls`](https://github.com/TEALab-org/nhls).
46
`nhls_py` is not bindings to a rust library.
57
Instead it generates rust code

nhls_py/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from .session_init import session_init as session_init
22

3-
# Module level variable to store the location
3+
# Module level variable to store the location
44
# nhls checkout / build artifacts
55
nhls_path = "~/.cache/nhls"
6-

nhls_py/session_init.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
from importlib.resources import files
33
from pathlib import Path
44
import subprocess
5-
from . import nhls_path
5+
from . import nhls_path
66

7+
8+
# Test if we can run rustup commands
79
def check_rustup_present():
810
try:
9-
subprocess.run(
10-
["rustup"],
11-
stdout=subprocess.DEVNULL,
12-
stderr=subprocess.DEVNULL
13-
)
11+
subprocess.run(["rustup"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
1412
return True
1513
except FileNotFoundError:
16-
return False
14+
return False
1715

18-
def session_init(nhls_path_override = None):
16+
17+
def session_init(nhls_path_override=None):
1918
# Load NHLS version information
2019
nhls_version_path = files("nhls_py") / "nhls_version.json"
2120
print(f"nhls_version_path: {nhls_version_path}")
@@ -27,8 +26,8 @@ def session_init(nhls_path_override = None):
2726
nhls_url = nhls_version["url"]
2827
print(f"nhls branch: {nhls_branch}, url: {nhls_url}")
2928

30-
# Figure out where checkout should be
31-
global nhls_path
29+
# Figure out where checkout should be
30+
global nhls_path
3231
if nhls_path_override is None:
3332
nhls_path = Path(nhls_path).expanduser()
3433
else:
@@ -52,11 +51,11 @@ def session_init(nhls_path_override = None):
5251
nhls_path,
5352
]
5453
subprocess.run(
55-
clone_args,
56-
cwd=nhls_path.parent,
57-
capture_output=False,
58-
text=True,
59-
check=True
54+
clone_args,
55+
cwd=nhls_path.parent,
56+
capture_output=False,
57+
text=True,
58+
check=True,
6059
)
6160

6261
# Check that rustup is present
@@ -66,7 +65,7 @@ def session_init(nhls_path_override = None):
6665
print("please install rustup!")
6766
print("https://rustup.rs")
6867
raise ValueError("Rustup not installed")
69-
68+
7069
# Ensure correct toolchain is present
7170
print("checking toolchain...")
7271
tool_args = [
@@ -75,11 +74,7 @@ def session_init(nhls_path_override = None):
7574
"install",
7675
]
7776
subprocess.run(
78-
tool_args,
79-
cwd=nhls_path,
80-
capture_output=False,
81-
text=True,
82-
check=True
77+
tool_args, cwd=nhls_path, capture_output=False, text=True, check=True
8378
)
8479

8580
# Run cargo build now
@@ -89,13 +84,9 @@ def session_init(nhls_path_override = None):
8984
"cargo",
9085
"build",
9186
"--release",
92-
]
87+
]
9388
subprocess.run(
94-
build_args,
95-
cwd=nhls_path,
96-
capture_output=False,
97-
text=True,
98-
check=True
89+
build_args, cwd=nhls_path, capture_output=False, text=True, check=True
9990
)
10091

10192
# Done

notebooks/draft.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"import sys\n",
1515
"\n",
1616
"# Build an absolute path from this notebook's parent directory\n",
17-
"module_path = os.path.abspath(os.path.join('..', 'nhls_py'))\n",
17+
"module_path = os.path.abspath(os.path.join(\"..\", \"nhls_py\"))\n",
1818
"\n",
1919
"# Add to sys.path if not already present\n",
2020
"if module_path not in sys.path:\n",

0 commit comments

Comments
 (0)