Skip to content

Commit

Permalink
ci: check code format with Black (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueg authored Nov 5, 2023
1 parent 8e9ab93 commit f739d49
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 227 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
lint:
name: Run linting
name: Run static code analysis
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand All @@ -24,6 +24,8 @@ jobs:
pip install .
- name: Lint with Flake8
run: flake8
- name: Check code format with Black
run: black --check setup.py pro_wes/ tests/
test:
name: Run tests
runs-on: ubuntu-latest
Expand Down
48 changes: 12 additions & 36 deletions pro_wes/client_wes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,14 @@ def get_service_info(
try:
response_unvalidated = self.session.get(url, **kwargs).json()
except (RequestException, ValueError) as exc:
raise EngineUnavailable(
"external workflow engine unavailable"
) from exc
raise EngineUnavailable("external workflow engine unavailable") from exc
try:
response = ServiceInfo(**response_unvalidated)
except Exception:
try:
response = ErrorResponse(**response_unvalidated)
except Exception as exc:
raise ValueError(
f"invalid response: {response_unvalidated}"
) from exc
raise ValueError(f"invalid response: {response_unvalidated}") from exc
return response

def post_run(
Expand Down Expand Up @@ -133,18 +129,14 @@ def post_run(
**kwargs,
).json()
except (RequestException, ValueError) as exc:
raise EngineUnavailable(
"external workflow engine unavailable"
) from exc
raise EngineUnavailable("external workflow engine unavailable") from exc
try:
response = RunId(**response_unvalidated)
except Exception:
try:
response = ErrorResponse(**response_unvalidated)
except Exception as exc:
raise ValueError(
f"invalid response: {response_unvalidated}"
) from exc
raise ValueError(f"invalid response: {response_unvalidated}") from exc
return response

def get_runs(
Expand All @@ -171,18 +163,14 @@ def get_runs(
try:
response_unvalidated = self.session.get(url, **kwargs).json()
except (RequestException, ValueError) as exc:
raise EngineUnavailable(
"external workflow engine unavailable"
) from exc
raise EngineUnavailable("external workflow engine unavailable") from exc
try:
response = RunListResponse(**response_unvalidated)
except Exception:
try:
response = ErrorResponse(**response_unvalidated)
except Exception as exc:
raise ValueError(
f"invalid response: {response_unvalidated}"
) from exc
raise ValueError(f"invalid response: {response_unvalidated}") from exc
return response

def get_run(
Expand Down Expand Up @@ -211,9 +199,7 @@ def get_run(
try:
response_unvalidated = self.session.get(url, **kwargs).json()
except (RequestException, ValueError) as exc:
raise EngineUnavailable(
"external workflow engine unavailable"
) from exc
raise EngineUnavailable("external workflow engine unavailable") from exc
# skip validation; workaround for cwl-WES
return response_unvalidated
try:
Expand All @@ -222,9 +208,7 @@ def get_run(
try:
response = ErrorResponse(**response_unvalidated)
except Exception as exc:
raise ValueError(
f"invalid response: {response_unvalidated}"
) from exc
raise ValueError(f"invalid response: {response_unvalidated}") from exc
return response

def get_run_status(
Expand Down Expand Up @@ -252,18 +236,14 @@ def get_run_status(
try:
response_unvalidated = self.session.get(url, **kwargs).json()
except (RequestException, ValueError) as exc:
raise EngineUnavailable(
"external workflow engine unavailable"
) from exc
raise EngineUnavailable("external workflow engine unavailable") from exc
try:
response = RunStatus(**response_unvalidated)
except Exception:
try:
response = ErrorResponse(**response_unvalidated)
except Exception as exc:
raise ValueError(
f"invalid response: {response_unvalidated}"
) from exc
raise ValueError(f"invalid response: {response_unvalidated}") from exc
return response

def cancel_run(
Expand Down Expand Up @@ -291,18 +271,14 @@ def cancel_run(
try:
response_unvalidated = self.session.post(url, **kwargs).json()
except (RequestException, ValueError) as exc:
raise EngineUnavailable(
"external workflow engine unavailable"
) from exc
raise EngineUnavailable("external workflow engine unavailable") from exc
try:
response = RunId(**response_unvalidated)
except Exception:
try:
response = ErrorResponse(**response_unvalidated)
except Exception as exc:
raise ValueError(
f"invalid response: {response_unvalidated}"
) from exc
raise ValueError(f"invalid response: {response_unvalidated}") from exc
return response

def set_token(
Expand Down
29 changes: 15 additions & 14 deletions pro_wes/config_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Defaults(BaseModel):
timeout: Timeout for outgoing requests. May be overridden by more
specific parameters for each endpoint.
"""

timeout: Optional[int] = 3


Expand All @@ -46,9 +47,10 @@ class PostRuns(BaseModel):
raised and the job is set to state `SYSTEM_ERROR`. Once a valid
response is obtained, the counter is reset to 1.
"""
storage_path: Path = Path('/data')

storage_path: Path = Path("/data")
db_insert_attempts: int = 10
id_charset: str = 'string.ascii_uppercase + string.digits'
id_charset: str = "string.ascii_uppercase + string.digits"
id_length: int = 6
timeout_post: Optional[int] = None
timeout_job: Optional[int] = None
Expand All @@ -65,6 +67,7 @@ class ListRuns(BaseModel):
Attributes:
default_page_size: Default page size for response pagination.
"""

default_page_size: int = 5


Expand All @@ -75,6 +78,7 @@ class WorkflowTypeVersion(BaseModel):
workflow_type_version: List of one or more acceptable versions for the
workflow type.
"""

workflow_type_version: Optional[List[str]] = []


Expand All @@ -91,6 +95,7 @@ class DefaultWorkflowEngineParameter(BaseModel):
type: Parameter type.
default_value: Stringified version of default parameter.
"""

name: Optional[str]
type: Optional[str]
default_value: Optional[str]
Expand Down Expand Up @@ -129,25 +134,20 @@ class ServiceInfo(BaseModel):
on how to get an authorization token for use with this service.
tags: Additional information about this service as key-value pairs.
"""

workflow_type_versions: Dict[str, WorkflowTypeVersion] = {
'CWL': WorkflowTypeVersion(workflow_type_version=['v1.0']),
"CWL": WorkflowTypeVersion(workflow_type_version=["v1.0"]),
}
supported_wes_versions: List[str] = [
'1.0.0',
"1.0.0",
]
supported_filesystem_protocols: List[str] = [
'http',
"http",
]
workflow_engine_versions: Dict[str, str] = {}
default_workflow_engine_parameters: List[
DefaultWorkflowEngineParameter
] = []
auth_instructions_url: AnyUrl = (
'https://lifescience-ri.eu/ls-login/'
)
tags: Dict[str, str] = {
'service_repo': 'https://github.com/elixir-europe/proWES'
}
default_workflow_engine_parameters: List[DefaultWorkflowEngineParameter] = []
auth_instructions_url: AnyUrl = "https://lifescience-ri.eu/ls-login/"
tags: Dict[str, str] = {"service_repo": "https://github.com/elixir-europe/proWES"}


class CustomConfig(BaseModel):
Expand All @@ -167,6 +167,7 @@ class CustomConfig(BaseModel):
service_info: Configuration parameters for initiliazing the service
info.
"""

defaults: Defaults = Defaults()
post_runs: PostRuns = PostRuns()
list_runs: ListRuns = ListRuns()
Expand Down
34 changes: 20 additions & 14 deletions pro_wes/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,93 +15,99 @@

class EngineProblem(InternalServerError):
"""The external workflow engine appears to experience problems."""

pass


class EngineUnavailable(EngineProblem):
"""The external workflow engine is not available."""

pass


class NoSuitableEngine(BadRequest):
"""Raised when the service does not know of a suitable engine to process
the requested workflow run.
"""

pass


class RunNotFound(NotFound):
"""Raised when workflow run with given run identifier was not found."""

pass


class IdsUnavailableProblem(PyMongoError):
"""Raised when no unique run identifier could be found for insertion into
the database collection.
"""

pass


class StorageUnavailableProblem(OSError):
"""Raised when storage is not available for OS operations."""

pass


exceptions = {
Exception: {
"message": "An unexpected error occurred.",
"code": '500',
"code": "500",
},
BadRequest: {
"message": "The request is malformed.",
"code": '400',
"code": "400",
},
BadRequestProblem: {
"message": "The request is malformed.",
"code": '400',
"code": "400",
},
ExtraParameterProblem: {
"message": "The request is malformed.",
"code": '400',
"code": "400",
},
NoSuitableEngine: {
"message": "No suitable workflow engine known.",
"code": '400',
"code": "400",
},
ValidationError: {
"message": "The request is malformed.",
"code": '400',
"code": "400",
},
Unauthorized: {
"message": " The request is unauthorized.",
"code": '401',
"code": "401",
},
Forbidden: {
"message": "The requester is not authorized to perform this action.",
"code": '403',
"code": "403",
},
NotFound: {
"message": "The requested resource wasn't found.",
"code": '404',
"code": "404",
},
RunNotFound: {
"message": "The requested run wasn't found.",
"code": '404',
"code": "404",
},
EngineUnavailable: {
"message": "Could not reach remote WES service.",
"code": '500',
"code": "500",
},
InternalServerError: {
"message": "An unexpected error occurred.",
"code": '500',
"code": "500",
},
IdsUnavailableProblem: {
"message": "No/few unique run identifiers available.",
"code": '500',
"code": "500",
},
StorageUnavailableProblem: {
"message": "Storage is not accessible.",
"code": '500',
"code": "500",
},
}
2 changes: 1 addition & 1 deletion pro_wes/ga4gh/wes/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def postServiceInfo(**kwargs) -> Tuple[None, str, Dict]:
"""
service_info = ServiceInfo()
headers = service_info.set_service_info(data=request.json)
return (None, '201', headers)
return (None, "201", headers)


# controller for `POST /runs`
Expand Down
Loading

0 comments on commit f739d49

Please sign in to comment.