Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Jan 12, 2024
1 parent 719ea6b commit 8cc3f7a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 35 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ help:
@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"

.PHONY: lint
lint: lint-isort lint-black lint-flake8
lint: lint-isort lint-black lint-flake8 lint-pyright

.PHONY: format
format: format-isort format-black
Expand All @@ -41,6 +42,10 @@ format-black:
lint-flake8:
flake8 .

.PHONY: lint-pyright
lint-pyright:
pyright .

.PHONY: test
test:
pytest
Expand Down
74 changes: 43 additions & 31 deletions altamisa/apps/isatab_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import sys
import warnings

import attrs
import typer
from typing_extensions import Annotated

from altamisa.isatab import (
AssayReader,
AssayValidator,
Expand All @@ -16,8 +20,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 +65,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 +105,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)
Empty file added altamisa/py.typed
Empty file.
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[tool.pyright]
include = [
"altamisa",
"tests",
]
exclude = [
"**/node_modules",
"**/__pycache__",
"src/experimental",
"src/typestubs"
]
defineConstant = { DEBUG = true }
stubPath = "stubs"

reportMissingImports = true
reportMissingTypeStubs = false

pythonVersion = "3.8"
pythonPlatform = "Linux"

executionEnvironments = [
{ root = "src" }
]
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Base requirements

attrs
typer[all]
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def parse_requirements(path):
],
entry_points={
"console_scripts": (
"isatab2dot = altamisa.apps.isatab2dot:main",
"isatab2isatab = altamisa.apps.isatab2isatab:main",
"isatab_validate = altamisa.apps.isatab_validate:main",
"isatab2dot = altamisa.apps.isatab2dot:app",
"isatab2isatab = altamisa.apps.isatab2isatab:app",
"isatab_validate = altamisa.apps.isatab_validate:app",
)
},
description="Implementation of ISA-tools data model and ISA-TAB",
Expand Down

0 comments on commit 8cc3f7a

Please sign in to comment.