Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Test Data classes to download from github releases #194

Merged
merged 23 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a92b906
feat: Add GitHubReleaseDataset class for fetching and downloading dat…
jjjermiah Jan 21, 2025
b7e176f
feat: Introduce GitHubReleaseAsset and GitHubRelease classes for enha…
jjjermiah Jan 21, 2025
cef129b
feat: Enhance GitHubReleaseManager with latest release caching and im…
jjjermiah Jan 21, 2025
f1fbdec
feat: Update MedImageTestData to filter extracted files and add struc…
jjjermiah Jan 22, 2025
aa26b87
feat: Update dependencies in pyproject.toml and add import error hand…
jjjermiah Jan 22, 2025
e09479d
feat: Update pixi.toml to include extras for med-imagetools in dev an…
jjjermiah Jan 22, 2025
fd7a21d
feat: Enhance GitHub release management with asynchronous asset downl…
jjjermiah Jan 22, 2025
2be30bc
feat: Remove structureset module and its associated imports
jjjermiah Jan 22, 2025
18bb461
feat: Update test_extract to download specific assets from the latest…
jjjermiah Jan 22, 2025
f768eda
feat: Add progress bar for asynchronous asset downloads in MedImageTe…
jjjermiah Jan 22, 2025
0e79040
feat: Implement progress bar for dataset downloads in MedImageTestData
jjjermiah Jan 22, 2025
167900b
feat: Add CLI command to download test data from the latest GitHub re…
jjjermiah Jan 22, 2025
04f6e29
feat: Update test_extract to filter assets based on specific strings …
jjjermiah Jan 22, 2025
49e3e3a
feat: Add assertion to check minimum release version in test_extract
jjjermiah Jan 22, 2025
1018c71
feat: Temporarily comment out pytest-xdist dependency in pixi.toml
jjjermiah Jan 22, 2025
f0bc308
feat: Enhance CLI with test data command and update workflows for ver…
jjjermiah Jan 22, 2025
5753d1e
feat: Update GitHubReleaseManager to use environment variable for GIT…
jjjermiah Jan 22, 2025
5ad5982
feat: Set GITHUB_TOKEN environment variable in GitHub Actions workflo…
jjjermiah Jan 22, 2025
74b77c6
feat: Enhance GitHubReleaseManager to support configurable request pa…
jjjermiah Jan 22, 2025
a795528
feat: Increase timeout for GitHub API requests and simplify token han…
jjjermiah Jan 22, 2025
19d19f2
feat: Add Windows support to CI workflow and update package platforms
jjjermiah Jan 22, 2025
cec5365
refactor: Update test cases for file handling to improve readability …
jjjermiah Jan 22, 2025
fdbd4c5
feat: Add debug optional dependency for pyvis in pyproject.toml
jjjermiah Jan 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ jobs:
locked: false # wont be the same because of the tag

- name: Run pytest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pixi run -e ${{ matrix.env }} test
pixi run -e ${{ matrix.env }} test -s -vv

- name: Upload coverage report artifact to be used by Codecov
# only upload if matrix.os is ubuntu-latest and matrix.python-version is 3.12
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div align="center">

# Med-Imagetools: Transparent and Reproducible Medical Image Processing Pipelines in Python
<!--intro-start-->

Expand All @@ -15,6 +17,8 @@
[![PyPI - Format](https://img.shields.io/pypi/format/med-imagetools)](https://pypi.org/project/med-imagetools/)
[![Downloads](https://static.pepy.tech/badge/med-imagetools)](https://pepy.tech/project/med-imagetools)

</div>

## Med-ImageTools core features

* AutoPipeline CLI
Expand Down
4,546 changes: 4,353 additions & 193 deletions pixi.lock

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Jermiah Joseph <jermiahjoseph98@gmail.com>"]
channels = ["conda-forge"]
description = "Add a short description here"
name = "med-imagetools"
platforms = ["linux-64", "osx-arm64"]
platforms = ["linux-64", "osx-arm64", "osx-64"]


[dependencies]
Expand All @@ -12,7 +12,7 @@ pip = ">=24.3.1,<25"


[pypi-dependencies]
med-imagetools = { path = ".", editable = true }
med-imagetools = { path = ".", editable = true}

[environments]
dev = ["test", "quality", "build", "dev", "docs"]
Expand All @@ -23,6 +23,9 @@ py311 = { features = ["py311", "test"], no-default-feature = true }
py312 = { features = ["py312", "test"], no-default-feature = true }

############################################## DEV ###############################################
[feature.dev.pypi-dependencies]
med-imagetools = { path = ".", editable = true, extras = ["all"]}

Comment on lines +26 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

The "all" extras group is missing in pyproject.toml

The extras = ["all"] specified in pixi.toml cannot be resolved as the "all" extras group is not defined in pyproject.toml. Currently, only "torch" and "test" extras groups are available.

  • Add an "all" extras group in pyproject.toml that includes all optional dependencies, or
  • Use one of the existing extras groups: "torch" or "test"
🔗 Analysis chain

Verify the "all" extras group exists in pyproject.toml.

The addition of extras = ["all"] looks good, but we should verify that this extras group is properly defined.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the "all" extras group is defined in pyproject.toml
rg -A 5 '\[project\.optional-dependencies\]|\[tool\.poetry\.extras\]' pyproject.toml

Length of output: 199

[feature.dev.dependencies]
ipython = "*"
ipykernel = "*"
Expand All @@ -47,18 +50,17 @@ python = "3.11.*"
[feature.py312.dependencies]
python = "3.12.*"


############################################## TEST ################################################
[feature.test.pypi-dependencies]
med-imagetools = { path = ".", editable = true, extras = ["test"]}

[feature.test.dependencies]
pytest = "*"
pytest-cov = "*"
pytest-xdist = "*"
# pytest-xdist = "*" re-introduce later.
pytest-mock = ">=3.14.0,<4"
sqlalchemy-stubs = ">=0.4,<0.5"

[feature.test.pypi-dependencies]
med-imagetools = { path = ".", editable = true }

[feature.test.tasks.test]
cmd = "pytest -c config/pytest.ini --rootdir ."
Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ classifiers = [
# Optional dependencies (extras)
[project.optional-dependencies]
torch = ["torch", "torchio"]
debug = ["pyvis"]
test = [
"pygithub>=2.5.0",
"aiohttp>=3.8.1",
]
all = [
"pygithub>=2.5.0",
# add these back later
# "torch",
# "torchio",
]
# debug = ["pyvis"]

# Entry points for CLI commands
[project.scripts]
Expand Down
6 changes: 6 additions & 0 deletions src/imgtools/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import set_log_verbosity
from .dicomfind import find_dicoms
from .dicomsort import dicomsort
from .testdatasets import is_testdata_available


@click.group(
Expand All @@ -29,5 +30,10 @@ def cli(verbose: int, quiet: bool) -> None:
cli.add_command(dicomsort)
cli.add_command(find_dicoms, "find-dicoms")

if is_testdata_available():
from .testdatasets import testdata

cli.add_command(testdata)

if __name__ == "__main__":
cli()
73 changes: 73 additions & 0 deletions src/imgtools/cli/testdatasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import pathlib
from typing import List

import click


def is_testdata_available() -> bool:
try:
from github import Github # type: ignore # noqa

return True
except ImportError:
return False


if is_testdata_available():
from imgtools.datasets import MedImageTestData


@click.command()
@click.argument(
"dest",
type=click.Path(
exists=False,
file_okay=False,
dir_okay=True,
writable=True,
path_type=pathlib.Path,
resolve_path=True,
),
)
@click.option(
"-a",
"--assets",
multiple=True,
help="Specific assets to download. If not provided, all assets will be downloaded.",
)
@click.help_option(
"-h",
"--help",
)
def testdata(dest: pathlib.Path, assets: List[str]) -> None:
"""Download test data from the latest GitHub release.

DEST is the directory where the test data will be saved.

assets can be one of the following:

\b
- 4D-Lung.tar.gz
- CC-Tumor-Heterogeneity.tar.gz
- NSCLC-Radiomics.tar.gz
- NSCLC_Radiogenomics.tar.gz
- QIN-PROSTATE-Repeatability.tar.gz
- Soft-tissue-Sarcoma.tar.gz
- Vestibular-Schwannoma-SEG.tar.gz

"""
manager = MedImageTestData()
selected_assets = None

if assets:
selected_assets = [asset for asset in manager.datasets if asset.name in assets]
if not selected_assets:
click.echo(f"No matching assets found for: {', '.join(assets)}")
return

downloaded_files = manager.download(dest, assets=selected_assets)
click.echo(f"Downloaded files: {', '.join(str(file) for file in downloaded_files)}")
jjjermiah marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
testdata()
13 changes: 13 additions & 0 deletions src/imgtools/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .github_helper import (
GitHubRelease,
GitHubReleaseAsset,
GitHubReleaseManager,
MedImageTestData,
)

__all__ = [
"GitHubRelease",
"GitHubReleaseAsset",
"GitHubReleaseManager",
"MedImageTestData",
]
Loading
Loading