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

refactor: move arg parser to separate file #93

Merged
merged 2 commits into from
Dec 15, 2020
Merged

refactor: move arg parser to separate file #93

merged 2 commits into from
Dec 15, 2020

Conversation

jenhagg
Copy link
Collaborator

@jenhagg jenhagg commented Dec 14, 2020

Purpose

Separate the args definition so it's a bit easier to read call.py. This may also enable some testing but I haven't explicitly done that here.

What it does

Wrap the arg parser into a function and remove the contents of __init__.py since I'm pretty sure we don't need them, plus it's out of date anyway.

Time to review

3 min - I tested by running python pyreisejl/utility/call.py with --help and 1234 (scenario id) arguments so think this is safe.

@jenhagg jenhagg self-assigned this Dec 14, 2020
@jenhagg jenhagg added this to the Hello Darkness My Old Friend milestone Dec 14, 2020
@rouille
Copy link
Collaborator

rouille commented Dec 14, 2020

I like the idea, I think too it is more readable.

Comment on lines 11 to 12
help="The start date for the simulation in format 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. "
"'YYYY-MM-DD HH:MM', or 'YYYY-MM-DD HH:MM:SS'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is somewhat unrelated, but while we're modifying this code let's turn some of these periods into commas where they appear to be part of a list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

parser.add_argument(
"-e",
"--end-date",
help="The end date for the simulation in format 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. "
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: periods -> commas.

default=None,
help="Scenario ID only if using PowerSimData. ",
)

args = parser.parse_args()
Copy link
Contributor

Choose a reason for hiding this comment

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

The way you kept this line is clever.

"has finished running will be automatically extracted into .pkl files, "
"and the result.mat files will be deleted. "
"The extraction process can be memory intensive. "
"This is optional and defaults to False.",
Copy link
Contributor

Choose a reason for hiding this comment

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

In #88 , I updated this description to defaults to False if the flag is omitted to be a little clearer. We can probably propagate this change here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks

import argparse


def parse_args():
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be parse_call_args? I'm assuming there will be a followup PR for extract_data which will need a different argument parsing function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I'll probably have to tweak it a bit, but might end up wrapping these in a class, e.g. from parser import CallParser then doing CallParser.parse_args() so think I will hold off until then if that sounds good.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why a class instead of a function? Is there anything stateful we need to keep track of?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would be a static method, using the class as more of a namespace than a state holder. Main reason is to have a consistent parse_args() method/function for both use cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems like an unnecessary layer over the existing namespace of parser.py. CallParser.parse_args() will already have to be different than ExtractParser.parse_args(), I think parse_call_args() and parse_extract_args() is cleaner.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe it's just personal preference, it seems more intuitive to me to have {kind of parser}.parse_args()than parse_{kind}_args(). But whichever way we end up going I think we can defer this decision?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do see the point about parser.py being the namespace, and it supporting multiple parsers via different functions, so I'm not entirely opposed to that either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Six one way, half a dozen the other. If I was reading this fresh, I would assume that there was more to the class than a single method, and be confused when I went looking. But I'm happy to follow whichever option is more popular. @ahurli do you want to cast a tie-breaker vote?

I would rather get the extract arg parsing (in one form or another) into this PR, so that we're not merging this and then immediately starting a parser.py refactor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm happy to go with the popular option, which I'll tentatively assume is the function based approach that Anna originally suggested.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how much more complicated we're expecting this to get, so I assume just the function naming convention should be sufficient for now.

But I totally understand waiting for the next PR to implement anything as it's not strictly necessary for this one.

Comment on lines 96 to 97
help="The start date as provided to run the simulation. Supported formats are"
" 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. 'YYYY-MM-DD HH:MM', or 'YYYY-MM-DD HH:MM:SS'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's get these periods to commas too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Combined with the most recent commit

Comment on lines 102 to 103
help="The end date as provided to run the simulation. Supported formats are"
" 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. 'YYYY-MM-DD HH:MM', or 'YYYY-MM-DD HH:MM:SS'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Periods to commas.

Copy link
Contributor

@ahurli ahurli left a comment

Choose a reason for hiding this comment

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

Thanks!

@jenhagg jenhagg merged commit 4124036 into develop Dec 15, 2020
@jenhagg jenhagg deleted the jon/parser branch December 15, 2020 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants