From f2243541b2963272c6edd444ebe890f7e70f9d33 Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Mon, 7 Aug 2023 15:03:24 +0200 Subject: [PATCH 1/4] __init__.py: added comments for categories of imports --- tools/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/__init__.py b/tools/__init__.py index 50471591..65e485e7 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -12,9 +12,12 @@ # # license: GPLv2 # + +# Standard library imports import os import subprocess +# Third party imports (anything installed into the local Python environment) from pyghee.utils import log From 7c67e1e10166244f7f4c7579389e4a6868cd2060 Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Mon, 7 Aug 2023 15:10:22 +0200 Subject: [PATCH 2/4] __init__.py: minor improvements of docstrings --- tools/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/__init__.py b/tools/__init__.py index 65e485e7..8dd541f5 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -22,14 +22,15 @@ def run_cmd(cmd, log_msg='', working_dir=None, log_file=None, raise_on_error=True): - """Runs a command in the shell, raising an error if one occurs. + """ + Runs a command in the shell and raises an error if one occurs. Args: cmd (string): command to run - log_msg (string): purpose of the command - working_dir (string): location of arch_job_dir + log_msg (string): message describing the purpose of the command + working_dir (string): location of the job's working directory log_file (string): path to log file - raise_on_error (bool): raise an exception in case of error + raise_on_error (bool): if True raise an exception in case of error Returns: tuple of 3 elements containing @@ -37,7 +38,6 @@ def run_cmd(cmd, log_msg='', working_dir=None, log_file=None, raise_on_error=Tru - stderr (string): stderr of the process - exit_code (string): exit code of the process """ - stdout, stderr, exit_code = run_subprocess(cmd, log_msg, working_dir, log_file) if exit_code != 0: @@ -60,12 +60,13 @@ def run_cmd(cmd, log_msg='', working_dir=None, log_file=None, raise_on_error=Tru def run_subprocess(cmd, log_msg, working_dir, log_file): - """Runs a command in the shell. No error is raised if the command fails, the exit code is returned in all scenarios. + """ + Runs a command in the shell. No error is raised if the command fails. Args: cmd (string): command to run log_msg (string): purpose of the command - working_dir (string): location of arch_job_dir + working_dir (string): location of the job's working directory log_file (string): path to log file Returns: @@ -74,7 +75,6 @@ def run_subprocess(cmd, log_msg, working_dir, log_file): - stderr (string): stderr of the process - exit_code (string): exit code of the process """ - if working_dir is None: working_dir = os.getcwd() From 24aa9c08817e7adf4739d11dfedbb4c9e2014af3 Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Mon, 7 Aug 2023 15:13:44 +0200 Subject: [PATCH 3/4] __init__.py: added TODO comments for future improvements --- tools/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/__init__.py b/tools/__init__.py index 8dd541f5..def3c2f7 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -21,6 +21,8 @@ from pyghee.utils import log +# TODO do we really need two functions (run_cmd and run_subprocess) for +# running a command? def run_cmd(cmd, log_msg='', working_dir=None, log_file=None, raise_on_error=True): """ Runs a command in the shell and raises an error if one occurs. @@ -38,6 +40,7 @@ def run_cmd(cmd, log_msg='', working_dir=None, log_file=None, raise_on_error=Tru - stderr (string): stderr of the process - exit_code (string): exit code of the process """ + # TODO use common method for logging function name in log messages stdout, stderr, exit_code = run_subprocess(cmd, log_msg, working_dir, log_file) if exit_code != 0: @@ -75,6 +78,7 @@ def run_subprocess(cmd, log_msg, working_dir, log_file): - stderr (string): stderr of the process - exit_code (string): exit code of the process """ + # TODO use common method for logging function name in log messages if working_dir is None: working_dir = os.getcwd() From 62bf050cb5d005b8e0768f5ccb621d94262beed6 Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Mon, 7 Aug 2023 15:15:46 +0200 Subject: [PATCH 4/4] __init__.py: added Raises section to docstring --- tools/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/__init__.py b/tools/__init__.py index def3c2f7..e064db6e 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -39,6 +39,10 @@ def run_cmd(cmd, log_msg='', working_dir=None, log_file=None, raise_on_error=Tru - stdout (string): stdout of the process - stderr (string): stderr of the process - exit_code (string): exit code of the process + + Raises: + RuntimeError: raises a RuntimeError if exit code was not zero and + raise_on_error is True """ # TODO use common method for logging function name in log messages stdout, stderr, exit_code = run_subprocess(cmd, log_msg, working_dir, log_file)