Giter VIP home page Giter VIP logo

Comments (12)

sr-murthy avatar sr-murthy commented on June 12, 2024

Bugs and test coverage fixes in oasislmf (0.0.1)

from oasislmf.

sr-murthy avatar sr-murthy commented on June 12, 2024

We can discuss this week, but @OmegaDroid I think I do need some guidance on the InputValues class (oasislmf.cmd.base.InputValues). It looks as the config_dir path attribute is obtained from the parent directory of the configuration file argument (args.config), but if it is not present it causes problems as with the generate-keys subcommand.

class InputValues(object):
    """
    Helper class for accessing the input values from either
    the command line or the configuration file.
    """
    def __init__(self, args):
        self.args = args

        self.config = {}
        self.config_dir = os.path.dirname(args.config)
        if os.path.exists(args.config):
            with io.open(args.config, 'r', encoding='utf-8') as f:
                self.config = json.load(f)
...
...

You're assuming here that args.config exists, but we need to make each MDK subcommand also work if all the arguments are passed in directly without using a configuration file. In this case args.config won't exist but it is not clear what happens. Later on you use config_dir to join it with other path arguments. It is not clear.

Even with the fix I made (https://github.com/OasisLMF/OasisLMF/pull/11/files) I am getting errors when I try to generate keys without using the configuration file option but passing all the arguments directly on the command line.

(oasislmf-venv) [srm@~/Documents/sandeep/cst/dev/oasis/oasislmf]$ oasislmf model generate-keys -k ../OasisPiWind/keys_data/PiWind -v ../OasisPiWind/keys_data/PiWind/ModelVersion.csv -l ../OasisPiWind/src/keys_server -t 'list_keys' -e ../OasisPiWind/keys_data/PiWind/oasislmf_piwind_model_loc_test.csv -s piwind-keys.csv
 Output file path does not exist: /Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/keys-20180302172532
(oasislmf-venv) [srm@~/Documents/sandeep/cst/dev/oasis/oasislmf]$ oasislmf model generate-keys -k ../OasisPiWind/keys_data/PiWind -v ../OasisPiWind/keys_data/PiWind/ModelVersion.csv -l ../OasisPiWind/src/keys_server -t 'list_keys' -e ../OasisPiWind/keys_data/PiWind/oasislmf_piwind_model_loc_test.csv
usage: oasislmf model generate-keys [-h] [-V] [-C CONFIG] [-k KEYS_DATA_PATH]
                                    [-v MODEL_VERSION_FILE_PATH]
                                    [-l LOOKUP_PACKAGE_PATH]
                                    [-t {oasis_keys,list_keys}]
                                    [-e MODEL_EXPOSURES_FILE_PATH] [-s]
                                    output-file-path
oasislmf model generate-keys: error: too few arguments

from oasislmf.

sr-murthy avatar sr-murthy commented on June 12, 2024

To test this fix I uninstalled the current oasislmf package version from my virtual env., and re-installed the version from the bug-fix branch using

pip install -e git+ssh://[email protected]/OasisLMF/OasisLMF.git@bug-fix#egg=oasislmf

from oasislmf.

OmegaDroid avatar OmegaDroid commented on June 12, 2024

So there is no assumption that the config file exists, if it doesn't then we don't try to attempt to get the value from the config.

The reason you are getting the too few arguments error is that it hasn't been setup to lookup from the config file, ill add that now.

from oasislmf.

OmegaDroid avatar OmegaDroid commented on June 12, 2024

Ahh ok, looks like you've sorted it already

from oasislmf.

sr-murthy avatar sr-murthy commented on June 12, 2024

@OmegaDroid There must be for each MDK subcommand two modes of specifying all the resources: via the command line using flags, or via a configuration file.

from oasislmf.

OmegaDroid avatar OmegaDroid commented on June 12, 2024

Thats what the Input values class handles, the logic is:

  1. Is it on the cmd line
  2. Is it in the config file
  3. Is there a default value

from oasislmf.

sr-murthy avatar sr-murthy commented on June 12, 2024

@OmegaDroid It might be a good idea to add a console logging option to the MDK commands. I imagine this wouldn't be difficult to do - at the moment you just get a message saying no logger set

No handlers could be found for logger "root"

it would be more meaningful in fact for console logging to appear, as it does with the MDK scripts.

from oasislmf.

OmegaDroid avatar OmegaDroid commented on June 12, 2024

I think there should be logging put in place already but maybe its not being set on the root logger. I'll take a look.

from oasislmf.

sr-murthy avatar sr-murthy commented on June 12, 2024

Thanks

from oasislmf.

sr-murthy avatar sr-murthy commented on June 12, 2024

It would be good to rebase this branch or your fixes branch against master before merging, as master has had a number of changes lately.

from oasislmf.

sr-murthy avatar sr-murthy commented on June 12, 2024

Flag conflict in generate-keys command

(oasislmf-venv) [srm@~/Documents/sandeep/cst/dev/oasis/oasislmf]$ oasislmf model generate-keys --help
Traceback (most recent call last):
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/bin/oasislmf", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/src/oasislmf/bin/oasislmf", line 7, in <module>
    sys.exit(RootCmd().run())
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/src/oasislmf/oasislmf/cmd/root.py", line 36, in run
    return super(OasisBaseCommand, self).run(args=args)
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/lib/python2.7/site-packages/argparsetree/cmd.py", line 153, in run
    args = args or self.parse_args()
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/src/oasislmf/oasislmf/cmd/base.py", line 117, in parse_args
    self.args = super(OasisBaseCommand, self).parse_args()
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/lib/python2.7/site-packages/argparsetree/cmd.py", line 59, in parse_args
    return self.arg_parser.parse_args(self.argv)
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/lib/python2.7/site-packages/argparsetree/cmd.py", line 49, in arg_parser
    self.register_sub_commands(self._arg_parser)
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/lib/python2.7/site-packages/argparsetree/cmd.py", line 87, in register_sub_commands
    cmd.register_sub_commands(sub_parser)
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/lib/python2.7/site-packages/argparsetree/cmd.py", line 86, in register_sub_commands
    cmd.add_args(sub_parser)
  File "/Users/srm/Documents/sandeep/cst/dev/oasis/OasisLMF/oasislmf-venv/src/oasislmf/oasislmf/cmd/model.py", line 74, in add_args
    help='Keys records output file path',
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py", line 1308, in add_argument
    return self._add_action(action)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py", line 1682, in _add_action
    self._optionals._add_action(action)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py", line 1509, in _add_action
    action = super(_ArgumentGroup, self)._add_action(action)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py", line 1322, in _add_action
    self._check_conflict(action)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py", line 1460, in _check_conflict
    conflict_handler(action, confl_optionals)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py", line 1467, in _handle_conflict_error
    raise ArgumentError(action, message % conflict_string)
argparse.ArgumentError: argument -o/--oasis-files-path: conflicting option string(s): -o

from oasislmf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.