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

Consolidate parsing into common_functions #211

Merged
merged 1 commit into from
Oct 11, 2019
Merged

Conversation

gerritdm
Copy link
Contributor

@gerritdm gerritdm commented Oct 8, 2019

I ran into some of these parsing issues again when dealing with the
plots so I went ahead and tried to address some of the issues raised
in #111 (e.g. we're still ignoring unknown arguments in the sub-scripts
called in run_end_to_end.py).

This PR re-factors the adding of parsed arguments into a set
of functions that add related arguments. Each script can then simply
use some of these function as parent parsers when setting up the
ArgumentParser for that script.

Note: there are still some issues with how arguments are passed through
from run_end_to_end to the other scripts. For instance, the scenario
name is required for run_scenario.py but in theory not for
run_end_to_end.py. However, run_end_to_end.py calls run_scenario.py, so
you will get an error message if you don't provide it in
run_end_to_end.py and the error message will be a somewhat confusing
combination of run_end_to_end.py and run_scenario.py

One solution could be to get rid of scenario_id and make scenario a
required argument. The value can be either the ID or the name, and we
can add some functionality to smartly determine what is provided and
get the equivalent name/id from the db (if needed).

This commit re-factors the adding of parsed arguments into a set
of functions that add related arguments. Each script can then simply
use some of these function as parent parsers when setting up the
ArgumentParser for that script.

Note: there are still some issues with how arguments are passed through
from run_end_to_end to the other scripts. For instance, the scenario
name is required for run_scenario.py but in theory not for
run_end_to_end.py. However, run_end_to_end.py calls run_scenario.py, so
you will get an error message if you don't provide it in
run_end_to_end.py and the error message will be a somewhat confusing
combination of run_end_to_end.py and run_scenario.py

One solution could be to get rid of scenario_id and make scenario a
required argument. The value can be either the ID or the name, and we
can add some functionality to smartly determine what is provided and
get the equivalent name/id from the db (if needed).
@gerritdm gerritdm added the type: refactor code clean-up label Oct 8, 2019
@gerritdm
Copy link
Contributor Author

gerritdm commented Oct 8, 2019

2 things that we might want to address in this PR as well:

  • remove reverting to a hard-coded default scenario_location in gridpath.common_functions.determine_scenario_directory() and simply use the default value from the argument parser. We might want to get rid of the function entirely and simply call os.path.join(scenario_location, scenario) whenever needed.
  • similarly for the database, I think it might be more clear to add the default db_path to the argument parser definition, rather than assigning it in db.common_functions.connect_to_database.

Copy link
Member

@anamileva anamileva left a comment

Choose a reason for hiding this comment

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

Looks good.

@gerritdm gerritdm merged commit 38b3c21 into master Oct 11, 2019
@gerritdm gerritdm deleted the improve_arg_parsing branch October 11, 2019 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor code clean-up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants