Skip to content

Commit

Permalink
remove pypi release action
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrOertlin committed Dec 4, 2023
1 parent 9e48c77 commit 3389fef
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 66 deletions.
33 changes: 1 addition & 32 deletions .github/workflows/release_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,4 @@ jobs:
context: ./
file: ./Dockerfile
push: true
tags: "clinicalgenomics/arnold:${{github.event.release.tag_name}}, clinicalgenomics/arnold:latest"

build-n-publish:
name: Build and publish Python distribution to PyPI
runs-on: ubuntu-latest
steps:
- name: Check out git repository
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install build tools
run: >-
python -m
pip install
wheel
twine
--user
- name: Build a binary wheel and a source tarball
run: >-
python
setup.py
sdist
bdist_wheel
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
tags: "clinicalgenomics/arnold:${{github.event.release.tag_name}}, clinicalgenomics/arnold:latest"
6 changes: 4 additions & 2 deletions arnold/api/api_v1/endpoints/flow_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def create_flow_cell(
) -> JSONResponse:
if find_flow_cell(flow_cell_id=flow_cell.flow_cell_id, adapter=adapter):
return JSONResponse(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED, content="flow_cell already in database"
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
content="flow_cell already in database",
)
try:
create.create_flow_cell(adapter=adapter, flow_cell=flow_cell)
Expand All @@ -52,5 +53,6 @@ def create_flow_cell(
)

return JSONResponse(
status_code=status.HTTP_200_OK, content=f"flow_cell {flow_cell.flow_cell_id} inserted to db"
status_code=status.HTTP_200_OK,
content=f"flow_cell {flow_cell.flow_cell_id} inserted to db",
)
23 changes: 19 additions & 4 deletions arnold/api/api_v1/endpoints/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class ReceivedPlotModel(BaseModel):
datapoints: List[ReceivedPlotDatapointsModel]


@router.get("/received", response_model=List[ReceivedPlotModel], response_model_exclude_none=True)
@router.get(
"/received",
response_model=List[ReceivedPlotModel],
response_model_exclude_none=True,
)
def received(
adapter: ArnoldAdapter = Depends(get_arnold_adapter),
date_min: Optional[dt.date] = dt.date.min,
Expand Down Expand Up @@ -53,7 +57,11 @@ def received(
},
{
"$group": {
"_id": {"tag": "$tag", "year": "$received_year", "month": "$received_month"},
"_id": {
"tag": "$tag",
"year": "$received_year",
"month": "$received_month",
},
"total": {"$sum": 1},
}
},
Expand Down Expand Up @@ -96,7 +104,11 @@ def received(
return list(samples)


@router.get("/turnaround", response_model=List[ReceivedPlotModel], response_model_exclude_none=True)
@router.get(
"/turnaround",
response_model=List[ReceivedPlotModel],
response_model_exclude_none=True,
)
def turnaround(
adapter: ArnoldAdapter = Depends(get_arnold_adapter),
date_min: Optional[dt.date] = dt.date.min,
Expand Down Expand Up @@ -124,7 +136,10 @@ def turnaround(
"received_month": {"$month": "$received_date"},
"priority": "$priority",
"turnaround_time": {
"$divide": [{"$subtract": ["$delivery_date", "$received_date"]}, 86400000]
"$divide": [
{"$subtract": ["$delivery_date", "$received_date"]},
86400000,
]
},
}
},
Expand Down
17 changes: 12 additions & 5 deletions arnold/api/api_v1/endpoints/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def create_sample(
) -> JSONResponse:
if arnold.crud.read.sample.find_sample(sample_id=sample.sample_id, adapter=adapter):
return JSONResponse(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED, content="Sample already in database"
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
content="Sample already in database",
)
try:
create.create_sample(adapter=adapter, sample=sample)
Expand All @@ -60,7 +61,8 @@ def create_sample(
)

return JSONResponse(
status_code=status.HTTP_200_OK, content=f"Sample {sample.sample_id} inserted to db"
status_code=status.HTTP_200_OK,
content=f"Sample {sample.sample_id} inserted to db",
)


Expand All @@ -75,7 +77,9 @@ def create_samples(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
content=f"exception {e} ",
)
return JSONResponse(status_code=status.HTTP_200_OK, content="Samples inserted to db")
return JSONResponse(
status_code=status.HTTP_200_OK, content="Samples inserted to db"
)


@router.put("/sample/")
Expand All @@ -92,7 +96,8 @@ def update_sample(
)

return JSONResponse(
status_code=status.HTTP_200_OK, content=f"Sample {sample.sample_id} inserted to db"
status_code=status.HTTP_200_OK,
content=f"Sample {sample.sample_id} inserted to db",
)


Expand All @@ -108,4 +113,6 @@ def update_samples(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
content=f"exception {e} ",
)
return JSONResponse(status_code=status.HTTP_200_OK, content="Samples inserted to db")
return JSONResponse(
status_code=status.HTTP_200_OK, content="Samples inserted to db"
)
18 changes: 14 additions & 4 deletions arnold/api/api_v1/endpoints/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
from arnold.models.database.step import Step
import logging

from arnold.models.api_models import WorkflowResponce, StepFilters, StepFiltersBase, Pagination
from arnold.models.api_models import (
WorkflowResponce,
StepFilters,
StepFiltersBase,
Pagination,
)
from arnold.settings import get_arnold_adapter
import arnold.crud.read.step

Expand Down Expand Up @@ -87,10 +92,13 @@ def get_steps(


@router.post("/step/")
def create_step(step: Step, adapter: ArnoldAdapter = Depends(get_arnold_adapter)) -> JSONResponse:
def create_step(
step: Step, adapter: ArnoldAdapter = Depends(get_arnold_adapter)
) -> JSONResponse:
if arnold.crud.read.step.find_step(step_id=step.step_id, adapter=adapter):
return JSONResponse(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED, content="step already in database"
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
content="step already in database",
)
try:
create.create_step(adapter=adapter, step=step)
Expand Down Expand Up @@ -120,7 +128,9 @@ def create_steps(


@router.put("/step/")
def update_step(step: Step, adapter: ArnoldAdapter = Depends(get_arnold_adapter)) -> JSONResponse:
def update_step(
step: Step, adapter: ArnoldAdapter = Depends(get_arnold_adapter)
) -> JSONResponse:

try:
update.update_step(adapter=adapter, step=step)
Expand Down
7 changes: 6 additions & 1 deletion arnold/api/api_v1/endpoints/trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def get_dynamic_udfs_over_time(
):
"""Endpoint for trending step udf fields over time. Possible to group by sample fields"""
return trend_step_fields(
adapter=adapter, step_type=step_type, workflow=workflow, field=field, group=group, year=year
adapter=adapter,
step_type=step_type,
workflow=workflow,
field=field,
group=group,
year=year,
)


Expand Down
4 changes: 3 additions & 1 deletion arnold/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def cli(context: click.Context):


@cli.command(name="serve")
@click.option("--version", default="v1", type=click.Choice(["v1", "v2"]), show_default=True)
@click.option(
"--version", default="v1", type=click.Choice(["v1", "v2"]), show_default=True
)
@click.option("--reload", is_flag=True)
def serve_command(reload: bool, version: str):
"""Serve the arnold app for testing purpose."""
Expand Down
4 changes: 3 additions & 1 deletion arnold/crud/read/flow_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
def find_flow_cell(adapter: ArnoldAdapter, flow_cell_id: str) -> Optional[FlowCell]:
"""Find one flow_cell from the flow_cell collection"""

raw_flow_cell = adapter.flow_cell_collection.find_one({"flow_cell_id": flow_cell_id})
raw_flow_cell = adapter.flow_cell_collection.find_one(
{"flow_cell_id": flow_cell_id}
)
if not raw_flow_cell:
return None
return FlowCell(**raw_flow_cell)
Expand Down
6 changes: 5 additions & 1 deletion arnold/crud/read/plot/format_plot_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def format_grouped_plot_data(plot_data: list, group_field, trend_field):
grouped_plottdata[group][trend_field].append(trend_value)
grouped_plottdata[group]["month"].append(month)
continue
grouped_plottdata[group] = {trend_field: [trend_value], "month": [month], "group": group}
grouped_plottdata[group] = {
trend_field: [trend_value],
"month": [month],
"group": group,
}

return [value for group, value in grouped_plottdata.items()]
9 changes: 7 additions & 2 deletions arnold/crud/read/plot/trend_nr_recieved_samples.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import Optional

from arnold.adapter import ArnoldAdapter
from arnold.crud.read.plot.format_plot_data import format_grouped_plot_data, format_plot_data
from arnold.crud.read.plot.format_plot_data import (
format_grouped_plot_data,
format_plot_data,
)


def trend_nr_samples_per_month(
Expand Down Expand Up @@ -37,7 +40,9 @@ def trend_nr_samples_per_month(
pipe = [match, project, match_year, group_by]
data = list(adapter.sample_collection.aggregate(pipe))
return (
format_grouped_plot_data(plot_data=data, group_field=group, trend_field="nr_samples")
format_grouped_plot_data(
plot_data=data, group_field=group, trend_field="nr_samples"
)
if group
else format_plot_data(plot_data=data, trend_field="nr_samples")
)
17 changes: 13 additions & 4 deletions arnold/crud/read/plot/trend_step_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import Optional

from arnold.adapter import ArnoldAdapter
from arnold.crud.read.plot.format_plot_data import format_grouped_plot_data, format_plot_data
from arnold.crud.read.plot.format_plot_data import (
format_grouped_plot_data,
format_plot_data,
)


def trend_step_fields(
Expand Down Expand Up @@ -46,7 +49,9 @@ def trend_step_fields(
}
}
add_average = {
"$addFields": {f"average_{field_replaced_dot}": {"$avg": f"${field_replaced_dot}"}}
"$addFields": {
f"average_{field_replaced_dot}": {"$avg": f"${field_replaced_dot}"}
}
}

if group:
Expand All @@ -59,8 +64,12 @@ def trend_step_fields(
data = list(adapter.step_collection.aggregate(pipe))
return (
format_grouped_plot_data(
plot_data=data, group_field=group, trend_field=f"average_{field_replaced_dot}"
plot_data=data,
group_field=group,
trend_field=f"average_{field_replaced_dot}",
)
if group
else format_plot_data(plot_data=data, trend_field=f"average_{field_replaced_dot}")
else format_plot_data(
plot_data=data, trend_field=f"average_{field_replaced_dot}"
)
)
5 changes: 4 additions & 1 deletion arnold/crud/read/plot/trend_turn_around_times.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import Optional

from arnold.adapter import ArnoldAdapter
from arnold.crud.read.plot.format_plot_data import format_grouped_plot_data, format_plot_data
from arnold.crud.read.plot.format_plot_data import (
format_grouped_plot_data,
format_plot_data,
)


def trend_turn_around_times(
Expand Down
14 changes: 11 additions & 3 deletions arnold/crud/read/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def join_udf_rules(udf_filters: Optional[list[UDFFilter]]) -> list:
except:
pass
udf_queries.append(
{f"{udf_filter.udf_type}_udfs.{udf_filter.udf_name}": {udf_filter.udf_rule: udf_value}}
{
f"{udf_filter.udf_type}_udfs.{udf_filter.udf_name}": {
udf_filter.udf_rule: udf_value
}
}
)
return udf_queries

Expand Down Expand Up @@ -114,7 +118,9 @@ def find_step_type_artifact_udfs(
) -> List[ArtifactUDF]:
"""Getting available artifact udfs from specific step type within specific workflow"""

pipe = find_step_type_udfs_pipe(workflow=workflow, step_type=step_type, udf_from="artifact")
pipe = find_step_type_udfs_pipe(
workflow=workflow, step_type=step_type, udf_from="artifact"
)
try:
aggregation_result = list(adapter.step_collection.aggregate(pipe))
return parse_obj_as(List[ArtifactUDF], aggregation_result[0].get("all_udfs"))
Expand All @@ -127,7 +133,9 @@ def find_step_type_process_udfs(
) -> List[ProcessUDF]:
"""Getting available artifact udfs from specific step type within specific workflow"""

pipe = find_step_type_udfs_pipe(workflow=workflow, step_type=step_type, udf_from="process")
pipe = find_step_type_udfs_pipe(
workflow=workflow, step_type=step_type, udf_from="process"
)
try:
aggregation_result = list(adapter.step_collection.aggregate(pipe))
return parse_obj_as(List[ProcessUDF], aggregation_result[0].get("all_udfs"))
Expand Down
4 changes: 3 additions & 1 deletion arnold/crud/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def update_step(adapter: ArnoldAdapter, step: Step) -> str:

step_id = step.step_id
result: UpdateResult = adapter.step_collection.update_one(
{"_id": step_id}, {"$set": step.dict(by_alias=True, exclude_none=True)}, upsert=True
{"_id": step_id},
{"$set": step.dict(by_alias=True, exclude_none=True)},
upsert=True,
)
if result.raw_result.get("updatedExisting"):
LOG.info("Updated step %s", step_id)
Expand Down
8 changes: 6 additions & 2 deletions tests/api/test_post_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def test_post_sample_already_in_db(mocker, fast_app_client, valid_sample):
def test_post_sample_create_sample_failing(mocker, fast_app_client, valid_sample):
# GIVEN that the sample is not in the database but the create_sample fails
mocker.patch("arnold.crud.read.sample.find_sample", return_value=False)
mocker.patch("arnold.crud.create.create_sample", side_effect=Exception("mocked error"))
mocker.patch(
"arnold.crud.create.create_sample", side_effect=Exception("mocked error")
)

# WHEN running the sample request with data
response = fast_app_client.post("/api/v1/sample/", json=valid_sample.dict())
Expand Down Expand Up @@ -69,7 +71,9 @@ def test_post_invalid_samples(fast_app_client, invalid_samples):

def test_post_sample_create_samples_failing(mocker, fast_app_client, valid_samples):
# GIVEN that the create_samples fails
mocker.patch("arnold.crud.create.create_samples", side_effect=Exception("mocked error"))
mocker.patch(
"arnold.crud.create.create_samples", side_effect=Exception("mocked error")
)

# WHEN running the samples request with data
response = fast_app_client.post("/api/v1/samples/", json=valid_samples)
Expand Down
4 changes: 3 additions & 1 deletion tests/api/test_post_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def test_post_step_already_in_db(mocker, fast_app_client, valid_step):
def test_post_step_create_step_failing(mocker, fast_app_client, valid_step):
# GIVEN that the step is not in the database but the create_step fails
mocker.patch("arnold.crud.read.step.find_step", return_value=False)
mocker.patch("arnold.crud.create.create_step", side_effect=Exception("mocked error"))
mocker.patch(
"arnold.crud.create.create_step", side_effect=Exception("mocked error")
)

# WHEN running the step request with data
response = fast_app_client.post("/api/v1/step/", json=valid_step.dict())
Expand Down
Loading

0 comments on commit 3389fef

Please sign in to comment.