Skip to content

Commit

Permalink
Add github actions testing/CI script.
Browse files Browse the repository at this point in the history
Change to Tuple for 3.8 compatibility.
Add more return values to utils.
Add resolve to manifest test.
Add PurePosixPath to manifest path for flattening across platforms.
  • Loading branch information
morriscb committed Jul 17, 2024
1 parent ac1646e commit 433865c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/abc_atlas_access_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci/ab_atlas_access
on:
push:
branches:
- master
pull_request:
jobs:
test:
name: ${{ matrix.python-version }}, ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ "macos-latest", "windows-latest", "ubuntu-latest" ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install
run: |
python -m pip install --upgrade pip
pip install .
- name: Test
run: pytest tests
10 changes: 7 additions & 3 deletions src/abc_atlas_access/abc_atlas_cache/cloud_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional, Union
from abc import ABC, abstractmethod
from pathlib import Path
from pathlib import Path, PurePosixPath
import json
import warnings
import tqdm
Expand Down Expand Up @@ -174,8 +174,12 @@ def list_all_downloaded_manifests(self) -> list:
Return a list of all of the manifest files that have been
downloaded for this dataset
"""
output = [self.manifest_prefix + str(x).split('releases/')[-1]
for x in self.cache_dir.glob("releases/*/manifest.json")]
# Use PurePosixPath for to enforce consistent formatting across
# platforms.
output = [
self.manifest_prefix + str(PurePosixPath(x)).split('releases/')[-1]
for x in self.cache_dir.glob("releases/*/manifest.json")
]
output.sort()
return output

Expand Down
6 changes: 3 additions & 3 deletions tests/abc_atlas_cache/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_metadata_file_attributes(self):
assert file_obj.url == 'https://allen-brain-cell-atlas.s3.us-west-2.amazonaws.com/metadata/Allen-CCF-2020/20230630/parcellation.csv' # noqa: E501
assert file_obj.version == '20230630'
assert file_obj.file_size == 41197
assert file_obj.local_path == cache_path / 'metadata/Allen-CCF-2020/20230630/parcellation.csv' # noqa: E501
assert file_obj.local_path == (cache_path / 'metadata/Allen-CCF-2020/20230630/parcellation.csv').resolve() # noqa: E501
assert file_obj.file_type == 'csv'
assert file_obj.relative_path == 'metadata/Allen-CCF-2020/20230630/parcellation.csv' # noqa: E501
assert file_obj.file_hash == 'aea6f6925d7c84f4e5a2d022cbc9c7bb'
Expand All @@ -128,7 +128,7 @@ def test_image_volume_file_attributes(self):
assert file_obj.url == 'https://allen-brain-cell-atlas.s3.us-west-2.amazonaws.com/image_volumes/MERFISH-C57BL6J-638850-CCF/20230630/resampled_annotation_boundary.nii.gz' # noqa: E501
assert file_obj.version == '20230630'
assert file_obj.file_size == 1548196
assert file_obj.local_path == cache_path / 'image_volumes/MERFISH-C57BL6J-638850-CCF/20230630/resampled_annotation_boundary.nii.gz' # noqa: E501
assert file_obj.local_path == (cache_path / 'image_volumes/MERFISH-C57BL6J-638850-CCF/20230630/resampled_annotation_boundary.nii.gz').resolve() # noqa: E501
assert file_obj.file_type == 'nii.gz'
assert file_obj.relative_path == 'image_volumes/MERFISH-C57BL6J-638850-CCF/20230630/resampled_annotation_boundary.nii.gz' # noqa: E501
assert file_obj.file_hash == "1ce4be21528fa6cbfb462a117552477d"
Expand All @@ -148,7 +148,7 @@ def test_expresion_matrix_file_attributes(self):
assert file_obj.url == 'https://allen-brain-cell-atlas.s3.us-west-2.amazonaws.com/expression_matrices/WMB-10Xv2/20230630/WMB-10Xv2-Isocortex-2-log2.h5ad' # noqa: E501
assert file_obj.version == '20230630'
assert file_obj.file_size == 9444387082
assert file_obj.local_path == cache_path / 'expression_matrices/WMB-10Xv2/20230630/WMB-10Xv2-Isocortex-2-log2.h5ad' # noqa: E501
assert file_obj.local_path == (cache_path / 'expression_matrices/WMB-10Xv2/20230630/WMB-10Xv2-Isocortex-2-log2.h5ad').resolve() # noqa: E501
assert file_obj.file_type == 'h5ad'
assert file_obj.relative_path == 'expression_matrices/WMB-10Xv2/20230630/WMB-10Xv2-Isocortex-2-log2.h5ad' # noqa: E501
assert file_obj.file_hash == "6cf8b3556e625b090c196ff5bb5f6cdd"
Expand Down
10 changes: 5 additions & 5 deletions tests/abc_atlas_cache/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Tuple
import boto3
import hashlib
from moto import mock_aws
Expand All @@ -22,7 +22,7 @@ def create_manifest_dict(version: str,
metadata_file: str = 'metadata_file.csv',
test_directory: str = 'test_directory',
file_hash: Optional[str] = None,
location: str = 'us-east-1') -> tuple[dict, str, str]:
location: str = 'us-east-1') -> Tuple[dict, str, str]:
"""
"""
if file_hash is None:
Expand Down Expand Up @@ -91,7 +91,7 @@ def create_manifest_dict(version: str,
def add_file_to_manifest(
file_attribute: CacheFileAttributes,
manifest: dict
):
) -> dict:
"""
"""
split_file = file_attribute.relative_path.split('/')
Expand Down Expand Up @@ -131,7 +131,7 @@ def add_file_to_manifest(
def add_directory_to_manifest(
file_attribute: CacheFileAttributes,
manifest: dict
):
) -> dict:
"""
"""
split_file = file_attribute.relative_path.split('/')
Expand Down Expand Up @@ -163,7 +163,7 @@ def add_directory_to_manifest(
return manifest


def hash_data(data):
def hash_data(data) -> str:
hasher = hashlib.md5()
hasher.update(data)
return hasher.hexdigest()
Expand Down

0 comments on commit 433865c

Please sign in to comment.