Skip to content

Commit

Permalink
Bruno Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeltrankyl committed Jan 29, 2025
1 parent 9f45612 commit a3acd0d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
28 changes: 16 additions & 12 deletions autosubmit/autosubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from distutils.util import strtobool
from pathlib import Path
from ruamel.yaml import YAML
from typing import Dict, Set, Tuple, Union, Any
from typing import Dict, Set, Tuple, Union, Any, List, Optional

from autosubmit.database.db_common import update_experiment_descrip_version
from autosubmit.helpers.parameters import PARAMETERS
Expand Down Expand Up @@ -81,7 +81,6 @@
from pyparsing import nestedExpr
from .history.experiment_status import ExperimentStatus
from .history.experiment_history import ExperimentHistory
from typing import List
import autosubmit.history.utils as HUtils
import autosubmit.helpers.autosubmit_helper as AutosubmitHelper
import autosubmit.statistics.utils as StatisticsUtils
Expand Down Expand Up @@ -177,9 +176,14 @@ def environ_init():
os.environ['PYTHONUNBUFFERED'] = 'true'

@staticmethod
def parse_args():
def parse_args() -> Tuple[int, Optional[argparse.Namespace]]:
"""
Parse arguments given to an executable and start execution of command given
Parse arguments given to an executable and start execution of command given.
Returns a tuple with the exit code (``status``), and an optional list of
arguments for ``argparse``. The list of arguments is only ever returned
when the arguments are valid for the execution of a subcommand. Otherwise,
they will be ``None``.
"""
Autosubmit.environ_init()
try:
Expand Down Expand Up @@ -692,16 +696,16 @@ def parse_args():
args, unknown = parser.parse_known_args()
if args.version:
Log.info(Autosubmit.autosubmit_version)
return 0
if unknown or args.command is None:
return 0, None
elif unknown or args.command is None:
parser.print_help()
return 1
except SystemExit as e:
return 1
return 1, None

return 0, args
except SystemExit:
return 1, None
except BaseException as e:
raise AutosubmitCritical(
"Incorrect arguments for this command", 7011)
return args
raise AutosubmitCritical(f"Incorrect arguments for this command: {str(e)}", 7011)

@staticmethod
def run_command(args):
Expand Down
11 changes: 5 additions & 6 deletions bin/autosubmit
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.

"""Script for handling experiment monitoring"""
import argparse
import os
import sys
from typing import Optional

script_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
sys.path.append(script_dir)
Expand All @@ -33,14 +35,11 @@ from autosubmitconfigparser.config.configcommon import AutosubmitConfig # noqa:

# noinspection PyProtectedMember
def main():
args = None
args = Optional[argparse.Namespace]
try:
args = Autosubmit.parse_args()
if type(args) is not int:
return_value, args = Autosubmit.parse_args()
if args:
return_value = Autosubmit.run_command(args)
else:
return_value = args
return_value = return_value if type(return_value) is int else 0
delete_lock_file()
except BaseException as e:
delete_lock_file()
Expand Down

0 comments on commit a3acd0d

Please sign in to comment.