From 1bd7ad3a48017ed44fd1fe8e465ec3870574725d Mon Sep 17 00:00:00 2001 From: awicenec Date: Tue, 2 Jul 2024 14:47:03 +0800 Subject: [PATCH] Apply suggestions from code review Most of Sourcery-ai suggested changes accepted. Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- daliuge-engine/dlg/deploy/configs/__init__.py | 6 +++++- daliuge-engine/dlg/deploy/create_dlg_job.py | 11 ++++++++--- daliuge-engine/dlg/deploy/slurm_client.py | 2 +- daliuge-engine/test/manager/test_dim.py | 5 ++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/daliuge-engine/dlg/deploy/configs/__init__.py b/daliuge-engine/dlg/deploy/configs/__init__.py index 00e901be..948adbf9 100644 --- a/daliuge-engine/dlg/deploy/configs/__init__.py +++ b/daliuge-engine/dlg/deploy/configs/__init__.py @@ -39,7 +39,11 @@ class DefaultConfig(object): - ACCOUNT = "" +class DefaultConfig(object): + def __init__(self, account): + self.ACCOUNT = account + HOME_DIR = os.environ["HOME"] if "HOME" in os.environ else "" + DLG_ROOT = f"{HOME_DIR}/dlg" HOME_DIR = os.environ["HOME"] if "HOME" in os.environ else "" DLG_ROOT = f"{HOME_DIR}/dlg" LOG_DIR = f"{DLG_ROOT}/log" diff --git a/daliuge-engine/dlg/deploy/create_dlg_job.py b/daliuge-engine/dlg/deploy/create_dlg_job.py index cd868d67..c1609d2a 100644 --- a/daliuge-engine/dlg/deploy/create_dlg_job.py +++ b/daliuge-engine/dlg/deploy/create_dlg_job.py @@ -62,7 +62,9 @@ def get_timestamp(line): date_time = "{0}T{1}".format(split[0], split[1]) pattern = "%Y-%m-%dT%H:%M:%S,%f" epoch = time.mktime(time.strptime(date_time, pattern)) - return datetime.datetime.strptime(date_time, pattern).microsecond / 1e6 + epoch + parsed_date = datetime.datetime.strptime(date_time, pattern) + microseconds = parsed_date.microsecond / 1e6 + return microseconds + epoch class LogEntryPair: @@ -610,7 +612,10 @@ def main(): ) (opts, _) = parser.parse_args(sys.argv) - if opts.configs: +(opts, _) = parser.parse_args(sys.argv) +if opts.configs: + print(f"Available facilities: {FACILITIES}") + sys.exit(1) print(f"Available facilities: {FACILITIES}") sys.exit(1) if not (opts.action and opts.facility) and not opts.configs: @@ -654,7 +659,7 @@ def main(): elif opts.physical_graph: path_to_graph_file = opts.physical_graph if path_to_graph_file and not os.path.exists(path_to_graph_file): - parser.error("Cannot locate graph file at '{0}'".format(path_to_graph_file)) + parser.error(f"Cannot locate graph file at '{path_to_graph_file}'") else: graph_name = os.path.basename(path_to_graph_file) with open(path_to_graph_file) as f: diff --git a/daliuge-engine/dlg/deploy/slurm_client.py b/daliuge-engine/dlg/deploy/slurm_client.py index 6c21faa8..2ab839c9 100644 --- a/daliuge-engine/dlg/deploy/slurm_client.py +++ b/daliuge-engine/dlg/deploy/slurm_client.py @@ -104,7 +104,7 @@ def __init__( self._submit = submit self._dtstr = datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S") # .%f ni, nn, self._pip_name = find_numislands(self._physical_graph_template_data) - if ni and ni >= self._num_islands: + if isinstance(ni, int) and ni >= self._num_islands: self._num_islands = ni if nn and nn >= self._num_nodes: self._num_nodes = nn diff --git a/daliuge-engine/test/manager/test_dim.py b/daliuge-engine/test/manager/test_dim.py index 38cd71fd..5984d055 100644 --- a/daliuge-engine/test/manager/test_dim.py +++ b/daliuge-engine/test/manager/test_dim.py @@ -72,7 +72,10 @@ def setUp(self): super(LocalDimStarter, self).setUp() self.nm_info = self.start_nm_in_thread() self.dm = self.nm_info.manager - self.dim = DataIslandManager([f"{nm_host}"]) +def test_invalid_host_format(self): + invalid_host = "invalid_host_format" + with self.assertRaises(ValueError): + DataIslandManager([f"{invalid_host}"]) def tearDown(self): self.nm_info.stop()