Skip to content

Commit 2af0516

Browse files
sayikandrewtavis
andauthored
add pre-commit configuration file (#59)
* add pre-commit configuration file * Adding license check files and minor edits to the CI workflow * Revert most changes to ci * Add ruff workflow and update package CI + docs shields * Add SPDX license identifier - BSD-3-Clause * Add new dependencies setup, update dependencies, new env directions * Format all files with Ruff * Fix all Ruff check --fix errors --------- Co-authored-by: Andrew Tavis McAllister <andrew.t.mcallister@gmail.com>
1 parent ca984e3 commit 2af0516

27 files changed

+1689
-175
lines changed

.github/workflows/pr_ci.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: pr_ci
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
paths:
12+
- "src/**"
13+
- "tests/**"
14+
push:
15+
branches:
16+
- main
17+
paths:
18+
- "src/**"
19+
- "tests/**"
20+
21+
jobs:
22+
ci:
23+
name: Run PR Check
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout Project
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Python Environment
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.11"
33+
34+
- name: Create Environment and Install Dependencies
35+
run: |
36+
python -m pip install --upgrade uv
37+
uv venv
38+
. .venv/bin/activate
39+
echo PATH=$PATH >> $GITHUB_ENV
40+
uv pip install -r requirements-dev.txt
41+
42+
- name: Run Ruff Format - Formatting Check
43+
run: ruff format ./src --check
44+
45+
- name: Run Ruff - Linting and Import Sorting Check
46+
if: always()
47+
run: ruff check ./src
48+
49+
- name: Run mypy - Static Type Checking
50+
if: always()
51+
run: mypy ./src --config-file ./pyproject.toml
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: pr_ci_license_header_check
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
types: [opened, reopened, synchronize]
7+
8+
jobs:
9+
license_header_check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repo Content
13+
uses: actions/checkout@v4
14+
15+
- name: Check License Header
16+
uses: apache/skywalking-eyes/header@main
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,63 @@
1-
name: CI
2-
1+
name: python_package_ci
32
on:
3+
workflow_dispatch:
44
pull_request:
5-
branches: [main]
6-
# schedule:
7-
# - cron: '0 0 * * 0' # weekly
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
paths:
12+
- "src/**"
13+
- "tests/**"
14+
push:
15+
branches:
16+
- main
17+
paths:
18+
- "src/**"
19+
- "tests/**"
820

921
jobs:
1022
run:
1123
runs-on: ${{ matrix.os }}
1224
strategy:
1325
matrix:
1426
os: [macos-latest]
15-
python-version: [3.8]
27+
python-version: [3.11]
28+
1629
env:
1730
OS: ${{ matrix.os }}
1831
PYTHON: ${{ matrix.python-version }}
1932

2033
steps:
21-
- name: Clone repository
34+
- name: Clone Repository
2235
uses: actions/checkout@v2
36+
2337
- name: Setup Python
2438
uses: actions/setup-python@main
2539
with:
2640
python-version: ${{ matrix.python-version }}
27-
- name: Add conda to system path
28-
uses: conda-incubator/setup-miniconda@v2
41+
42+
- name: Add Conda to System Path
43+
uses: conda-incubator/setup-miniconda@v3
2944
with:
3045
auto-update-conda: true
3146
python-version: ${{ matrix.python-version }}
32-
- name: Install dependencies
47+
48+
- name: Install Dependencies
3349
run: |
3450
eval "$(conda shell.bash hook)"
3551
conda env create --file environment.yml
36-
# - name: Build
37-
# eval "$(conda shell.bash hook)"
38-
# pip install -e .
39-
- name: Test and generate coverage
52+
53+
- name: Test and Generate Coverage
4054
run: |
4155
eval "$(conda shell.bash hook)"
4256
conda activate kwx-dev
4357
export PYTHONPATH="./src"
4458
pytest --cov=src tests --cov-report=xml
45-
- name: Upload coverage to Codecov
59+
60+
- name: Upload Coverage to Codecov
4661
uses: codecov/codecov-action@v2
4762
with:
4863
fail_ci_if_error: true

.licenserc.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
header:
2+
license:
3+
content: "SPDX-License-Identifier: BSD-3-Clause"
4+
paths:
5+
- '**/*.py'
6+
- '**/*.ts'
7+
paths-ignore:
8+
- 'build'
9+
- 'dist'
10+
- 'venv'
11+
- '**/*.md'
12+
- '**/__pycache__/**'
13+
- '**/.git/**'
14+
- '**/*__init__.py'
15+
comment: on-failure
16+
license-location-threshold: 10

.pre-commit-config.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
9+
- repo: https://github.com/astral-sh/ruff-pre-commit
10+
rev: v0.14.1
11+
hooks:
12+
- id: ruff-check
13+
name: run ruff linting check
14+
args: [--fix, --exit-non-zero-on-fix]
15+
16+
- id: ruff-format
17+
name: run ruff formatting check
18+
19+
- repo: https://github.com/tcort/markdown-link-check
20+
rev: v3.13.6
21+
hooks:
22+
- id: markdown-link-check
23+
name: run markdown link check
24+
args: [-q]
25+
26+
- repo: https://github.com/sphinx-contrib/sphinx-lint
27+
rev: v1.0.0
28+
hooks:
29+
- id: sphinx-lint
30+
name: run sphinx linting
31+
32+
- repo: https://github.com/numpy/numpydoc
33+
rev: v1.9.0
34+
hooks:
35+
- id: numpydoc-validation
36+
files: ^src/
37+
exclude: ^(tests/|.*__init__\.py$)
38+
39+
- repo: https://github.com/to-sta/spdx-checker-pre-commit
40+
rev: 0.1.7
41+
hooks:
42+
- id: spdx-license-checker
43+
name: run spdx-checker license check
44+
exclude: ^(?:.*/)?__init__\.py$
45+
args: [-l, BSD-3-Clause, --fix, --continue-on-error]
46+
types_or: [python, ts]
47+
48+
- repo: local
49+
hooks:
50+
- id: mypy-check
51+
name: run mypy static type checking
52+
files: ^src/
53+
entry: mypy ./src --config-file ./pyproject.toml
54+
language: python
55+
types: [python]
56+
pass_filenames: false

0 commit comments

Comments
 (0)