Skip to content

Commit

Permalink
chore: Switch to ruff (#140)
Browse files Browse the repository at this point in the history
* chore: Update pyproject.toml

* chore: formatting

* chore: update lockfile

* chore: update GHA

* fix: rm deprecated bits from check.sh

* chore: reorder checks
  • Loading branch information
msto authored Jun 17, 2024
1 parent cd554be commit 3d7e415
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 239 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,26 @@ jobs:
run: |
poetry install --extras docs
- name: Run pytest
shell: bash
run: |
poetry run python -m pytest --cov=fgpyo --cov-report=xml --cov-branch
- name: Run isort
shell: bash
run: |
poetry run isort --force-single-line-imports --profile black fgpyo
- name: Style checking
shell: bash
run: |
poetry run black --line-length 99 --check fgpyo
poetry run ruff format --check fgpyo
- name: Run lint
shell: bash
run: |
poetry run flake8 --config=ci/flake8.cfg fgpyo
poetry run ruff check fgpyo
- name: Run mypy
shell: bash
run: |
poetry run mypy -p fgpyo --config=ci/mypy.ini
- name: Run pytest
shell: bash
run: |
poetry run python -m pytest --cov=fgpyo --cov-report=xml --cov-branch
- name: Run docs
shell: bash
run: |
Expand Down
15 changes: 4 additions & 11 deletions ci/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,11 @@ function run() {

parent=$(cd $(dirname $0) && pwd -P)

# If the script is invoked with --check only have black check, otherwise have it fix!
black_extra_args=""
if [[ "$1" == "--check" ]]; then
black_extra_args="--check"
fi

banner "Executing in conda environment ${CONDA_DEFAULT_ENV} in directory ${root}"
run "Unit Tests" "python -m pytest -vv -r sx fgpyo"
run "Import Sorting" "isort --force-single-line-imports --profile black fgpyo"
run "Style Checking" "black --line-length 99 $black_extra_args fgpyo"
run "Linting" "flake8 --config=$parent/flake8.cfg fgpyo"
banner "Executing in conda environment ${CONDA_DEFAULT_ENV} in directory fgpyo"
run "Style Checking" "ruff format fgpyo"
run "Linting" "ruff check --fix fgpyo"
run "Type Checking" "mypy -p fgpyo --config $parent/mypy.ini"
run "Unit Tests" "python -m pytest -vv -r sx fgpyo"

if [ -z "$failures" ]; then
banner "Checks Passed"
Expand Down
6 changes: 0 additions & 6 deletions ci/flake8.cfg

This file was deleted.

10 changes: 4 additions & 6 deletions fgpyo/read_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def fixed_length(self) -> int:
"""The fixed length if there is one. Throws an exception on segments without fixed
lengths!"""
if not self.has_fixed_length:
raise AttributeError(
f"fixed_length called on a variable length read structure: {self}"
)
raise AttributeError(f"fixed_length called on a variable length read structure: {self}")
return self._min_length

@property
Expand Down Expand Up @@ -307,9 +305,9 @@ def from_segments(
segs.append(seg)
segments = tuple(segs)

assert all(
s.length is None or s.length > 0 for s in segments
), "Read structure contained zero length segments" + "".join(str(s) for s in segments)
assert all(s.length is None or s.length > 0 for s in segments), (
"Read structure contained zero length segments" + "".join(str(s) for s in segments)
)

return ReadStructure(segments=segments)

Expand Down
4 changes: 1 addition & 3 deletions fgpyo/sam/tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ def test_sorting() -> None:

def make_sort_order_builder(tmp_path: Path, sort_order: SamOrder) -> Path:
builder = SamBuilder(sort_order=sort_order)
builder.add_pair(
name="test3", chrom="chr1", start1=5000, start2=4700, strand1="-", strand2="+"
)
builder.add_pair(name="test3", chrom="chr1", start1=5000, start2=4700, strand1="-", strand2="+")
builder.add_pair(name="test2", chrom="chr1", start1=4000, start2=4300)
builder.add_pair(name="test1", chrom="chr5", start1=4000, start2=4300)
builder.add_pair(name="test4", chrom="chr2", start1=4000, start2=4300)
Expand Down
5 changes: 4 additions & 1 deletion fgpyo/sam/tests/test_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def test_sam_file_open_writing(
with NamedTemp(suffix=file_type.extension, dir=tmp_path, mode="w", delete=False) as fp:
kwargs = {"header": header_dict}
with sam._pysam_open(
path=fp.file, open_for_reading=False, file_type=file_type, **kwargs # type: ignore
path=fp.file,
open_for_reading=False,
file_type=file_type,
**kwargs, # type: ignore
) as sam_writer:
for r in expected_records:
sam_writer.write(r)
Expand Down
7 changes: 3 additions & 4 deletions fgpyo/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ def set_parser(
set({})
if s == "{}"
else [
subtype_parser(item)
for item in set(split_at_given_level(s[1:-1], split_delim=","))
subtype_parser(item) for item in set(split_at_given_level(s[1:-1], split_delim=","))
]
)
)
Expand Down Expand Up @@ -392,7 +391,7 @@ def get_parser() -> partial:


def get_fields_dict(
cls: Union[_DataclassesOrAttrClass, Type[_DataclassesOrAttrClass]]
cls: Union[_DataclassesOrAttrClass, Type[_DataclassesOrAttrClass]],
) -> Mapping[str, FieldType]:
"""Get the fields dict from either a dataclasses or attr dataclass (or instance)"""
if is_dataclasses_class(cls):
Expand All @@ -404,7 +403,7 @@ def get_fields_dict(


def get_fields(
cls: Union[_DataclassesOrAttrClass, Type[_DataclassesOrAttrClass]]
cls: Union[_DataclassesOrAttrClass, Type[_DataclassesOrAttrClass]],
) -> Tuple[FieldType, ...]:
"""Get the fields tuple from either a dataclasses or attr dataclass (or instance)"""
if is_dataclasses_class(cls):
Expand Down
2 changes: 1 addition & 1 deletion fgpyo/vcf/tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_sort_order(random_generator: random.Random) -> None:


def test_zero_sample_records_match_inputs(
zero_sample_record_inputs: Tuple[Mapping[str, Any]]
zero_sample_record_inputs: Tuple[Mapping[str, Any]],
) -> None:
"""Test if zero-sample VCF (no genotypes) records produced match the requested inputs."""
variant_builder = VariantBuilder()
Expand Down
Loading

0 comments on commit 3d7e415

Please sign in to comment.