Skip to content

Commit 31d1346

Browse files
authored
cicd: update linting, git hooks, etc (#447)
Implement a few template-related updates * Update GitHub Actions for a few utils * Test in 3.11-3.13 instead of 3.10-3.12 (to match `requires-python` in `pyproject.toml` -- if this was on purpose then the other needs to be fixed) * Update pre-commit hooks. Use `prek`, consolidate into one task in CI/CD, add some new hooks. * Update Ruff, add some new Ruff rules. * Fix versions being run in the install test action * Fix license metadata * Use `uv` for github actions
1 parent 396bb17 commit 31d1346

File tree

9 files changed

+134
-174
lines changed

9 files changed

+134
-174
lines changed

.github/workflows/checks.yaml

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,72 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
python-version: ["3.10", "3.11", "3.12"]
10+
python-version: ["3.11", "3.12", "3.13"]
1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: actions/checkout@v6
1313

14-
- name: Set up Python ${{ matrix.python-version }}
15-
uses: actions/setup-python@v5
14+
- name: Set up Python
15+
uses: actions/setup-python@v6
1616
with:
1717
python-version: ${{ matrix.python-version }}
1818

19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v7
21+
with:
22+
enable-cache: true
23+
1924
- name: Install dependencies
20-
run: |
21-
python3 -m pip install pipenv
22-
pipenv install --dev
25+
run: uv sync
2326
lint:
2427
runs-on: ubuntu-latest
2528
steps:
26-
- uses: actions/checkout@v4
29+
- uses: actions/checkout@v6
2730

2831
- name: Set up Python
29-
uses: actions/setup-python@v5
32+
uses: actions/setup-python@v6
3033
with:
31-
python-version: 3.11
34+
python-version: 3.13
35+
36+
- name: Install uv
37+
uses: astral-sh/setup-uv@v7
38+
with:
39+
enable-cache: true
3240

3341
- name: Install dependencies
34-
run: python3 -m pip install ".[dev]"
42+
run: uv sync --extra dev
3543

3644
- name: Check style
37-
run: python3 -m ruff check . && python3 -m ruff format --check .
45+
run: uv run ruff check && uv run ruff format --check
46+
47+
precommit_hooks:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v6
51+
52+
- uses: j178/prek-action@v1
53+
with:
54+
extra_args: '--all-files --skip "ruff-format" --skip "ruff-check"'
3855

3956
docs:
4057
runs-on: ubuntu-latest
4158
env:
4259
SPHINX_GITHUB_CHANGELOG_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4360
steps:
44-
- uses: actions/checkout@v4
61+
- uses: actions/checkout@v6
4562

4663
- name: Set up Python
47-
uses: actions/setup-python@v5
64+
uses: actions/setup-python@v6
4865
with:
49-
python-version: 3.11
66+
python-version: 3.12 # broken on 3.13
67+
68+
- name: Install uv
69+
uses: astral-sh/setup-uv@v7
70+
with:
71+
enable-cache: true
5072

5173
- name: Install dependencies
52-
run: |
53-
python3 -m pip install --upgrade pip
54-
python3 -m pip install '.[docs]'
74+
run: uv sync --extra docs
5575

5676
- name: Attempt docs build
5777
working-directory: ./docs
58-
run: make html
59-
60-
precommit_hooks:
61-
runs-on: ubuntu-latest
62-
strategy:
63-
matrix:
64-
cmd:
65-
- "end-of-file-fixer"
66-
- "trailing-whitespace"
67-
- "mixed-line-ending"
68-
steps:
69-
- uses: actions/checkout@v4
70-
71-
- name: Set up Python 3.12
72-
uses: actions/setup-python@v5
73-
with:
74-
python-version: 3.12
75-
76-
- uses: pre-commit/[email protected]
77-
with:
78-
extra_args: ${{ matrix.cmd }} --all-files
78+
run: source ../.venv/bin/activate && make html

.pre-commit-config.yaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v5.0.0 # pre-commit-hooks version
3+
rev: v6.0.0 # pre-commit-hooks version
44
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
105
- id: detect-aws-credentials
116
args: [ --allow-missing-credentials ]
7+
- repo: builtin
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: check-added-large-files
11+
args: ['--maxkb=1500']
12+
- id: check-case-conflict
13+
- id: end-of-file-fixer
14+
- id: fix-byte-order-marker
15+
- id: check-json
16+
- id: check-toml
17+
- id: check-yaml
1218
- id: mixed-line-ending
1319
args: [ --fix=lf ]
20+
- id: check-merge-conflict
21+
- id: detect-private-key
1422
- repo: https://github.com/astral-sh/ruff-pre-commit
15-
rev: v0.12.1
23+
rev: v0.14.10 # ruff version
1624
hooks:
1725
- id: ruff-format
18-
- id: ruff
26+
- id: ruff-check
1927
args: [ --fix, --exit-non-zero-on-fix ]
20-
minimum_pre_commit_version: 4.2.0
28+
minimum_prek_version: 0.2.23

pyproject.toml

Lines changed: 55 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ classifiers = [
1414
"Intended Audience :: Science/Research",
1515
"Intended Audience :: Developers",
1616
"Topic :: Scientific/Engineering :: Bio-Informatics",
17-
"License :: OSI Approved :: MIT License",
1817
"Programming Language :: Python :: 3",
1918
"Programming Language :: Python :: 3.11",
2019
"Programming Language :: Python :: 3.12",
2120
"Programming Language :: Python :: 3.13",
2221
]
2322
requires-python = ">=3.11"
2423
description = "Common Operation on Lots of Sequences Tool"
25-
license = {file = "LICENSE"}
24+
license = "MIT"
25+
license-files = ["LICENSE"]
2626
dependencies = [
2727
"asyncpg",
2828
"boto3",
@@ -38,11 +38,11 @@ dynamic = ["version"]
3838

3939
[project.optional-dependencies]
4040
dev = [
41-
"pre-commit>=4.2.0",
41+
"prek>=0.2.23",
4242
"ipython",
4343
"ipykernel",
4444
"psycopg2-binary",
45-
"ruff==0.12.1",
45+
"ruff==0.14.10",
4646
]
4747
tests = ["pytest", "pytest-cov", "pytest-asyncio", "mock"]
4848
docs = [
@@ -68,13 +68,6 @@ build-backend = "setuptools.build_meta"
6868

6969
[tool.setuptools_scm]
7070

71-
# Scanning for namespace packages in the ``src`` directory is true by
72-
# default in pyproject.toml, so you do NOT need to include the
73-
# `tool.setuptools.packages.find` if it looks like the following:
74-
# [tool.setuptools.packages.find]
75-
# namespaces = true
76-
# where = ["src"]
77-
7871
[tool.setuptools.package-data]
7972
"cool_seq_tool.resources" = ["transcript_mapping.tsv"]
8073

@@ -91,113 +84,78 @@ branch = true
9184
[tool.ruff]
9285
src = ["src"]
9386
exclude = ["docs/source/conf.py"]
94-
lint.select = [
95-
"F", # https://docs.astral.sh/ruff/rules/#pyflakes-f
96-
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
97-
"I", # https://docs.astral.sh/ruff/rules/#isort-i
98-
"N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n
99-
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
100-
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
101-
"ANN", # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
102-
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
103-
"S", # https://docs.astral.sh/ruff/rules/#flake8-bandit-s
104-
"B", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
105-
"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
106-
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
107-
"DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
108-
"T10", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
109-
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
110-
"LOG", # https://docs.astral.sh/ruff/rules/#flake8-logging-log
111-
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
112-
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
113-
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
114-
"T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20
115-
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
116-
"Q", # https://docs.astral.sh/ruff/rules/#flake8-quotes-q
117-
"RSE", # https://docs.astral.sh/ruff/rules/#flake8-raise-rse
118-
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
119-
"SLF", # https://docs.astral.sh/ruff/rules/#flake8-self-slf
120-
"SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
121-
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
122-
"ARG", # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
123-
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
124-
"PGH", # https://docs.astral.sh/ruff/rules/#pygrep-hooks-pgh
125-
"PLC", # https://docs.astral.sh/ruff/rules/#convention-c
126-
"PLE", # https://docs.astral.sh/ruff/rules/#error-e_1
127-
"TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try
128-
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
129-
"FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
130-
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
131-
]
132-
lint.fixable = [
133-
"I",
134-
"F401",
135-
"D",
136-
"UP",
137-
"ANN",
138-
"B",
139-
"C4",
140-
"LOG",
141-
"G",
142-
"PIE",
143-
"PT",
144-
"RSE",
145-
"SIM",
146-
"PLC",
147-
"PLE",
148-
"TRY",
149-
"PERF",
150-
"FURB",
151-
"RUF"
152-
]
15387

154-
# ANN003 - missing-type-kwargs
155-
# D203 - one-blank-line-before-class
156-
# D205 - blank-line-after-summary
157-
# D206 - indent-with-spaces*
158-
# D213 - multi-line-summary-second-line
159-
# D300 - triple-single-quotes*
160-
# D400 - ends-in-period
161-
# D415 - ends-in-punctuation
162-
# E111 - indentation-with-invalid-multiple*
163-
# E114 - indentation-with-invalid-multiple-comment*
164-
# E117 - over-indented*
165-
# E501 - line-too-long*
166-
# W191 - tab-indentation*
167-
# S321 - suspicious-ftp-lib-usage
168-
# PLC0206 - dict-index-missing-items
169-
# *ignored for compatibility with formatter
170-
lint.ignore = [
171-
"ANN003",
172-
"D203", "D205", "D206", "D213", "D300", "D400", "D415",
173-
"E111", "E114", "E117", "E501",
88+
[tool.ruff.lint]
89+
select = ["ALL"]
90+
ignore = [
91+
# unused
92+
"AIR",
93+
"ERA",
94+
"YTT",
95+
"BLE",
96+
"FBT",
97+
"CPY",
98+
"DJ",
99+
"EXE",
100+
"FIX",
101+
"FA",
102+
"PYI",
103+
"TD",
104+
"C90",
105+
"NPY",
106+
"PD",
107+
# ignore for compatibility with formatter
108+
"D206",
109+
"D300",
110+
"W191",
111+
"E111",
112+
"E114",
113+
"E117",
114+
"E501",
174115
"W191",
175116
"S321",
117+
"COM812",
118+
"COM819",
119+
"Q000",
120+
"Q001",
121+
"Q002",
122+
"Q003",
123+
# don't require types on *args, **kwargs
124+
"ANN002",
125+
"ANN003",
126+
# subjective pylint thresholds
127+
"PLR0904",
128+
"PLR091",
129+
"PLR1702",
176130
"PLC0206",
131+
# misc unnecessary stuff
132+
"S321",
133+
"D203",
134+
"D205",
135+
"D213",
136+
"D400",
137+
"D415",
177138
]
178139

179140
[tool.ruff.lint.per-file-ignores]
180141
# ANN001 - missing-type-function-argument
181142
# ANN2 - missing-return-type
182-
# D100 - undocumented-public-module
183-
# D102 - undocumented-public-class
184-
# D103 - undocumented-public-function
185143
# N805 - invalid-first-argument-name-for-method
186144
# F821 - undefined-name
187145
# F401 - unused-import
188146
# INP001 - implicit-namespace-package
189147
# SLF001 - private-member-access
190148
# ARG001 - unused-function-argument
149+
# PLR2004 - magic-value-comparison
191150
"tests/*" = [
192151
"ANN001",
193152
"ANN2",
194-
"D100",
195-
"D102",
196-
"D103",
153+
"D",
197154
"S101",
198155
"INP001",
199156
"SLF001",
200-
"ARG001"
157+
"ARG001",
158+
"PLR2004",
201159
]
202160
"*__init__.py" = ["F401"]
203161
"src/cool_seq_tool/schemas.py" = ["ANN201", "N805", "ANN001"]

src/cool_seq_tool/handlers/seqrepo_access.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ def get_reference_sequence(
5858
start, end = get_inter_residue_pos(start, end, coordinate_type)
5959
if start == end:
6060
end += 1
61-
else:
62-
if start is not None and coordinate_type == CoordinateType.RESIDUE:
63-
start -= 1
61+
elif start is not None and coordinate_type == CoordinateType.RESIDUE:
62+
start -= 1
6463

6564
try:
6665
sequence = self.sr.fetch(ac, start=start, end=end)

src/cool_seq_tool/mappers/alignment.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ async def p_to_c(
6868
# codon. We want to return inter-residue (0-based), so we subtract 1 from this.
6969
if coordinate_type == CoordinateType.RESIDUE:
7070
c_pos = (p_start_pos * 3) - 3, p_end_pos * 3
71+
elif p_start_pos == p_end_pos:
72+
c_pos = ((p_start_pos + 1) * 3) - 3, (p_end_pos + 1) * 3
7173
else:
72-
if p_start_pos == p_end_pos:
73-
c_pos = ((p_start_pos + 1) * 3) - 3, (p_end_pos + 1) * 3
74-
else:
75-
c_pos = ((p_start_pos + 1) * 3) - 3, p_end_pos * 3
74+
c_pos = ((p_start_pos + 1) * 3) - 3, p_end_pos * 3
7675

7776
return {
7877
"c_ac": c_ac,

0 commit comments

Comments
 (0)