From 9ba68e5843e3b93ec280a81a4c5da80e3a0d650f Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Thu, 5 Oct 2023 17:24:17 +0100 Subject: [PATCH 01/13] Changes to LocalDataset() & get_annotations() to account for releases pulled with folders --- darwin/dataset/local_dataset.py | 25 +++++++++--------------- darwin/dataset/utils.py | 34 ++++++++++++--------------------- 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/darwin/dataset/local_dataset.py b/darwin/dataset/local_dataset.py index c686f516a..75d9387e8 100644 --- a/darwin/dataset/local_dataset.py +++ b/darwin/dataset/local_dataset.py @@ -95,23 +95,16 @@ def __init__( stems = build_stems(release_path, annotations_dir, annotation_type, split, partition, split_type) # Find all the annotations and their corresponding images - for stem in stems: - annotation_path = annotations_dir / f"{stem}.json" - images = [] - for ext in SUPPORTED_IMAGE_EXTENSIONS: - image_path = images_dir / f"{stem}{ext}" - if image_path.exists(): - images.append(image_path) - continue - image_path = images_dir / f"{stem}{ext.upper()}" - if image_path.exists(): - images.append(image_path) - if len(images) < 1: + invalid_annotation_paths = [] + for annotation_path in annotations_dir.glob("**/*.json"): + darwin_json = parse_darwin_json(annotation_path) + image_path = images_dir / Path(darwin_json.full_path.lstrip('/\\')) + if image_path.exists(): + self.images_path.append(image_path) + self.annotations_path.append(annotation_path) + continue + else: raise ValueError(f"Annotation ({annotation_path}) does not have a corresponding image") - if len(images) > 1: - raise ValueError(f"Image ({stem}) is present with multiple extensions. This is forbidden.") - self.images_path.append(images[0]) - self.annotations_path.append(annotation_path) if len(self.images_path) == 0: raise ValueError(f"Could not find any {SUPPORTED_IMAGE_EXTENSIONS} file", f" in {images_dir}") diff --git a/darwin/dataset/utils.py b/darwin/dataset/utils.py index 3f3bb865f..cdaae8ce2 100644 --- a/darwin/dataset/utils.py +++ b/darwin/dataset/utils.py @@ -434,29 +434,19 @@ def get_annotations( # Find all the annotations and their corresponding images invalid_annotation_paths = [] - for stem in stems: - annotation_path = annotations_dir / f"{stem}.json" - images = [] - for ext in SUPPORTED_EXTENSIONS: - image_path = images_dir / f"{stem}{ext}" - if image_path.exists(): - images.append(image_path) - continue - image_path = images_dir / f"{stem}{ext.upper()}" - if image_path.exists(): - images.append(image_path) - - image_count = len(images) - if image_count != 1 and ignore_inconsistent_examples: - invalid_annotation_paths.append(annotation_path) + for annotation_path in annotations_dir.glob("**/*.json"): + darwin_json = parse_darwin_json(annotation_path) + image_path = images_dir / Path(darwin_json.full_path.lstrip('/\\')) + if image_path.exists(): + images_paths.append(image_path) + annotations_paths.append(annotation_path) continue - elif image_count < 1: - raise ValueError(f"Annotation ({annotation_path}) does not have a corresponding image") - elif image_count > 1: - raise ValueError(f"Image ({stem}) is present with multiple extensions. This is forbidden.") - - images_paths.append(images[0]) - annotations_paths.append(annotation_path) + else: + if ignore_inconsistent_examples: + invalid_annotation_paths.append(annotation_path) + continue + else: + raise ValueError(f"Annotation ({annotation_path}) does not have a corresponding image") print(f"Found {len(invalid_annotation_paths)} invalid annotations") for p in invalid_annotation_paths: From a6512665c6e4dc98fc63a1a25d7360098943b53a Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Wed, 11 Oct 2023 14:31:58 +0100 Subject: [PATCH 02/13] Preserve order of annotation files in LocalDataset constructor --- darwin/dataset/local_dataset.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/darwin/dataset/local_dataset.py b/darwin/dataset/local_dataset.py index 75d9387e8..01d2d1d89 100644 --- a/darwin/dataset/local_dataset.py +++ b/darwin/dataset/local_dataset.py @@ -95,8 +95,7 @@ def __init__( stems = build_stems(release_path, annotations_dir, annotation_type, split, partition, split_type) # Find all the annotations and their corresponding images - invalid_annotation_paths = [] - for annotation_path in annotations_dir.glob("**/*.json"): + for annotation_path in sorted(annotations_dir.glob("**/*.json")): darwin_json = parse_darwin_json(annotation_path) image_path = images_dir / Path(darwin_json.full_path.lstrip('/\\')) if image_path.exists(): From 809800f98697766b9763cb10a44729e8f9f84bae Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Thu, 12 Oct 2023 17:30:06 +0100 Subject: [PATCH 03/13] Fixed GH filtering & restored accidentally changed/deleted files --- .github/workflows/EVENT_pull_request.yml | 14 +-- .github/workflows/EVENT_release.yml | 114 +++++++++++------------ .github/workflows/JOB_e2e.yml | 14 +-- deploy/_filter_files.py | 2 +- deploy/nightly_package_setup.py | 44 +++++++++ deploy/revert_nightly_setup.py | 41 ++++++++ 6 files changed, 150 insertions(+), 79 deletions(-) create mode 100644 deploy/nightly_package_setup.py create mode 100644 deploy/revert_nightly_setup.py diff --git a/.github/workflows/EVENT_pull_request.yml b/.github/workflows/EVENT_pull_request.yml index 4c4c1df46..de477c3e6 100644 --- a/.github/workflows/EVENT_pull_request.yml +++ b/.github/workflows/EVENT_pull_request.yml @@ -31,15 +31,15 @@ jobs: with: files: ${{ needs.get_changed_files.outputs.python_changed_files }} - typecheck: - name: Analyse types in python - needs: get_changed_files - uses: ./.github/workflows/JOB_typecheck.yml - with: - files: ${{ needs.get_changed_files.outputs.python_changed_files }} + # typecheck: + # name: Analyse types in python + # needs: get_changed_files + # uses: ./.github/workflows/JOB_typecheck.yml + # with: + # files: ${{ needs.get_changed_files.outputs.python_changed_files }} run_tests: - needs: [format, lint, typecheck] + needs: [format, lint] name: Run tests uses: ./.github/workflows/JOB_tests.yml diff --git a/.github/workflows/EVENT_release.yml b/.github/workflows/EVENT_release.yml index 75a685289..b35b55c14 100644 --- a/.github/workflows/EVENT_release.yml +++ b/.github/workflows/EVENT_release.yml @@ -47,8 +47,9 @@ jobs: needs: validate_tag uses: ./.github/workflows/JOB_tests.yml - build: - needs: validate_tag + release: + needs: [run_tests] + if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -65,80 +66,77 @@ jobs: uses: abatilo/actions-poetry@v2 with: poetry-version: "1.3.1" - - - name: Install dependencies - run: | - poetry install --no-interaction --no-root --all-extras -vvv - poetry build - - - name: Add build to release - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dist/* - asset_name: ${{ env.release_id }}.tar.gz - asset_content_type: application/gzip - - release: - needs: [run_tests, build] - if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - steps: - name: Publish on pypi.org env: POETRY_HTTP_BASIC_PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - # poetry publish - echo "Publishing to pypi.org - Emulated" + poetry publish --build test_release: - needs: [run_tests, build] + needs: [run_tests] if: startsWith(github.ref, 'refs/tags/test-') runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.ref }} + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.9" + - run: pip install pip --upgrade + - name: Setup Poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: "1.3.1" + - name: Check secrets are set + run: | + if [[ -z "${{ secrets.TEST_PYPI_USERNAME }}" || -z "${{ secrets.TEST_PYPI_PASSWORD }}" ]]; then + echo "TEST_PYPI_USERNAME and TEST_PYPI_PASSWORD must be set" + exit 1 + fi - name: Publish on test.pypi.org env: POETRY_HTTP_BASIC_PYPI_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} run: | - poetry publish - echo "Publishing to test.pypi.org - Emulated" + python ./deploy/nightly_package_setup.py + poetry config repositories.test-pypi https://test.pypi.org/legacy/ + poetry config http-basic.test-pypi ${{ secrets.TEST_PYPI_USERNAME }} ${{ secrets.TEST_PYPI_PASSWORD }} + + poetry publish --build --repository test-pypi + python ./deploy/revert_nightly_setup.py # Linear tickets update notify_release: - needs: [release, test_release] - if: always() && contains(needs.*.result, 'success') - runs-on: ubuntu-latest - steps: - - name: Notify Slack - uses: ./.github/workflows/JOB_slack_message.yml - with: - icon: ":rocket:" - at_team: ${{ env.is_scheduled || !env.is_draft }} - secrets: inherit - message: | - :tada: *${{ env.release_tag }}* has been released! - :link: - - https://pypi.org/project/darwin-py - - ${{ github.event.release.html_url }} + needs: [release] + if: success() + uses: ./.github/workflows/JOB_slack_message.yml + secrets: inherit + with: + icon: ":rocket:" + at_team: true + message: | + :tada: *${{ inputs.release_tag || github.event.release.tag_name }}* has been released! + :link: + - https://pypi.org/project/darwin-py + - ${{ github.event.release.html_url }} notify_failed_release: - needs: [release, test_release] - if: always() && contains(needs.*.result, 'failure') - runs-on: ubuntu-latest - steps: - - name: Notify Slack - uses: ./.github/workflows/JOB_slack_message.yml - with: - secrets: inherit - icon: ":warning:" - at_team: true - message: | - :warning: *${{ env.release_tag }}* has failed to be released! - - *An error occurred performing release, and you may need to release manually.* - - :link: - - ${{ github.event.release.html_url }} + needs: [release] + if: failure() + uses: ./.github/workflows/JOB_slack_message.yml + secrets: inherit + with: + icon: ":warning:" + at_team: true + message: | + :warning: *${{ inputs.release_tag || github.event.release.tag_name }}* Release has failed to be released! + + *An error occurred performing release, and you may need to release manually.* + + :link: + - ${{ github.event.release.html_url }} diff --git a/.github/workflows/JOB_e2e.yml b/.github/workflows/JOB_e2e.yml index 41ff46cda..b3e231841 100644 --- a/.github/workflows/JOB_e2e.yml +++ b/.github/workflows/JOB_e2e.yml @@ -58,17 +58,5 @@ jobs: :link: - https://github.com/v7labs/darwin-py/actions/runs/${{ github.run_id }} - :warning: ${{ github.workflow }} failed + :warning: ${{ github.workflow }} failed. - - name: Send Slack Notification - run: | - PAYLOAD=$(cat < None: if file_extension.startswith("."): file_extension = file_extension[1:] - files_out = [file for file in files_in if file.endswith(f".{file_extension}") if "darwin/future" in file] + files_out = [file for file in files_in if file.endswith(f".{file_extension}") and "darwin/future" in file] print(" ".join(files_out)) diff --git a/deploy/nightly_package_setup.py b/deploy/nightly_package_setup.py new file mode 100644 index 000000000..216251ecd --- /dev/null +++ b/deploy/nightly_package_setup.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Require a single string argument, the new package name +# Example: python change_package_name.py com.example.newname + +from datetime import datetime +from os import linesep +from pathlib import Path + + +def main() -> None: + epoch_timestring = datetime.now().strftime("%s") + + this_file_path = Path(__file__).parent.resolve() + path_to_pyproject = this_file_path / ".." / "pyproject.toml" + path_to_version = this_file_path / ".." / "version.txt" + + try: + assert path_to_pyproject.exists() + except AssertionError: + print("No pyproject.toml found.") + exit(1) + + lines = path_to_pyproject.read_text().splitlines() + lines_to_write = [] + + for line in lines: + if line.startswith("name ="): + lines_to_write.append('name = "darwin-nightly"\n') + elif line.startswith("version ="): + version = line.split("=")[1].strip() + path_to_version.write_text(version) + lines_to_write.append(f'version = "{epoch_timestring}"\n') + else: + lines_to_write.append(line) + + path_to_pyproject.write_text(linesep.join(lines_to_write)) + + print(f"Set build to a nightly in pyproject.toml - darwin-nightly@{epoch_timestring}") + + +if __name__ == "__main__": + main() diff --git a/deploy/revert_nightly_setup.py b/deploy/revert_nightly_setup.py new file mode 100644 index 000000000..12737b6aa --- /dev/null +++ b/deploy/revert_nightly_setup.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from datetime import datetime +from os import path +from pathlib import Path + + +def main() -> None: + new_package_name = "darwin-py" + + this_file_path = Path(__file__).parent.resolve() + path_to_pyproject = this_file_path / ".." / "pyproject.toml" + path_to_version = this_file_path / ".." / "version.txt" + + try: + assert path_to_pyproject.exists() + assert path_to_version.exists() + except AssertionError: + print("No nightly build in place to revert") + exit(1) + + lines = path_to_pyproject.read_text().splitlines() + new_version = path_to_version.read_text().strip() + + lines_to_write = [] + + for line in lines: + if line.startswith("name ="): + line = f'name = "{new_package_name}"\n' + if line.startswith("version ="): + line = f'version = {new_version}\n' + lines_to_write.append(line) + + path_to_pyproject.write_text("\n".join(lines_to_write)) + + print(f"Changed package name to {new_package_name}@{new_version} in pyproject.toml") + + +if __name__ == "__main__": + main() From 23441b21ad692db2a26cd163eea61ef52ffda137 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Thu, 12 Oct 2023 17:36:55 +0100 Subject: [PATCH 04/13] Change to ensure tests can run without formatting & linting --- .github/workflows/EVENT_pull_request.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/EVENT_pull_request.yml b/.github/workflows/EVENT_pull_request.yml index de477c3e6..8e8944268 100644 --- a/.github/workflows/EVENT_pull_request.yml +++ b/.github/workflows/EVENT_pull_request.yml @@ -39,7 +39,6 @@ jobs: # files: ${{ needs.get_changed_files.outputs.python_changed_files }} run_tests: - needs: [format, lint] name: Run tests uses: ./.github/workflows/JOB_tests.yml From 08e657ef333c224699f8d31a4a3e4f2127946920 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Wed, 18 Oct 2023 19:33:02 +0100 Subject: [PATCH 05/13] Added funcitonality to access stage names, types, and edges --- darwin/future/meta/objects/stage.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/darwin/future/meta/objects/stage.py b/darwin/future/meta/objects/stage.py index 85ae3b0ba..6ca58683e 100644 --- a/darwin/future/meta/objects/stage.py +++ b/darwin/future/meta/objects/stage.py @@ -41,4 +41,25 @@ def move_attached_files_to_stage(self, new_stage_id: UUID) -> Stage: @property def id(self) -> UUID: + """Stage ID.""" return self._element.id + + @property + def name(self) -> str: + """Stage name.""" + return self._element.name + + @property + def type(self) -> str: + """Stage type.""" + return self._element.type.value + + @property + def edges(self) -> List[List[UUID]]: + """Edge ID, source stage ID, target stage ID.""" + edges = [] + for edge in self._element.edges: + edges.append( + [edge.id, edge.source_stage_id, edge.target_stage_id] + ) + return edges \ No newline at end of file From 760e49c5168b48006a1f541923070085d27cbb82 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Wed, 18 Oct 2023 19:58:52 +0100 Subject: [PATCH 06/13] Formatted stage.py to adhere to Black formatter --- darwin/future/meta/objects/stage.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/darwin/future/meta/objects/stage.py b/darwin/future/meta/objects/stage.py index 747b1637b..bfab84969 100644 --- a/darwin/future/meta/objects/stage.py +++ b/darwin/future/meta/objects/stage.py @@ -57,18 +57,16 @@ def id(self) -> UUID: def name(self) -> str: """Stage name.""" return self._element.name - + @property def type(self) -> str: """Stage type.""" return self._element.type.value - + @property def edges(self) -> List[List[UUID]]: """Edge ID, source stage ID, target stage ID.""" edges = [] for edge in self._element.edges: - edges.append( - [edge.id, edge.source_stage_id, edge.target_stage_id] - ) - return edges \ No newline at end of file + edges.append([edge.id, edge.source_stage_id, edge.target_stage_id]) + return edges From 8b0e213c07df3d6f4e304e2fcb0df3ab26fd8151 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Wed, 18 Oct 2023 20:12:19 +0100 Subject: [PATCH 07/13] Undo accidental changes meant as part of IO-1445 --- darwin/dataset/local_dataset.py | 24 +++++++++++++++-------- darwin/dataset/utils.py | 34 +++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/darwin/dataset/local_dataset.py b/darwin/dataset/local_dataset.py index 01d2d1d89..c686f516a 100644 --- a/darwin/dataset/local_dataset.py +++ b/darwin/dataset/local_dataset.py @@ -95,15 +95,23 @@ def __init__( stems = build_stems(release_path, annotations_dir, annotation_type, split, partition, split_type) # Find all the annotations and their corresponding images - for annotation_path in sorted(annotations_dir.glob("**/*.json")): - darwin_json = parse_darwin_json(annotation_path) - image_path = images_dir / Path(darwin_json.full_path.lstrip('/\\')) - if image_path.exists(): - self.images_path.append(image_path) - self.annotations_path.append(annotation_path) - continue - else: + for stem in stems: + annotation_path = annotations_dir / f"{stem}.json" + images = [] + for ext in SUPPORTED_IMAGE_EXTENSIONS: + image_path = images_dir / f"{stem}{ext}" + if image_path.exists(): + images.append(image_path) + continue + image_path = images_dir / f"{stem}{ext.upper()}" + if image_path.exists(): + images.append(image_path) + if len(images) < 1: raise ValueError(f"Annotation ({annotation_path}) does not have a corresponding image") + if len(images) > 1: + raise ValueError(f"Image ({stem}) is present with multiple extensions. This is forbidden.") + self.images_path.append(images[0]) + self.annotations_path.append(annotation_path) if len(self.images_path) == 0: raise ValueError(f"Could not find any {SUPPORTED_IMAGE_EXTENSIONS} file", f" in {images_dir}") diff --git a/darwin/dataset/utils.py b/darwin/dataset/utils.py index cdaae8ce2..3f3bb865f 100644 --- a/darwin/dataset/utils.py +++ b/darwin/dataset/utils.py @@ -434,19 +434,29 @@ def get_annotations( # Find all the annotations and their corresponding images invalid_annotation_paths = [] - for annotation_path in annotations_dir.glob("**/*.json"): - darwin_json = parse_darwin_json(annotation_path) - image_path = images_dir / Path(darwin_json.full_path.lstrip('/\\')) - if image_path.exists(): - images_paths.append(image_path) - annotations_paths.append(annotation_path) - continue - else: - if ignore_inconsistent_examples: - invalid_annotation_paths.append(annotation_path) + for stem in stems: + annotation_path = annotations_dir / f"{stem}.json" + images = [] + for ext in SUPPORTED_EXTENSIONS: + image_path = images_dir / f"{stem}{ext}" + if image_path.exists(): + images.append(image_path) continue - else: - raise ValueError(f"Annotation ({annotation_path}) does not have a corresponding image") + image_path = images_dir / f"{stem}{ext.upper()}" + if image_path.exists(): + images.append(image_path) + + image_count = len(images) + if image_count != 1 and ignore_inconsistent_examples: + invalid_annotation_paths.append(annotation_path) + continue + elif image_count < 1: + raise ValueError(f"Annotation ({annotation_path}) does not have a corresponding image") + elif image_count > 1: + raise ValueError(f"Image ({stem}) is present with multiple extensions. This is forbidden.") + + images_paths.append(images[0]) + annotations_paths.append(annotation_path) print(f"Found {len(invalid_annotation_paths)} invalid annotations") for p in invalid_annotation_paths: From f08a3190aedfbc0d5e8e57cae3d815fe4f1b0bc8 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Wed, 18 Oct 2023 22:36:38 +0100 Subject: [PATCH 08/13] Added unit tests --- darwin/future/tests/meta/objects/test_stagemeta.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/darwin/future/tests/meta/objects/test_stagemeta.py b/darwin/future/tests/meta/objects/test_stagemeta.py index 9a1d24c7d..65c0d28fc 100644 --- a/darwin/future/tests/meta/objects/test_stagemeta.py +++ b/darwin/future/tests/meta/objects/test_stagemeta.py @@ -81,3 +81,15 @@ def test_move_attached_files_to_stage( + f"v2/teams/default-team/items/ids?workflow_stage_ids={str(stage_meta.id)}&dataset_ids=1337", 1, ) + +def test_get_stage_id(stage_meta): + assert stage_meta.id == UUID("00000000-0000-0000-0000-000000000000") + +def test_get_stage_name(stage_meta): + assert stage_meta.name == "test-stage" + +def test_get_stage_type(stage_meta): + assert stage_meta.type == "annotate" + +def test_get_stage_edges(stage_meta): + assert stage_meta.edges == [] \ No newline at end of file From 05ff725b609b30c680b7d24ceb7f11899c7a2820 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Wed, 18 Oct 2023 22:42:22 +0100 Subject: [PATCH 09/13] Formatting changes to adhere to Black formatter --- darwin/future/tests/meta/objects/test_stagemeta.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/darwin/future/tests/meta/objects/test_stagemeta.py b/darwin/future/tests/meta/objects/test_stagemeta.py index 65c0d28fc..79fb7abad 100644 --- a/darwin/future/tests/meta/objects/test_stagemeta.py +++ b/darwin/future/tests/meta/objects/test_stagemeta.py @@ -82,14 +82,18 @@ def test_move_attached_files_to_stage( 1, ) + def test_get_stage_id(stage_meta): assert stage_meta.id == UUID("00000000-0000-0000-0000-000000000000") + def test_get_stage_name(stage_meta): assert stage_meta.name == "test-stage" + def test_get_stage_type(stage_meta): assert stage_meta.type == "annotate" + def test_get_stage_edges(stage_meta): - assert stage_meta.edges == [] \ No newline at end of file + assert stage_meta.edges == [] From 4bbb9d103e5cb8ffa039c33400b8364825d585ae Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Wed, 18 Oct 2023 22:56:20 +0100 Subject: [PATCH 10/13] Linting changes to adhere to ruff linter --- darwin/future/tests/meta/objects/test_stagemeta.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/darwin/future/tests/meta/objects/test_stagemeta.py b/darwin/future/tests/meta/objects/test_stagemeta.py index 79fb7abad..c0410bc07 100644 --- a/darwin/future/tests/meta/objects/test_stagemeta.py +++ b/darwin/future/tests/meta/objects/test_stagemeta.py @@ -46,7 +46,8 @@ def test_item_ids( rsps.add( rsps.GET, base_meta_client.config.api_endpoint - + f"v2/teams/default-team/items/ids?workflow_stage_ids={str(stage_meta.id)}&dataset_ids=1337", + + f"v2/teams/default-team/items/ids?workflow_stage_ids={str(stage_meta.id)}" + "&dataset_ids=1337", json={"item_ids": UUIDs_str}, status=200, ) @@ -61,7 +62,8 @@ def test_move_attached_files_to_stage( rsps.add( rsps.GET, base_meta_client.config.api_endpoint - + f"v2/teams/default-team/items/ids?workflow_stage_ids={str(stage_meta.id)}&dataset_ids=1337", + + f"v2/teams/default-team/items/ids?workflow_stage_ids={str(stage_meta.id)}" + "&dataset_ids=1337", json={"item_ids": UUIDs_str}, status=200, ) @@ -78,7 +80,8 @@ def test_move_attached_files_to_stage( ) assert rsps.assert_call_count( base_meta_client.config.api_endpoint - + f"v2/teams/default-team/items/ids?workflow_stage_ids={str(stage_meta.id)}&dataset_ids=1337", + + f"v2/teams/default-team/items/ids?workflow_stage_ids={str(stage_meta.id)}" + "&dataset_ids=1337", 1, ) From c386df343ace6e61984520604bd4aeb4809cf95f Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Thu, 19 Oct 2023 12:33:51 +0100 Subject: [PATCH 11/13] Test improvement & change to list comprehension --- darwin/future/meta/objects/stage.py | 8 ++--- .../tests/meta/objects/test_stagemeta.py | 34 +++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/darwin/future/meta/objects/stage.py b/darwin/future/meta/objects/stage.py index bfab84969..44decb650 100644 --- a/darwin/future/meta/objects/stage.py +++ b/darwin/future/meta/objects/stage.py @@ -66,7 +66,7 @@ def type(self) -> str: @property def edges(self) -> List[List[UUID]]: """Edge ID, source stage ID, target stage ID.""" - edges = [] - for edge in self._element.edges: - edges.append([edge.id, edge.source_stage_id, edge.target_stage_id]) - return edges + return [ + [edge.id, edge.source_stage_id, edge.target_stage_id] + for edge in self._element.edges + ] diff --git a/darwin/future/tests/meta/objects/test_stagemeta.py b/darwin/future/tests/meta/objects/test_stagemeta.py index c0410bc07..c68eb792e 100644 --- a/darwin/future/tests/meta/objects/test_stagemeta.py +++ b/darwin/future/tests/meta/objects/test_stagemeta.py @@ -4,7 +4,7 @@ import responses from pytest import fixture -from darwin.future.data_objects.workflow import WFStageCore, WFTypeCore +from darwin.future.data_objects.workflow import WFEdgeCore, WFStageCore, WFTypeCore from darwin.future.meta.client import Client from darwin.future.meta.objects.stage import Stage from darwin.future.tests.core.fixtures import * @@ -99,4 +99,34 @@ def test_get_stage_type(stage_meta): def test_get_stage_edges(stage_meta): - assert stage_meta.edges == [] + edges = [ + WFEdgeCore( + name="edge_1", + id=UUID("00000000-0000-0000-0000-000000000000"), + source_stage_id=UUID("00000000-0000-0000-0000-000000000000"), + target_stage_id=UUID("00000000-0000-0000-0000-000000000000"), + ), + WFEdgeCore( + name="edge_2", + id=UUID("00000000-0000-0000-0000-000000000000"), + source_stage_id=UUID("00000000-0000-0000-0000-000000000000"), + target_stage_id=UUID("00000000-0000-0000-0000-000000000000"), + ), + ] + test_stage = Stage( + stage_meta.client, + WFStageCore( + id=UUID("00000000-0000-0000-0000-000000000000"), + name="test-stage", + type=WFTypeCore.ANNOTATE, + assignable_users=[], + edges=edges, + ), + { + "team_slug": "default-team", + "dataset_id": 1337, + "workflow_id": UUID("00000000-0000-0000-0000-000000000000"), + }, + ) + assert len(test_stage.edges) == 2 + assert len(test_stage.edges[0]) == 3 From 98f475bf2447effcd068e132ca4fa23eb2d2780a Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Thu, 19 Oct 2023 12:48:53 +0100 Subject: [PATCH 12/13] Further test improvement --- darwin/future/tests/meta/objects/test_stagemeta.py | 1 + 1 file changed, 1 insertion(+) diff --git a/darwin/future/tests/meta/objects/test_stagemeta.py b/darwin/future/tests/meta/objects/test_stagemeta.py index c68eb792e..9f3dd68cf 100644 --- a/darwin/future/tests/meta/objects/test_stagemeta.py +++ b/darwin/future/tests/meta/objects/test_stagemeta.py @@ -130,3 +130,4 @@ def test_get_stage_edges(stage_meta): ) assert len(test_stage.edges) == 2 assert len(test_stage.edges[0]) == 3 + assert test_stage.edges[0][0] == UUID("00000000-0000-0000-0000-000000000000") From feae78de110878fa6c89093686aa91ec8d68ba83 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Thu, 19 Oct 2023 12:52:39 +0100 Subject: [PATCH 13/13] Test improvement --- darwin/future/tests/meta/objects/test_stagemeta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/darwin/future/tests/meta/objects/test_stagemeta.py b/darwin/future/tests/meta/objects/test_stagemeta.py index 9f3dd68cf..271ff9721 100644 --- a/darwin/future/tests/meta/objects/test_stagemeta.py +++ b/darwin/future/tests/meta/objects/test_stagemeta.py @@ -124,7 +124,7 @@ def test_get_stage_edges(stage_meta): ), { "team_slug": "default-team", - "dataset_id": 1337, + "dataset_id": 000000, "workflow_id": UUID("00000000-0000-0000-0000-000000000000"), }, )