From b89641c52c8a899aec00f127392a56cd4136e0c3 Mon Sep 17 00:00:00 2001 From: Keith James Date: Mon, 20 Nov 2023 15:53:46 +0000 Subject: [PATCH] Move CLI from scripts to entrypoints This make these easier to test and also means we are using a non-deprecated pyproject.toml configuration for them. --- pyproject.toml | 32 ++++++++++--------- scripts/backfill_pacbio_ids | 2 +- src/npg_irods/cli/__init__.py | 1 + .../npg_irods/cli/apply_ont_metadata.py | 7 +--- .../npg_irods/cli/check_checksums.py | 7 +--- .../npg_irods/cli/check_common_metadata.py | 7 +--- .../npg_irods/cli/check_consent_withdrawn.py | 7 +--- .../npg_irods/cli/check_replicas.py | 7 +--- .../npg_irods/cli/copy_confirm.py | 7 +--- .../npg_irods/cli/locate_data_objects.py | 9 ++---- .../npg_irods/cli/repair-common-metadata.py | 3 +- .../npg_irods/cli/repair_checksums.py | 7 +--- .../npg_irods/cli/repair_replicas.py | 7 +--- .../npg_irods/cli/safe_remove_script.py | 7 +--- .../cli/update_secondary_metadata.py | 7 +--- src/npg_irods/{cli.py => cli/util.py} | 0 .../npg_irods/cli/withdraw_consent.py | 7 +--- 17 files changed, 34 insertions(+), 90 deletions(-) create mode 100644 src/npg_irods/cli/__init__.py rename scripts/apply-ont-metadata => src/npg_irods/cli/apply_ont_metadata.py (96%) rename scripts/check-checksums => src/npg_irods/cli/check_checksums.py (96%) rename scripts/check-common-metadata => src/npg_irods/cli/check_common_metadata.py (96%) rename scripts/check-consent-withdrawn => src/npg_irods/cli/check_consent_withdrawn.py (96%) rename scripts/check-replicas => src/npg_irods/cli/check_replicas.py (96%) rename scripts/copy-confirm => src/npg_irods/cli/copy_confirm.py (96%) rename scripts/locate-data-objects => src/npg_irods/cli/locate_data_objects.py (99%) mode change 100755 => 100644 rename scripts/repair-common-metadata => src/npg_irods/cli/repair-common-metadata.py (97%) rename scripts/repair-checksums => src/npg_irods/cli/repair_checksums.py (96%) rename scripts/repair-replicas => src/npg_irods/cli/repair_replicas.py (96%) rename scripts/safe-remove-script => src/npg_irods/cli/safe_remove_script.py (95%) rename scripts/update-secondary-metadata => src/npg_irods/cli/update_secondary_metadata.py (97%) rename src/npg_irods/{cli.py => cli/util.py} (100%) rename scripts/withdraw-consent => src/npg_irods/cli/withdraw_consent.py (96%) diff --git a/pyproject.toml b/pyproject.toml index c91d8a2..9cb68c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,14 +34,29 @@ test = [ homepage = "https://github.com/wtsi-npg/npg-irods-python" repository = "https://github.com/wtsi-npg/npg-irods-python.git" +[project.scripts] +"apply-ont-metadata" = "npg_irods.cli.apply_ont_metadata:main" +"check-checksums" = "npg_irods.cli.check_checksums:main" +"check-common-metadata" = "npg_irods.cli.check_common_metadata:main" +"check-consent-withdrawn" = "npg_irods.cli.check_consent_withdrawn:main" +"check-replicas" = "npg_irods.cli.check_replicas:main" +"copy-confirm" = "npg_irods.cli.copy_confirm:main" +"locate-data-objects" = "npg_irods.cli.locate_data_objects:main" +"repair-common-metadata" = "npg_irods.cli.repair_common_metadata:main" +"repair-checksums" = "npg_irods.cli.repair_checksums:main" +"repair-replicas" = "npg_irods.cli.repair_replicas:main" +"safe-remove-script" = "npg_irods.cli.safe_remove_script:main" +"update-secondary-metadata" = "npg_irods.cli.update_secondary_metadata:main" +"withdraw-consent" = "npg_irods.cli.withdraw_consent:main" + [build-system] requires = ["setuptools>=41", "wheel", "setuptools-git-versioning<2"] build-backend = "setuptools.build_meta" [tool.setuptools] # Note: we are relying on setuptools' automatic package discovery, so no further -# configuration is required. This is possible because partisan uses a standard src -# layout. See the following for more information: +# configuration is required. This is possible because npg-irods-python uses a standard +# src layout. See the following for more information: # # https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#src-layout @@ -50,21 +65,8 @@ build-backend = "setuptools.build_meta" # "project.scripts", but that only supports automatcially generating wrapper scripts # for entry points, not installing existing scripts. script-files = [ - "scripts/apply-ont-metadata", "scripts/backfill_illumina_locations.py", "scripts/backfill_pacbio_ids", - "scripts/check-checksums", - "scripts/check-common-metadata", - "scripts/check-consent-withdrawn", - "scripts/check-replicas", - "scripts/copy-confirm", - "scripts/locate-data-objects", - "scripts/repair-checksums", - "scripts/repair-common-metadata", - "scripts/repair-replicas", - "scripts/safe-remove-script", - "scripts/update-secondary-metadata", - "scripts/withdraw-consent", ] [tool.setuptools-git-versioning] diff --git a/scripts/backfill_pacbio_ids b/scripts/backfill_pacbio_ids index ab8a1f1..a5c60cb 100755 --- a/scripts/backfill_pacbio_ids +++ b/scripts/backfill_pacbio_ids @@ -22,7 +22,7 @@ import argparse import logging import structlog -from npg_irods.cli import configure_logging, add_logging_arguments +from npg_irods.cli.util import configure_logging, add_logging_arguments from npg_irods.metadata.pacbio import backfill_id_products from npg_irods.version import version diff --git a/src/npg_irods/cli/__init__.py b/src/npg_irods/cli/__init__.py new file mode 100644 index 0000000..e630e89 --- /dev/null +++ b/src/npg_irods/cli/__init__.py @@ -0,0 +1 @@ +"""Command line interface for npg-irods-python.""" diff --git a/scripts/apply-ont-metadata b/src/npg_irods/cli/apply_ont_metadata.py similarity index 96% rename from scripts/apply-ont-metadata rename to src/npg_irods/cli/apply_ont_metadata.py index ef104ca..92f64bd 100755 --- a/scripts/apply-ont-metadata +++ b/src/npg_irods/cli/apply_ont_metadata.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2023 Genome Research Ltd. All rights reserved. @@ -25,7 +24,7 @@ import structlog from sqlalchemy.orm import Session -from npg_irods.cli import add_logging_arguments, configure_logging, parse_iso_date +from npg_irods.cli.util import add_logging_arguments, configure_logging, parse_iso_date from npg_irods.db import DBConfig from npg_irods.ont import apply_metadata from npg_irods.version import version @@ -130,7 +129,3 @@ def main(): num_updated=num_updated, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/scripts/check-checksums b/src/npg_irods/cli/check_checksums.py similarity index 96% rename from scripts/check-checksums rename to src/npg_irods/cli/check_checksums.py index a35c695..67b8712 100755 --- a/scripts/check-checksums +++ b/src/npg_irods/cli/check_checksums.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2022, 2023 Genome Research Ltd. All rights reserved. @@ -24,7 +23,7 @@ import structlog from npg_irods.utilities import check_checksums -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -132,7 +131,3 @@ def main(): num_passed=num_passed, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/scripts/check-common-metadata b/src/npg_irods/cli/check_common_metadata.py similarity index 96% rename from scripts/check-common-metadata rename to src/npg_irods/cli/check_common_metadata.py index 3fca5df..df0edb4 100755 --- a/scripts/check-common-metadata +++ b/src/npg_irods/cli/check_common_metadata.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2022, 2023 Genome Research Ltd. All rights reserved. @@ -24,7 +23,7 @@ import structlog from npg_irods.utilities import check_common_metadata -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -130,7 +129,3 @@ def main(): num_passed=num_passed, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/scripts/check-consent-withdrawn b/src/npg_irods/cli/check_consent_withdrawn.py similarity index 96% rename from scripts/check-consent-withdrawn rename to src/npg_irods/cli/check_consent_withdrawn.py index 46a1880..37229a5 100755 --- a/scripts/check-consent-withdrawn +++ b/src/npg_irods/cli/check_consent_withdrawn.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2023 Genome Research Ltd. All rights reserved. @@ -26,7 +25,7 @@ from npg_irods.utilities import ( check_consent_withdrawn, ) -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -124,7 +123,3 @@ def main(): num_passed=num_passed, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/scripts/check-replicas b/src/npg_irods/cli/check_replicas.py similarity index 96% rename from scripts/check-replicas rename to src/npg_irods/cli/check_replicas.py index 2ad317d..7781ceb 100755 --- a/scripts/check-replicas +++ b/src/npg_irods/cli/check_replicas.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2023 Genome Research Ltd. All rights reserved. @@ -24,7 +23,7 @@ import structlog from npg_irods.utilities import check_replicas -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -140,7 +139,3 @@ def main(): num_passed=num_passed, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/scripts/copy-confirm b/src/npg_irods/cli/copy_confirm.py similarity index 96% rename from scripts/copy-confirm rename to src/npg_irods/cli/copy_confirm.py index c7baaf7..a44c3e6 100755 --- a/scripts/copy-confirm +++ b/src/npg_irods/cli/copy_confirm.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2022, 2023 Genome Research Ltd. All rights reserved. @@ -25,7 +24,7 @@ from npg_irods.exception import ChecksumError from npg_irods.utilities import copy -from npg_irods.cli import add_logging_arguments, configure_logging, rods_path +from npg_irods.cli.util import add_logging_arguments, configure_logging, rods_path from npg_irods.version import version description = """ @@ -126,7 +125,3 @@ def main(): except Exception as e: log.error(e) exit(1) - - -if __name__ == "__main__": - main() diff --git a/scripts/locate-data-objects b/src/npg_irods/cli/locate_data_objects.py old mode 100755 new mode 100644 similarity index 99% rename from scripts/locate-data-objects rename to src/npg_irods/cli/locate_data_objects.py index 384e36f..e53a253 --- a/scripts/locate-data-objects +++ b/src/npg_irods/cli/locate_data_objects.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2023 Genome Research Ltd. All rights reserved. @@ -18,6 +17,7 @@ # # @author Keith James + import argparse from collections import defaultdict from datetime import datetime, timedelta, timezone @@ -28,7 +28,7 @@ from sqlalchemy.orm import Session from npg_irods import illumina, ont -from npg_irods.cli import ( +from npg_irods.cli.util import ( add_logging_arguments, configure_logging, integer_in_range, @@ -42,6 +42,7 @@ from npg_irods.ont import barcode_collections from npg_irods.version import version + description = """ A utility for locating sets of data objects in iRODS. @@ -359,7 +360,3 @@ def main(): print(version()) exit(0) args.func(args) - - -if __name__ == "__main__": - main() diff --git a/scripts/repair-common-metadata b/src/npg_irods/cli/repair-common-metadata.py similarity index 97% rename from scripts/repair-common-metadata rename to src/npg_irods/cli/repair-common-metadata.py index 8bd3c02..a7a3bb7 100755 --- a/scripts/repair-common-metadata +++ b/src/npg_irods/cli/repair-common-metadata.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2022, 2023 Genome Research Ltd. All rights reserved. @@ -24,7 +23,7 @@ import structlog from npg_irods.utilities import repair_common_metadata -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ diff --git a/scripts/repair-checksums b/src/npg_irods/cli/repair_checksums.py similarity index 96% rename from scripts/repair-checksums rename to src/npg_irods/cli/repair_checksums.py index b4c5ef5..4d1e7be 100755 --- a/scripts/repair-checksums +++ b/src/npg_irods/cli/repair_checksums.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2022, 2023 Genome Research Ltd. All rights reserved. @@ -24,7 +23,7 @@ import structlog from npg_irods.utilities import repair_checksums -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -140,7 +139,3 @@ def main(): num_repaired=num_repaired, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/scripts/repair-replicas b/src/npg_irods/cli/repair_replicas.py similarity index 96% rename from scripts/repair-replicas rename to src/npg_irods/cli/repair_replicas.py index c91db60..bcc9abf 100755 --- a/scripts/repair-replicas +++ b/src/npg_irods/cli/repair_replicas.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2023 Genome Research Ltd. All rights reserved. @@ -24,7 +23,7 @@ import structlog from npg_irods.utilities import repair_replicas -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -140,7 +139,3 @@ def main(): num_repaired=num_repaired, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/scripts/safe-remove-script b/src/npg_irods/cli/safe_remove_script.py similarity index 95% rename from scripts/safe-remove-script rename to src/npg_irods/cli/safe_remove_script.py index b7c7c64..dd1873f 100755 --- a/scripts/safe-remove-script +++ b/src/npg_irods/cli/safe_remove_script.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2022, 2023 Genome Research Ltd. All rights reserved. @@ -23,7 +22,7 @@ import structlog from npg_irods.utilities import write_safe_remove_script -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -100,7 +99,3 @@ def main(): except Exception as e: log.error(e) exit(1) - - -if __name__ == "__main__": - main() diff --git a/scripts/update-secondary-metadata b/src/npg_irods/cli/update_secondary_metadata.py similarity index 97% rename from scripts/update-secondary-metadata rename to src/npg_irods/cli/update_secondary_metadata.py index fb92e5f..07b6e57 100755 --- a/scripts/update-secondary-metadata +++ b/src/npg_irods/cli/update_secondary_metadata.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2023 Genome Research Ltd. All rights reserved. @@ -25,7 +24,7 @@ import structlog from sqlalchemy.orm import Session -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.db import DBConfig from npg_irods.utilities import update_secondary_metadata from npg_irods.version import version @@ -158,7 +157,3 @@ def main(): num_updated=num_updated, num_errors=num_errors, ) - - -if __name__ == "__main__": - main() diff --git a/src/npg_irods/cli.py b/src/npg_irods/cli/util.py similarity index 100% rename from src/npg_irods/cli.py rename to src/npg_irods/cli/util.py diff --git a/scripts/withdraw-consent b/src/npg_irods/cli/withdraw_consent.py similarity index 96% rename from scripts/withdraw-consent rename to src/npg_irods/cli/withdraw_consent.py index e8cc717..c20461b 100755 --- a/scripts/withdraw-consent +++ b/src/npg_irods/cli/withdraw_consent.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2023 Genome Research Ltd. All rights reserved. @@ -26,7 +25,7 @@ from npg_irods.utilities import ( withdraw_consent, ) -from npg_irods.cli import add_logging_arguments, configure_logging +from npg_irods.cli.util import add_logging_arguments, configure_logging from npg_irods.version import version description = """ @@ -118,7 +117,3 @@ def main(): num_withdrawn=num_withdrawn, num_errors=num_errors, ) - - -if __name__ == "__main__": - main()