From 95022d2a57f20e6839577b48925ba34816db6a46 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 27 May 2024 14:11:34 -0700 Subject: [PATCH 1/4] ci: fix poetry error during ci image build --- .github/workflows/publish.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a1e077d..80a8490 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,8 +19,6 @@ jobs: uses: actions/checkout@v3 - name: Write VERSION file run: echo ${{ github.event.release.tag_name }} > VERSION - - name: Update pyproject.toml - run: sed -i 's/0\.0\.0/${{ github.event.release.tag_name }}/' pyproject.toml - name: Login to Registry uses: docker/login-action@v2 with: From ee062d745205307b0d9c938a53788feac25030dc Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 27 May 2024 14:14:12 -0700 Subject: [PATCH 2/4] refactor: put fixtures in separate module --- Dockerfile | 4 ++-- fixtures.py | 26 ++++++++++++++++++++++++++ workflow.py | 22 ---------------------- 3 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 fixtures.py diff --git a/Dockerfile b/Dockerfile index 0b88950..2ff821f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ ENV VIRTUAL_ENV=/app/.venv \ COPY --from=bowtie2 /build/bowtie2/* /usr/local/bin/ COPY --from=pigz /build/pigz-2.8/pigz /usr/local/bin/pigz COPY --from=build /workflow/.venv /workflow/.venv -COPY workflow.py VERSION* ./ +COPY fixtures.py workflow.py VERSION* ./ FROM build as test WORKDIR /workflow @@ -45,6 +45,6 @@ ENV PATH="/root/.local/bin:${PATH}" \ COPY --from=build /workflow/.venv /workflow/.venv COPY pyproject.toml poetry.lock ./ RUN poetry install -COPY workflow.py ./ +COPY fixtures.py workflow.py ./ COPY tests/ ./tests/ RUN poetry run pytest diff --git a/fixtures.py b/fixtures.py new file mode 100644 index 0000000..d32ae4d --- /dev/null +++ b/fixtures.py @@ -0,0 +1,26 @@ +import asyncio +from pathlib import Path +from types import SimpleNamespace + +from pyfixtures import fixture + + +@fixture +async def bowtie_index_path(work_path: Path) -> Path: + """The output directory for the subtraction's Bowtie2 index.""" + path = work_path / "bowtie" + await asyncio.to_thread(path.mkdir) + + return path + + +@fixture +async def decompressed_fasta_path(work_path: Path) -> Path: + """The path to the input FASTA file for the subtraction.""" + return work_path / "subtraction.fa" + + +@fixture +def intermediate() -> SimpleNamespace: + """A namespace for intermediate variables.""" + return SimpleNamespace() diff --git a/workflow.py b/workflow.py index 4fb37a4..16ed24d 100644 --- a/workflow.py +++ b/workflow.py @@ -3,7 +3,6 @@ from pathlib import Path from types import SimpleNamespace -from pyfixtures import fixture from virtool_core.utils import compress_file, decompress_file, is_gzipped from virtool_workflow import hooks, step from virtool_workflow.data.subtractions import WFNewSubtraction @@ -16,27 +15,6 @@ async def delete_subtraction(new_subtraction: WFNewSubtraction): await new_subtraction.delete() -@fixture -async def bowtie_index_path(work_path: Path) -> Path: - """The output directory for the subtraction's Bowtie2 index.""" - path = work_path / "bowtie" - await asyncio.to_thread(path.mkdir) - - return path - - -@fixture -async def decompressed_fasta_path(work_path: Path) -> Path: - """The path to the input FASTA file for the subtraction.""" - return work_path / "subtraction.fa" - - -@fixture -def intermediate() -> SimpleNamespace: - """A namespace for intermediate variables.""" - return SimpleNamespace() - - @step(name="Decompress FASTA") async def decompress( decompressed_fasta_path: Path, From a62f27a9f1ef8de5fc3118a23ca6590896f37484 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 27 May 2024 14:18:42 -0700 Subject: [PATCH 3/4] chore: resolve deepsource issue --- workflow.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/workflow.py b/workflow.py index 16ed24d..b2a9bd1 100644 --- a/workflow.py +++ b/workflow.py @@ -42,6 +42,9 @@ async def compute_gc_and_count( """Compute the GC and count.""" def func(path: Path): + if not path.suffix != ".fa": + raise ValueError("Input file is not a FASTA file.") + _count = 0 _nucleotides = {"a": 0, "t": 0, "g": 0, "c": 0, "n": 0} From 369ad099f63e47ed5f8e9a37057ce5a78f60df3a Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 27 May 2024 14:24:30 -0700 Subject: [PATCH 4/4] test: fix failing test --- Dockerfile | 1 - tests/test_workflow.py | 8 ++++---- workflow.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2ff821f..25e0673 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,4 +47,3 @@ COPY pyproject.toml poetry.lock ./ RUN poetry install COPY fixtures.py workflow.py ./ COPY tests/ ./tests/ -RUN poetry run pytest diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 50c3282..afa12f9 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -11,7 +11,7 @@ @pytest.mark.datafiles(ARABIDOPSIS_PATH) async def test_decompress_and_compute_gc(datafiles, mocker, tmp_path: Path): - fasta_path = tmp_path / "decompress.fa" + decompressed_fasta_path = tmp_path / "decompressed.fa" new_subtraction = WFNewSubtraction( id="foo", @@ -23,13 +23,13 @@ async def test_decompress_and_compute_gc(datafiles, mocker, tmp_path: Path): upload=mocker.Mock(), ) - await decompress(fasta_path, new_subtraction, 1) + await decompress(decompressed_fasta_path, new_subtraction, 1) - assert fasta_path.is_file() + assert decompressed_fasta_path.is_file() intermediate = SimpleNamespace() - await compute_gc_and_count(fasta_path, intermediate) + await compute_gc_and_count(decompressed_fasta_path, intermediate) assert intermediate.gc == {"a": 0.319, "t": 0.319, "g": 0.18, "c": 0.18, "n": 0.002} assert intermediate.count == 7 diff --git a/workflow.py b/workflow.py index b2a9bd1..56aa78a 100644 --- a/workflow.py +++ b/workflow.py @@ -42,7 +42,7 @@ async def compute_gc_and_count( """Compute the GC and count.""" def func(path: Path): - if not path.suffix != ".fa": + if not path.suffix != "fa": raise ValueError("Input file is not a FASTA file.") _count = 0