Skip to content

Commit

Permalink
Merge pull request #104 from ACED-IDP/fix/repeatable-push
Browse files Browse the repository at this point in the history
fixes: repeatable push, G3T_NUM_PARALLEL,  skip validate client_ids
  • Loading branch information
lbeckman314 authored Dec 2, 2024
2 parents 04d6e8b + 80ad186 commit c1d133b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
10 changes: 9 additions & 1 deletion gen3_tracker/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def git_files(dry_run=False) -> list[str]:
to_upload = set()
for _ in git_logs:
to_upload.update([_ for _ in _['files'] if _.startswith('MANIFEST')])
break
return list(to_upload)
return []

Expand Down Expand Up @@ -597,7 +598,14 @@ def save(self, dvc: DVC) -> str:
self.manifest.append(to_manifest(dvc))
return 'OK'

def commit(self, dry_run=False, profile=None, upload_path=None, bucket_name=None, worker_count=(multiprocessing.cpu_count() - 1)):
@staticmethod
def default_worker_count():
"""Get the default worker count."""
if 'G3T_NUM_PARALLEL' in os.environ:
return int(os.environ.get('G3T_NUM_PARALLEL'))
return multiprocessing.cpu_count() - 1

def commit(self, dry_run=False, profile=None, upload_path=None, bucket_name=None, worker_count=default_worker_count()):
with open(self.manifest_file_path, 'w') as f:
json.dump(self.manifest, f)
if len(self.manifest) > 0:
Expand Down
8 changes: 7 additions & 1 deletion gen3_tracker/git/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ def commit(ctx, targets, message, all):
if all:
command.append("-a")

run_command(" ".join(command), dry_run=config.dry_run, no_capture=True)
try:
run_command(" ".join(command), dry_run=config.dry_run, no_capture=True)
except Exception as e:
click.secho(str(e), fg=ERROR_COLOR, file=sys.stderr)
if config.debug:
raise
exit(1)


@cli.command()
Expand Down
10 changes: 8 additions & 2 deletions gen3_tracker/meta/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ def _check_reference(self: Reference, *args, **kwargs):


def validate(directory_path: pathlib.Path, project_id=None) -> ValidateDirectoryResult:
"""Check FHIR data, accumulate results."""
"""Check FHIR data, accumulate results.
Args:
directory_path: pathlib.Path
project_id: str, optional if set, check that the resource id is valid for the project_id
"""
exceptions = []
resources = defaultdict(int)
# add resources to bundle
Expand All @@ -85,7 +90,8 @@ def validate(directory_path: pathlib.Path, project_id=None) -> ValidateDirectory
continue

try:
assert_valid_id(parse_result.resource, project_id)
if project_id:
assert_valid_id(parse_result.resource, project_id)
except Exception as e:
parse_result.exception = e
exceptions.append(parse_result)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='gen3_tracker',
version='0.0.6',
version='0.0.7rc1',
description='A CLI for adding version control to Gen3 data submission projects.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_end_to_end_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ def test_simple_workflow(runner: CliRunner, project_id, tmpdir) -> None:
# validate the meta files
run(runner, ["--debug", "meta", "validate"])

# update the file
test_file = pathlib.Path("my-project-data/hello.txt")
test_file.parent.mkdir(parents=True, exist_ok=True)
test_file.write_text('hello UPDATE\n')
# re-add the file
run(runner, ["--debug", "add", str(test_file)], expected_files=["MANIFEST/my-project-data/hello.txt.dvc"])
run(runner, ["--debug", "meta", "init"], expected_files=["META/DocumentReference.ndjson"])
run(runner, ["--debug", "commit", "-am", "updated"])
run(runner, ["--debug", "meta", "validate"])

# create a visualisation
run(runner, ["--debug", "meta", "graph"], expected_files=["meta.html"])

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/meta/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import gen3_tracker.config
from gen3_tracker.git import run_command
from gen3_tracker.meta.validator import validate
from tests import run


Expand Down Expand Up @@ -63,6 +64,10 @@ def test_assert_object_id_invalid_on_project_id_change(runner: CliRunner, projec
yaml.dump(config.model_dump(), f)
run(runner, ["commit", "-m", "restore-project_id", '.g3t/config.yaml'])

# ensure we can validate without passing project id
results = validate(directory_path="META")
assert len(results.exceptions) == 0, "Expected no exceptions."

run(runner, ["--debug", "meta", "validate"], expected_exit_code=0)
run(runner, ["--debug", "push", "--dry-run"], expected_exit_code=0)

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_num_parallel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

from gen3_tracker.git import Gen3ClientRemoteWriter


def test_num_parallel():
"""Test the default worker count for file uploads."""
os.environ["G3T_NUM_PARALLEL"] = "9999"
assert Gen3ClientRemoteWriter.default_worker_count() == 9999
del os.environ["G3T_NUM_PARALLEL"]
assert Gen3ClientRemoteWriter.default_worker_count() != 9999
assert Gen3ClientRemoteWriter.default_worker_count() > 0

0 comments on commit c1d133b

Please sign in to comment.