Skip to content

Commit 213b3aa

Browse files
authored
cicd: add basic precommit hooks (#454)
* Add precommit + some minimally controversial hooks. Add a note in README. * Run hooks over existing codebase. There's a few instances of trailing whitespace and incorrect line endings. * Run checks in CI
1 parent 4e65955 commit 213b3aa

File tree

13 files changed

+58
-35
lines changed

13 files changed

+58
-35
lines changed

.github/workflows/python-cqa.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- uses: actions/cache@v4
2525
with:
2626
path: ~/.cache/pip
27-
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
27+
key: ${{ runner.os }}-pip-test-${{ hashFiles('pyproject.toml') }}
2828
restore-keys: |
2929
${{ runner.os }}-pip-
3030
- name: Set up Python ${{ matrix.python-version }}
@@ -40,3 +40,10 @@ jobs:
4040
- name: Test with pytest
4141
run: |
4242
python -m pytest
43+
44+
precommit_hooks:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: actions/setup-python@v5
49+
- uses: pre-commit/[email protected]

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ lint
2323
uta_*.pgd.gz
2424
.vscode
2525
*.log
26-
.idea
26+
.idea

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: detect-private-key
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-merge-conflict
10+
- id: detect-aws-credentials
11+
args: [ --allow-missing-credentials ]
12+
- id: mixed-line-ending
13+
args: [ --fix=lf ]
14+
minimum_pre_commit_version: 4.0.1

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ venv/%:
4747
#=> develop: install package in develop mode
4848
.PHONY: develop setup
4949
develop setup:
50-
pip install -e .[dev,extras,notebooks]
50+
pip install -e .[dev,extras,notebooks]; \
51+
pre-commit install
5152

5253
#=> devready: create venv, install prerequisites, install pkg in develop mode
5354
.PHONY: devready

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ This section is intended for developers who contribute to VRS-Python.
192192

193193
### Installing for development
194194

195-
Fork the repo at <https://github.com/ga4gh/vrs-python/>.
195+
Fork the repo at <https://github.com/ga4gh/vrs-python/> and initialize a development environment.
196196

197197
```shell
198198
git clone --recurse-submodules [email protected]:YOUR_GITHUB_ID/vrs-python.git
@@ -201,6 +201,13 @@ make devready
201201
source venv/3.12/bin/activate
202202
```
203203

204+
This setup includes [pre-commit hooks](https://pre-commit.com/). If you create a virtual environment manually, be sure to install the hooks yourself; otherwise, commits may fail during [CI/CD checks](https://github.com/ga4gh/vrs-python/actions/workflows/python-cqa.yml):
205+
206+
```shell
207+
source venv/3.12/bin/activate
208+
pre-commit install
209+
```
210+
204211
If you already cloned the repo, but forgot to include `--recurse-submodules` you can run:
205212

206213
```shell

docs/setup_help/m1_mac_setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig:/opt/homebre
4646
14. Run the make devready command:
4747
1. `make devready`
4848
15. Run the make test command:
49-
1. `make test`
49+
1. `make test`

docs/setup_help/uta_installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
4. Create roles for the application, give login and CREATEDB permissions:
99
1. `CREATE ROLE uta_admin WITH LOGIN CREATEDB;`
1010
2. `CREATE ROLE anonymous WITH LOGIN CREATEDB;`
11-
5. List the users using the command
11+
5. List the users using the command
1212
1. `\du`
1313
6. Create the UTA Database object
1414
1. `CREATE DATABASE uta;`
1515
7. Grant privileges to manage the database to uta_admin
1616
1. `GRANT ALL PRIVILEGES ON DATABASE uta TO uta_admin;`
1717
8. Exit postgres
1818
1. `\q`
19-
9. Download the UTA database and place it in the uta database object that you created before (**This step takes around 5 hours**).
19+
9. Download the UTA database and place it in the uta database object that you created before (**This step takes around 5 hours**).
2020
1. `export UTA_VERSION=uta_20210129.pgd.gz\ncurl -O http://dl.biocommons.org/uta/$UTA_VERSION\ngzip -cdq ${UTA_VERSION} | psql -h localhost -U uta_admin --echo-errors --single-transaction -v ON_ERROR_STOP=1 -d uta -p 5432`
2121
10. Set your UTA path
2222
1. `export UTA_DB_URL=postgresql://uta_admin@localhost:5432/uta/uta_20210129`
@@ -30,4 +30,4 @@ gzip -cdq ${UTA_VERSION} | grep -v "^REFRESH MATERIALIZED VIEW" | psql -h localh
3030
1. `REFRESH MATERIALIZED VIEW uta_20210129.exon_set_exons_fp_mv;`
3131
2. `REFRESH MATERIALIZED VIEW uta_20210129.tx_exon_set_summary_mv;`
3232
3. `REFRESH MATERIALIZED VIEW uta_20210129.tx_def_summary_mv;`
33-
4. `REFRESH MATERIALIZED VIEW uta_20210129.tx_similarity_mv;` #**This step will take 5 or more hours**
33+
4. `REFRESH MATERIALIZED VIEW uta_20210129.tx_similarity_mv;` #**This step will take 5 or more hours**

notebooks/getting_started/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,3 @@ we show how to transform basic variants to VRS, and in some cases, back to the o
4242
The final notebook of this series,
4343
[Exploring the CNV Translator](5_Exploring_the_CnvTranslator.ipynb) details transformations
4444
of various forms of copy number variation to their VRS representations.
45-
46-
47-
48-
49-

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dev = [
5858
"vcrpy",
5959
"pyyaml",
6060
# style
61+
"pre-commit>=4.0.1",
6162
"pylint",
6263
"yapf",
6364
# docs

src/ga4gh/vrs/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ class ga4gh(_ValueObject.ga4gh):
703703
'component',
704704
'orientation',
705705
'type'
706-
]
706+
]
707707

708708
class DerivativeMolecule(_VariationBase):
709709
"""The "Derivative Molecule" data class is a structure for describing a derivate
@@ -716,7 +716,7 @@ class DerivativeMolecule(_VariationBase):
716716
description="The traversal block components that make up the derivative molecule.",
717717
min_length=2
718718
)
719-
circular: Optional[bool] = Field(None, description="A flag indicating if the derivative molecule is circular (true) or linear (false).")
719+
circular: Optional[bool] = Field(None, description="A flag indicating if the derivative molecule is circular (true) or linear (false).")
720720

721721
class ga4gh(_Ga4ghIdentifiableObject.ga4gh):
722722
prefix = "DM"

0 commit comments

Comments
 (0)