From 0bb6a9321aaeefc372f58b877e101e0eca7cc4fa Mon Sep 17 00:00:00 2001 From: Ian Boyes Date: Mon, 27 May 2024 14:25:55 -0700 Subject: [PATCH] ci: fix poetry error during ci image build --- .github/workflows/publish.yml | 2 -- Dockerfile | 5 ++--- fixtures.py | 26 ++++++++++++++++++++++++++ tests/test_workflow.py | 8 ++++---- workflow.py | 25 +++---------------------- 5 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 fixtures.py 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: diff --git a/Dockerfile b/Dockerfile index 0b88950..25e0673 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,5 @@ 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/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 4fb37a4..56aa78a 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, @@ -64,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}