Skip to content

Commit 4c26afc

Browse files
committed
Add pre-commit configuration and github workflows
This commit introduces two new features to the repository: 1. It adds a configuration for the pre-commit [1] tool that includes a selection of basic linters as well as a configuration to run the unit tests. You can activate these local checks by installing the pre-commit tool (using `pip` or `pipx`) and then running `pre-commit install`; this will update your `.git/hooks/pre-commit` file to run the checks automatically as part of each commit. See README.md for additional information. 2. It adds GitHub workflows that run these tests as part of each push and pull request. This is particularly useful when collaborating with other developers, since it helps catch minor errors and ensure consistent code formatting before changes are committed to the repository. [1]: https://pre-commit.com/
1 parent a3a0c18 commit 4c26afc

File tree

10 files changed

+150
-9
lines changed

10 files changed

+150
-9
lines changed

.github/dependabot.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Set update schedule for GitHub Actions
2+
3+
version: 2
4+
updates:
5+
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
# Check for updates to GitHub Actions every week
10+
interval: "weekly"

.github/workflows/precommit.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Run linters
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: "3.13"
15+
- name: Set up uv
16+
uses: astral-sh/setup-uv@v5
17+
- name: Install dependencies
18+
run: |
19+
uv sync --all-groups
20+
- uses: pre-commit/[email protected]

.github/workflows/tests.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run unit tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
unit-tests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: "3.13"
15+
- name: Set up uv
16+
uses: astral-sh/setup-uv@v5
17+
18+
- name: Install dependencies
19+
run: |
20+
uv sync --all-groups
21+
22+
- name: Run tests
23+
run: |
24+
uv run pytest -v

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
check
1+
check

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
repos:
2+
- repo: https://github.com/Lucas-C/pre-commit-hooks
3+
rev: v1.5.5
4+
hooks:
5+
- id: remove-tabs
6+
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v6.0.0
9+
hooks:
10+
- id: trailing-whitespace
11+
- id: check-merge-conflict
12+
- id: end-of-file-fixer
13+
- id: check-added-large-files
14+
- id: check-case-conflict
15+
- id: check-json
16+
- id: check-symlinks
17+
- id: detect-private-key
18+
19+
- repo: https://github.com/adrienverge/yamllint.git
20+
rev: v1.37.1
21+
hooks:
22+
- id: yamllint
23+
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
rev: v0.14.2
26+
hooks:
27+
- id: ruff-check
28+
- id: ruff-format
29+
30+
- repo: local
31+
hooks:
32+
- id: unit-tests
33+
name: Run unit tests
34+
entry: uv run pytest
35+
language: python
36+
types:
37+
- python
38+
pass_filenames: false

README.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
11
# python-batchtools
22

3-
## Setting up your development environment
3+
## Set up your development environment
44

5-
Install [uv](https://github.com/astral-sh/uv), then run:
5+
### Tooling
6+
7+
1. Start by installing `uv`. Depending on your distribution, this may be as simple as:
8+
9+
```sh
10+
sudo dnf -y install uv
11+
```
12+
13+
If you would like to run the latest version, your best bet is probably to start by installing `pipx`:
14+
15+
```
16+
sudo dnf -y install pipx
17+
```
18+
19+
And then using `pipx` to install `uv`:
20+
21+
```
22+
pipx install uv
23+
```
24+
25+
2. Next, install `pre-commit`. As with the `uv`, you can install this using your system package manager:
26+
27+
```
28+
sudo dnf -y install pre-commit
29+
```
30+
31+
Or you can install it just for your user using `pipx`:
32+
33+
```
34+
pipx install pre-commit
35+
```
36+
37+
38+
### Activate pre-commit
39+
40+
Activate `pre-commit` for your working copy of this repository by running:
41+
42+
```
43+
pre-commit install
44+
```
45+
46+
This will configure `.git/hooks/pre-commit` to run the `pre-commit` tool every time you make a commit. Running these tests locally ensures that your code is clean and that tests are passing before you share your code with others.
47+
48+
49+
### Install dependencies
50+
51+
To install the project dependencies, run:
652
753
```
854
uv sync --all-extras
955
```
1056
11-
## Running tests
57+
### Run tests
1258
13-
To run the unit tests:
59+
To run just the unit tests:
1460
1561
```
1662
uv run pytest

batchtools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def run(self, args: list[str] | None = None):
5959

6060
def main() -> None:
6161
if not is_logged_in():
62-
sys.exit("You are not logged in to the oc cli. Retrieve the token using 'oc login --web' or retrieving the login token from the openshift UI.")
62+
sys.exit(
63+
"You are not logged in to the oc cli. Retrieve the token using 'oc login --web' or retrieving the login token from the openshift UI."
64+
)
6365

6466
app = BatchTools()
6567
app.run()

bt-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ python3 batchtools.py bl
3939
python3 batchtools.py bl csw-dev-0
4040
br nvidia-smi
4141

42-
# ADD CASES HERE FOR
42+
# ADD CASES HERE FOR
4343
br sleep 20 &
4444
# Needs bash to get jobs
4545
# python3 batchtools.py bl csw-dev-0 csw-dev-1
@@ -73,4 +73,4 @@ python3 batchtools.py bp
7373
# BR
7474
# ----------------------------------------------------------------------------------------
7575
python3 batchtools.py br nvidia-smi
76-
python3 batchtools.py br --wait 0 nvidia-smi
76+
python3 batchtools.py br --wait 0 nvidia-smi

helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def is_logged_in() -> bool:
88
except oc.OpenShiftPythonException:
99
return False
1010

11+
1112
def pretty_print(pod: oc.APIObject) -> str:
1213
formatted_logs: str = ""
1314
try:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ analyzeUnannotatedFunctions = false
2424

2525

2626
[tool.pytest.ini_options]
27-
addopts = "--cov=. --cov-report=html -v"
27+
addopts = "--cov=. --cov-report=html"
2828

2929
[tool.coverage.report]
3030
omit = ["tests/*"]

0 commit comments

Comments
 (0)