diff --git a/src/npg_irods/__init__.py b/src/npg_irods/__init__.py
index e69de29..813f5e9 100644
--- a/src/npg_irods/__init__.py
+++ b/src/npg_irods/__init__.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © 2022, 2024 Genome Research Ltd. All rights reserved.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# @author Keith James
+
+
+import importlib.metadata
+
+__version__ = importlib.metadata.version("npg-irods-python")
+
+
+def version() -> str:
+ """Return the current version."""
+ return __version__
diff --git a/src/npg_irods/cli/apply_ont_metadata.py b/src/npg_irods/cli/apply_ont_metadata.py
index d5362b4..e39519f 100755
--- a/src/npg_irods/cli/apply_ont_metadata.py
+++ b/src/npg_irods/cli/apply_ont_metadata.py
@@ -32,9 +32,8 @@
from npg.log import configure_structlog
from sqlalchemy.orm import Session
-from npg_irods import db
+from npg_irods import db, version
from npg_irods.ont import apply_metadata
-from npg_irods.version import version
description = """
Applies metadata and data access permissions on ONT run collections in iRODS, to reflect
@@ -66,7 +65,7 @@
type=str,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -81,10 +80,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
dbconfig = IniData(db.Config).from_file(args.db_config.name, "mlwh_ro")
engine = sqlalchemy.create_engine(
dbconfig.url, pool_pre_ping=True, pool_recycle=3600
diff --git a/src/npg_irods/cli/check_checksums.py b/src/npg_irods/cli/check_checksums.py
index 57b341f..66f451e 100755
--- a/src/npg_irods/cli/check_checksums.py
+++ b/src/npg_irods/cli/check_checksums.py
@@ -24,8 +24,8 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import check_checksums
-from npg_irods.version import version
description = """
Reads iRODS data object paths from a file or STDIN, one per line and performs
@@ -77,7 +77,7 @@
default=4,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -92,10 +92,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_passed, num_errors = check_checksums(
args.input,
args.output,
diff --git a/src/npg_irods/cli/check_common_metadata.py b/src/npg_irods/cli/check_common_metadata.py
index 93cb211..efc1f43 100755
--- a/src/npg_irods/cli/check_common_metadata.py
+++ b/src/npg_irods/cli/check_common_metadata.py
@@ -24,8 +24,8 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import check_common_metadata
-from npg_irods.version import version
description = """
Reads iRODS data object paths from a file or STDIN, one per line and performs
@@ -76,7 +76,7 @@
default=4,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -91,10 +91,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_passed, num_errors = check_common_metadata(
args.input,
args.output,
diff --git a/src/npg_irods/cli/check_consent_withdrawn.py b/src/npg_irods/cli/check_consent_withdrawn.py
index 0da3f12..654f5a1 100755
--- a/src/npg_irods/cli/check_consent_withdrawn.py
+++ b/src/npg_irods/cli/check_consent_withdrawn.py
@@ -24,10 +24,11 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import (
check_consent_withdrawn,
)
-from npg_irods.version import version
+
description = """
Reads iRODS data object paths from a file or STDIN, one per line and checks that each
@@ -71,7 +72,7 @@
action="store_true",
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
@@ -87,10 +88,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_passed, num_errors = check_consent_withdrawn(
args.input,
args.output,
diff --git a/src/npg_irods/cli/check_replicas.py b/src/npg_irods/cli/check_replicas.py
index b7ac03c..a282a9a 100755
--- a/src/npg_irods/cli/check_replicas.py
+++ b/src/npg_irods/cli/check_replicas.py
@@ -24,8 +24,8 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import check_replicas
-from npg_irods.version import version
description = """
Reads iRODS data object paths from a file or STDIN, one per line and performs
@@ -85,7 +85,7 @@
default=4,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -100,10 +100,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_passed, num_errors = check_replicas(
args.input,
args.output,
diff --git a/src/npg_irods/cli/copy_confirm.py b/src/npg_irods/cli/copy_confirm.py
index cde0dea..72f2e65 100755
--- a/src/npg_irods/cli/copy_confirm.py
+++ b/src/npg_irods/cli/copy_confirm.py
@@ -25,10 +25,10 @@
from npg.log import configure_structlog
from partisan.exception import RodsError
+from npg_irods import version
from npg_irods.common import rods_path
from npg_irods.exception import ChecksumError
from npg_irods.utilities import copy
-from npg_irods.version import version
description = """
Copies iRODS collections and data objects from one path to another, optionally
@@ -84,7 +84,7 @@
action="store_true",
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -99,10 +99,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
try:
num_processed, num_copied = copy(
args.source,
diff --git a/src/npg_irods/cli/locate_data_objects.py b/src/npg_irods/cli/locate_data_objects.py
index 5b9cb76..0bc9858 100644
--- a/src/npg_irods/cli/locate_data_objects.py
+++ b/src/npg_irods/cli/locate_data_objects.py
@@ -37,7 +37,7 @@
from partisan.irods import AVU, DataObject, RodsItem, query_metadata
from sqlalchemy.orm import Session
-from npg_irods import db, illumina, ont, pacbio, sequenom
+from npg_irods import db, illumina, ont, pacbio, sequenom, version
from npg_irods.db.mlwh import (
find_consent_withdrawn_samples,
@@ -51,7 +51,6 @@
from npg_irods.metadata.illumina import Instrument
from npg_irods.metadata.lims import TrackedSample, TrackedStudy
from npg_irods.ont import barcode_collections
-from npg_irods.version import version
description = """
A utility for locating sets of data objects in iRODS.
@@ -630,7 +629,10 @@ def main():
type=str,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version",
+ help="Print the version and exit.",
+ action="version",
+ version=version(),
)
subparsers = parser.add_subparsers(title="Sub-commands", required=True)
@@ -673,6 +675,20 @@ def main():
)
ilup_parser.set_defaults(func=illumina_updates_cli)
+ ontcre_parser = subparsers.add_parser(
+ "ont-run-creation",
+ help="Find ONT runfolder collections created in iRODS within a specified time "
+ "range.",
+ )
+ add_date_range_arguments(ontcre_parser)
+ ontcre_parser.add_argument(
+ "--report-json",
+ "--report_json",
+ help="Print output in JSON format.",
+ action="store_true",
+ )
+ ontcre_parser.set_defaults(func=ont_run_collections_created_cli)
+
ontup_parser = subparsers.add_parser(
"ont-updates",
help="Find collections, containing data objects for ONT runs, whose tracking"
@@ -755,9 +771,6 @@ def main():
json=args.json,
)
- if args.version:
- print(version())
- sys.exit(0)
args.func(args)
diff --git a/src/npg_irods/cli/repair_checksums.py b/src/npg_irods/cli/repair_checksums.py
index c0306b2..ce66e0c 100755
--- a/src/npg_irods/cli/repair_checksums.py
+++ b/src/npg_irods/cli/repair_checksums.py
@@ -24,8 +24,8 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import repair_checksums
-from npg_irods.version import version
description = """
Reads iRODS data object paths from a file or STDIN, one per line and repairs
@@ -82,7 +82,7 @@
default=4,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -97,10 +97,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_repaired, num_errors = repair_checksums(
args.input,
args.output,
diff --git a/src/npg_irods/cli/repair_common_metadata.py b/src/npg_irods/cli/repair_common_metadata.py
index d229875..26560ab 100755
--- a/src/npg_irods/cli/repair_common_metadata.py
+++ b/src/npg_irods/cli/repair_common_metadata.py
@@ -24,8 +24,8 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import repair_common_metadata
-from npg_irods.version import version
description = """
Reads iRODS data object paths from a file or STDIN, one per line and repairs
@@ -79,7 +79,7 @@
default=4,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -94,10 +94,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_repaired, num_errors = repair_common_metadata(
args.input,
args.output,
diff --git a/src/npg_irods/cli/repair_replicas.py b/src/npg_irods/cli/repair_replicas.py
index 9469303..4cb8146 100755
--- a/src/npg_irods/cli/repair_replicas.py
+++ b/src/npg_irods/cli/repair_replicas.py
@@ -24,8 +24,8 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import repair_replicas
-from npg_irods.version import version
description = """
Reads iRODS data object paths from a file or STDIN, one per line and repairs their
@@ -81,7 +81,7 @@
default=4,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -96,10 +96,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_repaired, num_errors = repair_replicas(
args.input,
args.output,
diff --git a/src/npg_irods/cli/safe_remove_script.py b/src/npg_irods/cli/safe_remove_script.py
index c80055e..eab7a12 100755
--- a/src/npg_irods/cli/safe_remove_script.py
+++ b/src/npg_irods/cli/safe_remove_script.py
@@ -24,8 +24,8 @@
from npg.cli import add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import write_safe_remove_script
-from npg_irods.version import version
description = """
Writes a shell script to allow safe recursive deletion of collections and data objects
@@ -73,7 +73,7 @@
action="store_true",
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -88,10 +88,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
try:
write_safe_remove_script(
args.output,
diff --git a/src/npg_irods/cli/update_secondary_metadata.py b/src/npg_irods/cli/update_secondary_metadata.py
index 1a4ffb3..961abfc 100755
--- a/src/npg_irods/cli/update_secondary_metadata.py
+++ b/src/npg_irods/cli/update_secondary_metadata.py
@@ -26,9 +26,8 @@
from npg.conf import IniData
from npg.log import configure_structlog
-from npg_irods import db
+from npg_irods import db, version
from npg_irods.utilities import update_secondary_metadata
-from npg_irods.version import version
description = """
Reads iRODS data object and/or collection paths from a file or STDIN, one per line and
@@ -89,7 +88,10 @@ def main():
default=4,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version",
+ help="Print the version and exit.",
+ action="version",
+ version=version(),
)
parser.add_argument(
"--zone",
@@ -108,10 +110,6 @@ def main():
json=args.json,
)
- if args.version:
- print(version())
- sys.exit(0)
-
dbconfig = IniData(db.Config).from_file(args.db_config.name, "mlwh_ro")
engine = sqlalchemy.create_engine(
dbconfig.url, pool_pre_ping=True, pool_recycle=3600
diff --git a/src/npg_irods/cli/withdraw_consent.py b/src/npg_irods/cli/withdraw_consent.py
index f806e8d..6235aed 100755
--- a/src/npg_irods/cli/withdraw_consent.py
+++ b/src/npg_irods/cli/withdraw_consent.py
@@ -24,10 +24,10 @@
from npg.cli import add_logging_arguments
from npg.log import configure_structlog
+from npg_irods import version
from npg_irods.utilities import (
withdraw_consent,
)
-from npg_irods.version import version
description = """
Reads iRODS data object paths from a file or STDIN, one per line and ensures that each
@@ -77,7 +77,7 @@
action="store_true",
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
@@ -93,10 +93,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
num_processed, num_withdrawn, num_errors = withdraw_consent(
args.input,
args.output,
diff --git a/src/npg_irods/cli/write_html_report.py b/src/npg_irods/cli/write_html_report.py
index bf6c494..b661436 100644
--- a/src/npg_irods/cli/write_html_report.py
+++ b/src/npg_irods/cli/write_html_report.py
@@ -26,8 +26,8 @@
from partisan.exception import RodsError
from yattag import indent
+from npg_irods import version
from npg_irods.html_reports import ont_runs_html_report_this_year
-from npg_irods.version import version
description = """Writes an HTML report summarising data in iRODS.
@@ -69,7 +69,7 @@
type=str,
)
parser.add_argument(
- "--version", help="Print the version and exit.", action="store_true"
+ "--version", help="Print the version and exit.", action="version", version=version()
)
args = parser.parse_args()
@@ -84,10 +84,6 @@
def main():
- if args.version:
- print(version())
- sys.exit(0)
-
report = args.report[0]
try:
diff --git a/src/npg_irods/ont.py b/src/npg_irods/ont.py
index 33d60dd..cfd55c1 100644
--- a/src/npg_irods/ont.py
+++ b/src/npg_irods/ont.py
@@ -451,17 +451,24 @@ def find_run_collections(
args = []
if zone is not None:
args.extend(["-z", shlex.quote(zone)])
- args.append("%s/%s")
+ args.append("%s")
query = (
"select COLL_NAME where "
f"META_COLL_ATTR_NAME = '{Instrument.EXPERIMENT_NAME}' and "
f"META_COLL_ATTR_NAME = '{Instrument.INSTRUMENT_SLOT}' and "
- f"COLL_CREATE_TIME >= '{int(since.timestamp()) :>011}' amd "
+ f"COLL_CREATE_TIME >= '{int(since.timestamp()) :>011}' and "
f"COLL_CREATE_TIME <= '{int(until.timestamp()) :>011}'"
)
- return [Collection(p) for p in iquest(*args, query).splitlines()]
+ # iquest mixes logging and data in its output
+ ignore = f"Zone is {zone}" if zone is not None else "Zone is"
+
+ return [
+ Collection(p)
+ for p in iquest(*args, query).splitlines()
+ if not p.strip().startswith(ignore)
+ ]
def tag_index_from_id(tag_identifier: str) -> int:
diff --git a/src/npg_irods/utilities.py b/src/npg_irods/utilities.py
index 08ac139..53f222e 100644
--- a/src/npg_irods/utilities.py
+++ b/src/npg_irods/utilities.py
@@ -43,7 +43,7 @@
from sqlalchemy.exc import SQLAlchemyError
from structlog import get_logger
-from npg_irods import common, illumina, ont, pacbio
+from npg_irods import common, illumina, ont, pacbio, version
from npg_irods.common import (
AnalysisType,
Platform,
@@ -74,7 +74,6 @@
has_consent_withdrawn_metadata,
has_consent_withdrawn_permissions,
)
-from npg_irods.version import version
log = get_logger(__name__)
diff --git a/src/npg_irods/version.py b/src/npg_irods/version.py
deleted file mode 100644
index 691d7a8..0000000
--- a/src/npg_irods/version.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright © 2022 Genome Research Ltd. All rights reserved.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-#
-# @author Keith James
-
-import importlib.metadata
-
-__version__ = importlib.metadata.version("npg-irods-python")
-
-
-def version() -> str:
- """Return the current version."""
- return __version__