Skip to content

Commit

Permalink
Move CLI from scripts to entrypoints
Browse files Browse the repository at this point in the history
This make these easier to test and also means we are using a
non-deprecated pyproject.toml configuration for them.
  • Loading branch information
kjsanger committed Nov 20, 2023
1 parent bb8aa7d commit b89641c
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 90 deletions.
32 changes: 17 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion scripts/backfill_pacbio_ids
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/npg_irods/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Command line interface for npg-irods-python."""
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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
Expand Down Expand Up @@ -130,7 +129,3 @@ def main():
num_updated=num_updated,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2022, 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down Expand Up @@ -132,7 +131,3 @@ def main():
num_passed=num_passed,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2022, 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down Expand Up @@ -130,7 +129,3 @@ def main():
num_passed=num_passed,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2023 Genome Research Ltd. All rights reserved.
Expand Down Expand Up @@ -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 = """
Expand Down Expand Up @@ -124,7 +123,3 @@ def main():
num_passed=num_passed,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down Expand Up @@ -140,7 +139,3 @@ def main():
num_passed=num_passed,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
7 changes: 1 addition & 6 deletions scripts/copy-confirm → src/npg_irods/cli/copy_confirm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2022, 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down Expand Up @@ -126,7 +125,3 @@ def main():
except Exception as e:
log.error(e)
exit(1)


if __name__ == "__main__":
main()
9 changes: 3 additions & 6 deletions scripts/locate-data-objects → src/npg_irods/cli/locate_data_objects.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -18,6 +17,7 @@
#
# @author Keith James <[email protected]>


import argparse
from collections import defaultdict
from datetime import datetime, timedelta, timezone
Expand All @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -359,7 +360,3 @@ def main():
print(version())
exit(0)
args.func(args)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2022, 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2022, 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down Expand Up @@ -140,7 +139,3 @@ def main():
num_repaired=num_repaired,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down Expand Up @@ -140,7 +139,3 @@ def main():
num_repaired=num_repaired,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2022, 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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 = """
Expand Down Expand Up @@ -100,7 +99,3 @@ def main():
except Exception as e:
log.error(e)
exit(1)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2023 Genome Research Ltd. All rights reserved.
Expand All @@ -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
Expand Down Expand Up @@ -158,7 +157,3 @@ def main():
num_updated=num_updated,
num_errors=num_errors,
)


if __name__ == "__main__":
main()
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2023 Genome Research Ltd. All rights reserved.
Expand Down Expand Up @@ -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 = """
Expand Down Expand Up @@ -118,7 +117,3 @@ def main():
num_withdrawn=num_withdrawn,
num_errors=num_errors,
)


if __name__ == "__main__":
main()

0 comments on commit b89641c

Please sign in to comment.