Skip to content

Commit

Permalink
feat: properly setup of type checking (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Jan 15, 2024
1 parent d60348b commit a0526c4
Show file tree
Hide file tree
Showing 40 changed files with 850 additions and 595 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ recursive-exclude * *.py[co]
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif

include versioneer.py
include vcfpy/_version.py
include altamisa/_version.py
include altamisa/py.typed

include requirements.txt requirements/*.txt
50 changes: 44 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,59 @@
.PHONY: default black flake8 test test-v test-vv
.PHONY: default
default: help

default: black flake8
.PHONY: help
help:
@echo "make help - show this help"
@echo "make lint - run all linting"
@echo "make format - run all formatting"
@echo "make lint-isort - run isort linting"
@echo "make format-isort - run isort formatting"
@echo "make lint-black - run black linting"
@echo "make format-black - run black formatting"
@echo "make lint-flake8 - run flake8 linting"
@echo "make lint-pyright - run pyright linting"
@echo "make test - run all tests"
@echo "make test-v - run all tests with verbose output"
@echo "make test-vv - run all tests with very verbose output"

black:
black -l 100 --exclude "versioneer.py|_version.py" .
.PHONY: lint
lint: lint-isort lint-black lint-flake8 lint-pyright

.PHONY: format
format: format-isort format-black

.PHONY: lint-isort
lint-isort:
isort --check-only --diff --force-sort-within-sections --profile=black .

.PHONY: format-isort
format-isort:
isort --force-sort-within-sections --profile=black .

black-check:
.PHONY: lint-black
lint-black:
black -l 100 --exclude "versioneer.py|_version.py" --check .

flake8:
.PHONY: format-black
format-black:
black -l 100 --exclude "versioneer.py|_version.py" .

.PHONY: lint-flake8
lint-flake8:
flake8 .

.PHONY: lint-pyright
lint-pyright:
pyright

.PHONY: test
test:
pytest

.PHONY: test-v
test-v:
pytest -v

.PHONY: test-vv
test-vv:
pytest -vv
2 changes: 1 addition & 1 deletion altamisa/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"""Git implementation of _version.py."""

import errno
import functools
import os
import re
import subprocess
import sys
from typing import Any, Callable, Dict, List, Optional, Tuple
import functools


def get_keywords() -> Dict[str, str]:
Expand Down
12 changes: 9 additions & 3 deletions altamisa/apps/isatab2dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"""Conversion of ISA-Tab to dot.
"""

import argparse
import json
import sys
import os
import argparse
import sys

from altamisa.isatab import InvestigationReader, StudyReader, AssayReader
from altamisa.isatab import AssayReader, InvestigationReader, StudyReader


def print_dot(
Expand Down Expand Up @@ -59,6 +59,9 @@ def run(args):
print(' rankdir = "LR";', file=args.output_file)

for s, study_info in enumerate(investigation.studies):
if not study_info.info.path:
print(" /* no file for study {} */".format(s + 1), file=args.output_file)
continue
with open(os.path.join(path, study_info.info.path), "rt") as inputf:
study = StudyReader.from_stream("S{}".format(s + 1), inputf).read()
print(" /* study {} */".format(study_info.info.path), file=args.output_file)
Expand All @@ -68,6 +71,9 @@ def run(args):
print(" }", file=args.output_file)

for a, assay_info in enumerate(study_info.assays):
if not assay_info.path:
print(" /* no file for assay {} */".format(a + 1), file=args.output_file)
continue
with open(os.path.join(path, assay_info.path), "rt") as inputf:
assay = AssayReader.from_stream(
"S{}".format(s + 1), "A{}".format(a + 1), inputf
Expand Down
8 changes: 6 additions & 2 deletions altamisa/apps/isatab2isatab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import warnings

from altamisa.exceptions import IsaException
from altamisa.isatab import (
AssayReader,
AssayValidator,
Expand All @@ -18,7 +19,6 @@
StudyValidator,
StudyWriter,
)
from altamisa.exceptions import IsaException


def run(args):
Expand All @@ -30,7 +30,11 @@ def run(args):
if not args.no_warnings:
for record in records:
warnings.showwarning(
record.message, record.category, record.filename, record.lineno, record.line
record.message,
record.category,
record.filename,
lineno=record.lineno,
line=record.line,
)


Expand Down
76 changes: 43 additions & 33 deletions altamisa/apps/isatab_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"""Read from ISA-Tab and print validation warnings, if any.
"""

import argparse
import os
import sys
import warnings

import attrs
import typer
from typing_extensions import Annotated

from altamisa.isatab import (
AssayReader,
AssayValidator,
Expand All @@ -16,8 +18,40 @@
StudyValidator,
)

#: Typer application instance.
app = typer.Typer()


@attrs.define
class Arguments:
input_investigation_file: str
show_duplicate_warnings: bool


def run(args):
@app.command()
def main(
input_investigation_file: Annotated[
str,
typer.Option(
"--input-investigation-file",
"-i",
help="Path to input investigation file",
),
],
show_duplicate_warnings: Annotated[
bool,
typer.Option(
"--show-duplicate-warnings/--no-show-duplicate_warnings",
help="Show duplicated warnings, i.e. with same message and same category (False by default)",
),
] = False,
):
"""Main entry point."""
# Convert to `Arguments` object.
args = Arguments(
input_investigation_file=input_investigation_file,
show_duplicate_warnings=show_duplicate_warnings,
)
# Show all warnings of same type and content
if args.show_duplicate_warnings:
warnings.simplefilter("always")
Expand All @@ -29,20 +63,20 @@ def run(args):
# Print warnings
for record in records:
warnings.showwarning(
record.message, record.category, record.filename, record.lineno, record.line
record.message, record.category, record.filename, lineno=record.lineno, line=record.line
)


def run_warnings_caught(args):
def run_warnings_caught(args: Arguments):
# Read investigation
investigation = InvestigationReader.from_stream(args.input_investigation_file).read()
args.input_investigation_file.close()
with open(args.input_investigation_file, "rt") as inputf:
investigation = InvestigationReader.from_stream(inputf).read()

# Validate investigation
InvestigationValidator(investigation).validate()

# Read studies and assays
path_in = os.path.normpath(os.path.dirname(args.input_investigation_file.name))
path_in = os.path.normpath(os.path.dirname(args.input_investigation_file))
studies = {}
assays = {}
for s, study_info in enumerate(investigation.studies):
Expand All @@ -69,29 +103,5 @@ def run_warnings_caught(args):
).validate()


def main(argv=None):
parser = argparse.ArgumentParser()

parser.add_argument(
"-i",
"--input-investigation-file",
required=True,
type=argparse.FileType("rt"),
help="Path to input investigation file",
)
parser.add_argument(
"--show-duplicate-warnings",
dest="show_duplicate_warnings",
action="store_true",
help=(
"Show duplicated warnings, i.e. with same message and same category (False by default)"
),
)
parser.set_defaults(no_warnings=False)

args = parser.parse_args(argv)
return run(args)


if __name__ == "__main__": # pragma: no cover
sys.exit(main())
typer.run(main)
4 changes: 2 additions & 2 deletions altamisa/constants/investigation_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


__author__ = (
"Manuel Holtgrewe <manuel.holtgrewe@bihealth.de>, "
"Mathias Kuhring <mathias.kuhring@bihealth.de>"
"Manuel Holtgrewe <manuel.holtgrewe@bih-charite.de>, "
"Mathias Kuhring <mathias.kuhring@bih-charite.de>"
)


Expand Down
4 changes: 2 additions & 2 deletions altamisa/constants/table_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


__author__ = (
"Manuel Holtgrewe <manuel.holtgrewe@bihealth.de>, "
"Mathias Kuhring <mathias.kuhring@bihealth.de>"
"Manuel Holtgrewe <manuel.holtgrewe@bih-charite.de>, "
"Mathias Kuhring <mathias.kuhring@bih-charite.de>"
)


Expand Down
5 changes: 2 additions & 3 deletions altamisa/constants/table_restrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@


__author__ = (
"Manuel Holtgrewe <manuel.holtgrewe@bihealth.de>, "
"Mathias Kuhring <mathias.kuhring@bihealth.de>"
"Manuel Holtgrewe <manuel.holtgrewe@bih-charite.de>, "
"Mathias Kuhring <mathias.kuhring@bih-charite.de>"
)


from . import table_headers


# Assay measurement types (only the once needed for special validations)
PROTEIN_EXPRESSION_PROFILING = "protein expression profiling" #:
PROTEIN_IDENTIFICATION = "protein identification" #:
Expand Down
4 changes: 2 additions & 2 deletions altamisa/constants/table_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


__author__ = (
"Manuel Holtgrewe <manuel.holtgrewe@bihealth.de>, "
"Mathias Kuhring <mathias.kuhring@bihealth.de>"
"Manuel Holtgrewe <manuel.holtgrewe@bih-charite.de>, "
"Mathias Kuhring <mathias.kuhring@bih-charite.de>"
)


Expand Down
2 changes: 1 addition & 1 deletion altamisa/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Exceptions and Warnings used in the AltamISA library.
"""

__author__ = "Manuel Holtgrewe <manuel.holtgrewe@bihealth.de>"
__author__ = "Manuel Holtgrewe <manuel.holtgrewe@bih-charite.de>"


class IsaException(Exception):
Expand Down
2 changes: 1 addition & 1 deletion altamisa/isatab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
from .parse_investigation import InvestigationReader # noqa: F401
from .validate_assay_study import AssayValidator, StudyValidator # noqa: F401
from .validate_investigation import InvestigationValidator # noqa: F401
from .write_assay_study import AssayWriter, StudyWriter, RefTableBuilder # noqa: F401
from .write_assay_study import AssayWriter, RefTableBuilder, StudyWriter # noqa: F401
from .write_investigation import InvestigationWriter # noqa: F401
Loading

0 comments on commit a0526c4

Please sign in to comment.