Skip to content

Commit eca06f1

Browse files
committed
Fix error handling and update lint settings
1 parent 4cd945b commit eca06f1

11 files changed

+36
-28
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
!pyproject.toml
66
!README.md
77
!sapporo
8+
!sapporo-wes-spec-2.0.0.yml
89
!tests

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LABEL org.opencontainers.image.licenses="Apache2.0"
99

1010
RUN apt update && \
1111
apt install -y --no-install-recommends \
12+
curl \
1213
jq && \
1314
apt clean && \
1415
rm -rf /var/lib/apt/lists/*

compose.dev.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
volumes:
99
- ${PWD}/sapporo:/app/sapporo
1010
- ${PWD}/tests:/app/tests
11+
- ${PWD}/pyproject.toml:/app/pyproject.toml
12+
- ${PWD}/sapporo-wes-spec-2.0.0.yml:/app/sapporo-wes-spec-2.0.0.yml
1113
# The ones below are mounted for cwltool and DinD.
1214
- ${PWD}/runs:${PWD}/runs
1315
- /var/run/docker.sock:/var/run/docker.sock
@@ -20,11 +22,12 @@ services:
2022
- SAPPORO_RUN_DIR=${PWD}/runs
2123
ports:
2224
- 127.0.0.1:1122:1122
23-
restart: on-failure
25+
restart: always
2426
working_dir: /app
2527
command: [ "sleep", "infinity" ]
2628
networks:
2729
- sapporo-dev-network
30+
init: true
2831

2932
networks:
3033
sapporo-dev-network:

compose.keycloak.dev.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ services:
1111
ports:
1212
- 127.0.0.1:8080:8080
1313
user: 0:0
14-
restart: on-failure
15-
command: ["start-dev"]
14+
restart: always
15+
command: [ "start-dev" ]
1616
networks:
1717
- sapporo-network
1818

1919
networks:
2020
sapporo-network:
21-
# name: sapporo-network
2221
name: sapporo-dev-network
2322
external: true

compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
- SAPPORO_RUN_DIR=${PWD}/runs
1616
ports:
1717
- 127.0.0.1:1122:1122
18-
restart: on-failure
18+
restart: always
1919
working_dir: /app
2020
command: [ "sapporo" ]
2121
networks:

pyproject.toml

+4-12
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,9 @@ testpaths = ["tests/py_tests"]
7878

7979
[tool.mypy]
8080
files = ["./sapporo/**/*.py"]
81+
follow_imports = "silent"
82+
strict = true
8183
ignore_missing_imports = true
82-
follow_imports = "skip"
83-
warn_redundant_casts = true
84-
warn_unused_ignores = true
85-
disallow_any_generics = true
86-
check_untyped_defs = true
87-
no_implicit_reexport = true
88-
disallow_untyped_defs = true
89-
90-
[tool.pydantic-mypy]
91-
init_forbid_extra = true
92-
init_typed = true
93-
warn_required_dynamic_aliases = true
9484

9585
[tool.pylint.messages_control]
9686
disable = [
@@ -105,5 +95,7 @@ disable = [
10595
"R0913", # Too many arguments
10696
"R0914", # Too many local variables
10797
"R0915", # Too many statements
98+
"R0917", # Too many positional arguments
10899
"R1705", # Unnecessary "else" after "return"
100+
"W0719", # Raising too general exception
109101
]

sapporo/auth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_auth_config() -> AuthConfig:
8989

9090

9191
class HTTPBearerCustom(HTTPBearer):
92-
async def __call__(self, request: Request) -> str:
92+
async def __call__(self, request: Request) -> str: # type: ignore
9393
authorization = request.headers.get("Authorization")
9494
scheme, credentials = get_authorization_scheme_param(authorization)
9595
if not (authorization and scheme and credentials):
@@ -262,7 +262,7 @@ async def external_create_access_token(username: str, password: str) -> str:
262262
async with httpx.AsyncClient() as client:
263263
res = await client.post(token_url, data=data, headers=headers, follow_redirects=True)
264264
res.raise_for_status()
265-
return res.json()["access_token"]
265+
return res.json()["access_token"] # type: ignore
266266
except Exception as e:
267267
raise HTTPException(
268268
status_code=status.HTTP_401_UNAUTHORIZED,

sapporo/database.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_session() -> Generator[Session, None, None]:
5151
# === Models ===
5252

5353

54-
class Run(SQLModel, table=True): # type: ignore
54+
class Run(SQLModel, table=True):
5555
__tablename__ = "runs"
5656

5757
run_id: str = Field(primary_key=True)
@@ -125,7 +125,7 @@ def add_run_db(
125125

126126

127127
def system_state_counts() -> Dict[str, int]:
128-
statement = select(Run.state, func.count(Run.run_id)).group_by(Run.state) # pylint: disable=E1102
128+
statement = select(Run.state, func.count(Run.run_id)).group_by(Run.state) # type: ignore # pylint: disable=E1102
129129
with get_session() as session:
130130
results = session.exec(statement).all()
131131

@@ -146,7 +146,7 @@ def _encode_page_token(last_run: Run) -> str:
146146

147147
def _decode_page_token(page_token: str) -> Dict[str, str]:
148148
token_data = base64.urlsafe_b64decode(page_token).decode("utf-8")
149-
return json.loads(token_data)
149+
return json.loads(token_data) # type: ignore
150150

151151

152152
def list_runs_db(

sapporo/ro_crate.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import magic
1919
import multiqc
2020
from fastapi import UploadFile
21+
from multiqc.core.update_config import ClConfig
2122
from pydantic import BaseModel, TypeAdapter
2223
from rocrate.model.computationalworkflow import ComputationalWorkflow
2324
from rocrate.model.computerlanguage import ComputerLanguage
@@ -510,7 +511,15 @@ def add_multiqc_stats(crate: ROCrate, run_dir: Path, create_action_ins: ContextE
510511
stderr = io.StringIO()
511512
try:
512513
with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
513-
multiqc.run(str(run_dir), outdir=str(run_dir), data_format="json", no_report=True, quiet=True)
514+
multiqc.run(
515+
str(run_dir),
516+
cfg=ClConfig(
517+
output_dir=str(run_dir),
518+
data_format="json",
519+
make_report=False,
520+
quiet=True,
521+
),
522+
)
514523
except Exception: # pylint: disable=broad-except
515524
print(stderr.getvalue(), file=sys.stderr)
516525
return
@@ -672,7 +681,7 @@ def extract_exe_dir_file_ids(crate: ROCrate) -> List[str]:
672681
for entity in crate.get_entities():
673682
if isinstance(entity, Dataset):
674683
if str(entity["@id"]) == f"{RUN_DIR_STRUCTURE['exe_dir']}/":
675-
return get_norm_value(entity, "hasPart")
684+
return get_norm_value(entity, "hasPart") # type: ignore
676685
return []
677686

678687

sapporo/run.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def wf_engine_params_to_str(run_request: RunRequestForm) -> str:
8585
service_info = create_service_info()
8686
default_wf_engine_params = service_info.default_workflow_engine_parameters.get(wf_engine or "", []) # pylint: disable=E1101
8787
for param in default_wf_engine_params:
88-
params.append(param.get("name", ""))
89-
params.append(param.get("default_value", ""))
88+
params.append(param.name or "")
89+
params.append(param.default_value or "")
9090
else:
9191
for key, value in wf_engine_params.items():
9292
params.append(str(key))
@@ -120,9 +120,12 @@ def download_wf_attachment(run_id: str, run_request: RunRequestForm) -> None:
120120
res.raise_for_status()
121121
with file_path.open(mode="wb") as f:
122122
f.write(res.content)
123+
except httpx.HTTPStatusError as e:
124+
# Because it is a background task, raise Exception instead of HTTPException
125+
raise Exception(f"Failed to download workflow attachment {obj}: {res.status_code} {res.text}") from e
123126
except Exception as e:
124127
# Because it is a background task, raise Exception instead of HTTPException
125-
raise Exception(f"Failed to download workflow attachment {obj}: {res.status_code} {res.text}") from e # pylint: disable=W0719
128+
raise Exception(f"Failed to download workflow attachment {obj}: {e}") from e
126129

127130

128131
def fork_run(run_id: str) -> None:

sapporo/schemas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class RunSummary(RunStatus):
277277

278278

279279
class RunListResponse(BaseModel):
280-
runs: Optional[List[Union[RunStatus, RunSummary]]] = Field(
280+
runs: Optional[Union[List[RunStatus], List[RunSummary]]] = Field(
281281
None,
282282
description=GA4GH_WES_SCHEMAS["RunListResponse"]["properties"]["runs"]["description"],
283283
)

0 commit comments

Comments
 (0)