-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
CLI dispatch mechanism #108
Conversation
I haven't tested the _split_target_list function in StatusCommand, 'cause I don't know how to muck up a test of target status checking right now.
@@ -23,7 +23,7 @@ lint: | |||
flake8 | |||
|
|||
coverage: | |||
coverage report | |||
coverage report --omit gwf/cli/__main__.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be specified in the configuration file .coveragerc
instead.
@@ -1,117 +1,212 @@ | |||
from __future__ import absolute_import | |||
from __future__ import print_function | |||
from __future__ import absolute_import, print_function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only support Python 3.4+, so we don't need imports from __future__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but that is actually your commit and not mine ;)
@@ -0,0 +1 @@ | |||
from __future__ import absolute_import, print_function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary import. See comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -0,0 +1,26 @@ | |||
from __future__ import absolute_import, print_function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file should be called entrypoint.py
to make it clear that this is the entry point of the program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
import argparse | ||
|
||
|
||
class SubCommand(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just Command
is better than SubCommand
. Otherwise RunCommand
should be called RunSubCommand
, but that's just ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python 3 has new-style classes by default, so there's no reason to inherit from object
explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
I don't know why there's a lot of changes to the SLURM backend included in this PR. Is it possible to remove again, maybe my merging master into the branch again?
Some general comments:
- Order imports according to PEP8 (this is done automatically if you use Atom with the atom-beautify plugin).
- Remove spacing around
=
. The above mentioned plugin takes care of that too. - Don't import from
__future__
.
from __future__ import absolute_import, print_function | ||
from ..utils import cache, import_object | ||
from ..core import PreparedWorkflow | ||
import argparse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if the file was just called parsing.py
to be consistent with PEP8 recommendations about not using underscores in module names. It's also prettier.
Order imports alphabetically with stdlib imports first, then third-party imports, then package imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the name of the file and order of imporots.
@property | ||
@cache | ||
def workflow(cls): | ||
if cls._workflow is None: # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you write, no reason to check this. We'll make sure to always set the workflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the check
def handle(self, arguments): | ||
"Callback when this sub-command is invoked." | ||
|
||
class ArgumentDispatching(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't inherit from object
.
I think this should just be called Dispatcher
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have a problem with inheriting from object? in 2.7 it is the way to use the new class system and it doesn't look like it is doing any damage in 3.5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it's just unnecessary :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Will remove it then
|
||
def __init__(self): | ||
self.parser = argparse.ArgumentParser( | ||
description="Grid WorkFlow", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use the same description as in the docs: "A flexible, pragmatic workflow tool."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
# Set global options here. Options for sub-commands will be set by the | ||
# sub-commands we dispatch to. | ||
self.parser.add_argument("-w", "--workflow", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backward compatibility I think the flag should be -f
and --file
. No reason to confuse users unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok :(
self.subparsers = self.parser.add_subparsers(title = "commands", description = "Subcommands to execute") | ||
|
||
def install_subcommand(self, name, description, handler): | ||
"""Install a sub-command with "name" and with functionality implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird wrapping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird how?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my mistake. That was my editor wrapping it :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
default = "workflow.py") | ||
|
||
# Prepare for sub-commands | ||
self.subparsers = self.parser.add_subparsers(title = "commands", description = "Subcommands to execute") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
from math import ceil | ||
|
||
|
||
__doc__ = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc string should just go to the top of the module (then it will be automatically assigned to __doc__
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -13,6 +13,16 @@ def __init__(self, target): | |||
|
|||
super(TargetExistsError, self).__init__(message) | |||
|
|||
class TargetDoesNotExistsError(GWFError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar: Exists -> Exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
test_suite='tests', | ||
install_requires=[ | ||
"colorama", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify a minimum version with >=major.minor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah. I don't know which minimal version to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most recent one right now: 0.3.7 ;)
# Conflicts: # setup.py
The unit tests are failing now but it is in the code that prepares the workflow, so I think the problem is with the code I merged in from the master branch which I haven't checked how is changed. @dansondergaard, can you see why there is a key error in a dictionary lookup in the workflow preparation now?
Design for a CLI interface based on installing subcommands and callbacks.
For each subcommand you write a class with two hooks: one for setting sub-command arguments and the other to be called if the sub-command is invoked.