Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace SimpleOption by a ConfigArgParser wrapper class (HPC-10990) #94

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/vsc/utils/script_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import os
import sys

from configargparse import ArgParser
from copy import deepcopy

import logging
from vsc.utils import fancylogger
from vsc.utils.availability import proceed_on_ha_service
from vsc.utils.generaloption import SimpleOption
from vsc.utils.lock import lock_or_bork, release_or_bork, LOCKFILE_DIR, LOCKFILE_FILENAME_TEMPLATE
from vsc.utils.nagios import (
SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode,
Expand All @@ -58,6 +58,7 @@
MAX_RTT = 2 * MAX_DELTA + 1



def _script_name(full_name):
"""Return the script name without .py extension if any. This assumes that the script name does not contain a
dot in case of lacking an extension.
Expand Down Expand Up @@ -102,7 +103,25 @@ def _merge_options(options):
return opts


class ExtendedSimpleOption(SimpleOption):
class ConfigOption:
"""
Allow using configargparse.ArgParser instead of GeneralOption but with the same
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm quite sure that same doesn't mean what you think it means ;)
anyway, best to start with a separate named class, and start to swap it in controlled way. then we can see what features are not used.

but tbh, i fail to see the need at all. if you want to make a general option with this configargparse as backend, then go for that and do this in vsc-base.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to get rid of GeneralOption altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why you want this, but starting in this repo is not the correct place imho.
it's better to have a look what "features" of generaloption we don't want anymore, and then look for code where they are used; and then estimate the amount of work to replace it.

options-specifying syntax
"""

def __init__(self, options, config_files=None):
self.parser = ArgParser(auto_env_var_prefix='')

if config_files:
self.parser.config_file_parser(config_files)

for option, (help_str, type_, action, default_value) in options.items():
self.parser.add(f'--{option}', help=help_str, type=type_, action=action, default=default_value)

self.options = self.parser.parse_args()


class ExtendedSimpleOption(ConfigOption):
"""
Extends the SimpleOption class to allow other checks to occur at script prologue and epilogue.

Expand Down Expand Up @@ -227,6 +246,8 @@ def critical_exception_handler(self, tp, value, traceback):
self.critical(message)




class CLI:
"""
Base class to implement cli tools that require timestamps, nagios checks, etc.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
'lockfile >= 0.9.1',
'netifaces',
'jsonpickle',
'configargparse',
]

PACKAGE = {
'version': '2.2.6',
'version': '2.3.0',
'author': [ag, sdw],
'maintainer': [ag, sdw],
'excluded_pkgs_rpm': ['vsc', 'vsc.utils'], # vsc is default, vsc.utils is provided by vsc-base
Expand Down
Loading