Skip to content

Commit e685463

Browse files
author
drickett
committed
resolve mypy issues, update gitlab ci
1 parent e10d857 commit e685463

File tree

12 files changed

+183
-63
lines changed

12 files changed

+183
-63
lines changed

.github/workflows/python.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest]
25-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11.0-beta.5 - 3.11"]
25+
python-version: ["3.10", "3.11", "3.12"]
2626

2727
steps:
2828
- uses: actions/checkout@v3
@@ -33,10 +33,10 @@ jobs:
3333
python-version: ${{ matrix.python-version }}
3434

3535
- name: Install Hatch
36-
run: pip install --upgrade hatch
36+
run: pip install uv
3737

3838
- name: Run tests
39-
run: hatch run ci-report
39+
run: uv run pytest
4040

4141
- name: Upload coverage data
4242
uses: actions/upload-artifact@v3

.gitlab-ci.yml

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
22
variables:
3+
JUNIT_TEST_REPORT: test_report_${CI_COMMIT_SHORT_SHA}.html
4+
COVERAGE_TEST_REPORT: coverage_report_${CI_COMMIT_SHORT_SHA}
35
PYTHON_VERSION:
4-
value: "3.8"
6+
value: "3.10"
57
options:
6-
- "3.8"
7-
- "3.9"
88
- "3.10"
99
- "3.11"
10+
- "3.12"
1011
description: Python version to use
1112

1213
stages:
@@ -26,13 +27,21 @@ validate-yaml:
2627
- "*.yml"
2728
- "*.yaml"
2829

29-
Check-For-Black:
30+
.python:
31+
image:
32+
name: python:${PYTHON_VERSION}-slim
33+
pull_policy: if-not-present
34+
before_script:
35+
- pip install uv
36+
allow_failure: false
37+
38+
Code-Check:
39+
extends: .python
3040
stage: validate
31-
image: black
3241
script:
3342
- cd $CI_PROJECT_DIR
34-
- black --check src/
35-
allow_failure: false
43+
- uv run mypy --check .
44+
- uv run ruff check .
3645
rules:
3746
- if: $CI_JOB_MANUAL
3847
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
@@ -42,15 +51,14 @@ Check-For-Black:
4251

4352
Check-HLA-Modified-Dates:
4453
stage: validate
45-
image: python:${PYTHON_VERSION}-slim
46-
before_script:
54+
extends: .python
55+
variables:
56+
PYTHONPATH: "${CI_BUILDS_DIR}/src"
57+
script:
4758
- apt update
4859
- apt install git-restore-mtime -y --no-install-recommends
49-
- pip install typer
50-
script:
5160
- cd $CI_PROJECT_DIR
52-
- python tools/check_date_modified.py check-dates
53-
allow_failure: false
61+
- uv run tools/check_date_modified.py check-dates
5462
rules:
5563
- if: $CI_JOB_MANUAL
5664
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
@@ -59,23 +67,31 @@ Check-HLA-Modified-Dates:
5967
- src/**/*.mtime
6068

6169
Unit-Tests:
62-
image: python:${PYTHON_VERSION}-slim
63-
before_script:
64-
- pip install hatch
70+
extends: .python
71+
stage: test
6572
script:
66-
- hatch env run --env test ci-report
73+
- cd $CI_PROJECT_DIR
74+
- uv run pytest
75+
-vra
76+
--html=${JUNIT_TEST_REPORT}
77+
--self-contained-html
78+
--cov-report=html:${COVERAGE_TEST_REPORT}
79+
--cov-report=term
80+
--junitxml=pytest.xml
6781
parallel:
6882
matrix:
6983
- PYTHON_VERSION:
70-
- "3.8"
71-
- "3.9"
7284
- "3.10"
7385
- "3.11"
86+
- "3.12"
7487
coverage: '/^TOTAL.+?(\d+\%)$/'
7588
interruptible: true
7689
artifacts:
7790
reports:
78-
junit: unit_test.xml
91+
junit: pytest.xml
7992
coverage_report:
8093
coverage_format: cobertura
8194
path: coverage.xml
95+
paths:
96+
- ${COVERAGE_TEST_REPORT}/*
97+
- ${JUNIT_TEST_REPORT}

mypy.ini

Lines changed: 0 additions & 5 deletions
This file was deleted.

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ dependencies = [
3737
dev = [
3838
"mypy>=1.15.0",
3939
"mypy-extensions>=1.0.0",
40+
"pandas>=2.2.3",
41+
"pandas-stubs>=2.2.3.241126",
4042
"pre-commit>=4.1.0",
4143
"pytest>=8.3.5",
4244
"pytest-cov>=6.0.0",
@@ -82,7 +84,7 @@ package = true
8284
[tool.pytest.ini_options]
8385
pythonpath = "src"
8486
minversion = "6.0"
85-
addopts = "-ra -n 4 --cov --cov-report xml --strict-markers -m 'not slow'"
87+
addopts = "-ra -n 4 --cov --cov-report term --cov-report xml --strict-markers -m 'not slow'"
8688
testpaths = ["tests"]
8789
markers = [
8890
"integration: Run integration tests",
@@ -123,3 +125,7 @@ ignore = ["E712"]
123125

124126
[tool.pydocstyle]
125127
match = "src/**/*.py"
128+
129+
[tool.mypy]
130+
plugins = ["numpy.typing.mypy_plugin"]
131+
ignore_missing_imports = true

src/easyhla/easyhla.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,9 @@ def interpret(
552552
seq = np.concatenate((exon2_bin, exon3_bin))
553553
else:
554554
seq = self.pad_short(
555-
self.nuc2bin(entry.seq), samp, hla_std=self.hla_stds[0]
555+
self.nuc2bin(entry.seq), # type: ignore
556+
samp,
557+
hla_std=self.hla_stds[0],
556558
)
557559
exon2 = self.bin2nuc(seq[: EasyHLA.EXON2_LENGTH])
558560
intron = self.bin2nuc(seq[EasyHLA.EXON2_LENGTH : -EasyHLA.EXON3_LENGTH])
@@ -617,7 +619,7 @@ def interpret(
617619
alleles_all_str=alleles_all_str,
618620
ambig=int(ambig),
619621
homozygous=int(homozygous),
620-
mismatch_count=f"{mismatch_count}",
622+
mismatch_count=mismatch_count,
621623
mismatches=f"{mismatches}",
622624
exon2=exon2.upper(),
623625
intron=intron.upper(),

src/easyhla/entrypoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def main(
5555

5656
easyhla.run(
5757
easyhla.letter,
58-
sequence_file,
59-
output_file,
58+
sequence_file.as_posix(),
59+
output_file.as_posix(),
6060
threshold=mismatch_threshold,
6161
to_stdout=print_to_stdout,
6262
)

tests/conftest.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def make_comparison(easyhla: EasyHLA, ref_seq: str, test_seq: str) -> str:
3030
side_is_short = "test"
3131
elif len(ref) < len(test):
3232
side_is_short = "ref"
33-
return easyhla.bin2nuc(masked_seq) + f" [{side_is_short} is short]"
34-
return easyhla.bin2nuc(masked_seq)
33+
return easyhla.bin2nuc(masked_seq) + f" [{side_is_short} is short]" # type: ignore
34+
return easyhla.bin2nuc(masked_seq) # type: ignore
3535

3636

3737
def compare_ref_vs_test(
@@ -60,9 +60,9 @@ def compare_ref_vs_test(
6060

6161
column_names = reference_file[0].strip().split(",")
6262

63-
assert len(reference_file) == len(
64-
test_output_file
65-
), "Size of test output does not match reference file!"
63+
assert len(reference_file) == len(test_output_file), (
64+
"Size of test output does not match reference file!"
65+
)
6666

6767
for row_num, (ref, test) in enumerate(zip(reference_file, test_output_file)):
6868
try:
@@ -86,19 +86,19 @@ def compare_ref_vs_test(
8686

8787
_row_num = row_num + 1 + int(skip_preamble[1])
8888
# Check that there is no strippable whitespace when there shouldn't be.
89-
assert (
90-
_test == _test.strip()
91-
), f"Whitespace detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
92-
assert (
93-
_ref == _ref.strip()
94-
), f"[REFERENCE FILE] Whitespace detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
95-
96-
assert len(_ref.strip()) == len(
97-
_test.strip()
98-
), f"Length mismatch detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
99-
assert (
100-
_ref.strip() == _test.strip()
101-
), f"Content mismatch detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
89+
assert _test == _test.strip(), (
90+
f"Whitespace detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
91+
)
92+
assert _ref == _ref.strip(), (
93+
f"[REFERENCE FILE] Whitespace detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
94+
)
95+
96+
assert len(_ref.strip()) == len(_test.strip()), (
97+
f"Length mismatch detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
98+
)
99+
assert _ref.strip() == _test.strip(), (
100+
f"Content mismatch detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
101+
)
102102

103103
if row_num > 0 and column_names[col_num] in [
104104
"ALLELES_CLEAN",
@@ -107,7 +107,9 @@ def compare_ref_vs_test(
107107
assert (
108108
set(_ref.strip().split(";")) ^ set(_test.strip().split(";"))
109109
== set()
110-
), f"Order mismatch detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
110+
), (
111+
f"Order mismatch detected at row {_row_num}, column {col_num} ('{column_names[col_num]}')"
112+
)
111113
except AssertionError as e:
112114
print("REF >>>", ref)
113115
print("OUT >>>", test)

tests/easyhla_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from datetime import datetime
33
from pathlib import Path
4-
from typing import List, Tuple
4+
from typing import Dict, List, Tuple
55

66
import numpy as np
77
import pytest
@@ -648,7 +648,7 @@ def test_get_matching_stds(
648648
hla_stds: List[HLAStandard],
649649
exp_result: List[HLAStandardMatch],
650650
):
651-
result = easyhla.get_matching_stds(seq=sequence, hla_stds=hla_stds)
651+
result = easyhla.get_matching_stds(seq=sequence, hla_stds=hla_stds) # type: ignore
652652
print(result)
653653
assert result == exp_result
654654

@@ -1034,16 +1034,16 @@ def test_combine_stds(
10341034
sequence: List[int],
10351035
threshold: int,
10361036
matching_standards: List[HLAStandardMatch],
1037-
exp_result: List[int],
1037+
exp_result: Dict[int, List[int]],
10381038
):
10391039
result = easyhla.combine_stds(
10401040
matching_stds=matching_standards,
10411041
seq=sequence,
10421042
max_mismatch_threshold=threshold,
10431043
)
10441044
print(sorted(result.items()))
1045-
print([(k, v) for k, v in exp_result.items()])
1046-
assert sorted(result.items()) == [(k, v) for k, v in exp_result.items()]
1045+
print((k, v) for k, v in exp_result.items())
1046+
assert sorted(result.items()) == list((k, v) for k, v in exp_result.items()) # noqa: C400
10471047

10481048
@pytest.mark.parametrize(
10491049
"best_matches, exp_homozygous, exp_alleles",

tools/check_date_modified.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import typer
2525

26-
from src.easyhla.easyhla import DATE_FORMAT
26+
from easyhla.easyhla import DATE_FORMAT
2727

2828
app = typer.Typer()
2929

tools/data_parse.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434

3535
# 0-1, percentage of input samples that should be suffixed '_exon#'
3636
# HLA Type A has to include the intron
37+
perc_pure_exon: float = 0.0
3738
if HLA_TYPE.upper() == "A":
38-
perc_pure_exon: float = 0.0
39-
else:
40-
perc_pure_exon: float = 0.0
39+
perc_pure_exon = 0.0
4140

4241
sample_input_df = df[[ENUM_IDENTIFIER[HLA_TYPE], "EXON2", "INTRON", "EXON3"]]
4342
sample_input_seqs: Dict[str, str] = {}

0 commit comments

Comments
 (0)