Skip to content

Commit ebe3370

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 ef30452 commit ebe3370

File tree

10 files changed

+719
-9
lines changed

10 files changed

+719
-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 pre-commit checks
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.10"
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]

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ check
22
__pycache__
33
.pytest_cache
44
.coverage
5-
htmlcov
5+
htmlcov

.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

.yamllint.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends: default
2+
rules:
3+
line-length: disable
4+
document-start: disable
5+
indentation:
6+
indent-sequences: whatever
7+
hyphens:
8+
max-spaces-after: 4
9+
truthy:
10+
check-keys: false

README.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,66 @@
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+
### Install tools
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, you can install the command using `pipx`. First, install `pipx`:
14+
15+
```
16+
sudo dnf -y install pipx
17+
```
18+
19+
And then use `pipx` to install `uv`:
20+
21+
```
22+
pipx install uv
23+
```
24+
25+
2. Next, install `pre-commit`. As with `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 a possibly more recent version 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. To manually run all the checks:
47+
48+
```
49+
pre-commit run --all-files
50+
```
51+
52+
53+
### Install dependencies
54+
55+
To install the project dependencies, run:
656
757
```
858
uv sync --all-extras
959
```
1060
11-
## Running tests
61+
### Run tests
1262
13-
To run the unit tests:
63+
To run just the unit tests:
1464
1565
```
1666
uv run pytest

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "python-batchtools"
33
version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"
6-
requires-python = ">=3.13"
6+
requires-python = ">=3.10"
77
dependencies = ["kubernetes-typed>=18.20.2", "openshift-client>=2.0.5"]
88

99
[dependency-groups]
@@ -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)