-
Notifications
You must be signed in to change notification settings - Fork 191
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
changes in verdi restapi command (#2384) #2853
Conversation
waychal
commented
May 8, 2019
- updated verdi restapi command and its click parameters
- removed load_profile functionality from restapi code as it is already handled by verdi command
- removed __main__ from restapi code as it is duplicating the functionality provided by 'verdi restapi' command
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.
Thanks @waychal some minor comments
@@ -26,33 +26,44 @@ | |||
|
|||
|
|||
@verdi.command('restapi') | |||
@click.option('-H', '--host', type=click.STRING, default='127.0.0.1', help='the hostname to use') | |||
@click.option('-h', '--host', type=click.STRING, default='127.0.0.1', help='the hostname 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.
This will be problematic, because -h
is already as the short option for the --help
flag, which is automatically added by verdi
itself. The predefined overridable options in aiida.cmdline.params.options
already define an option for the hostname and port. Please use those, so that the same flags will be used all across verdi
.
aiida/restapi/run_api.py
Outdated
else: | ||
aiida_profile = "default" | ||
catch_internal_server = kwargs['catch_internal_server'] | ||
debug = kwargs["debug"] |
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.
Please use single quotes for string literal identifiers
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
type=click.BOOL, | ||
default=False, | ||
help='to use WSGI profiler middleware for finding bottlenecks in web application') | ||
@click.option('--hookup', type=click.BOOL, default=True, help='to hookup app') |
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 flag-like options, you should use click.option('--hookup', is_flag=True, default=False)
. A user then only has to specify --hookup
without the boolean value. If the flag needs to be on by default and needs to be turned off, you can use click.option('--hookup/--no-hookup', 'hookup', is_flag=True, default=True)
. This also applies to --wsgi-profile
and --debug
.
If the flag is off by default and should just be passed to turn it on, like in the case of --debug
, you only want to specify the on flag and do not use the double flag version.
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
""" | ||
Run the AiiDA REST API server | ||
|
||
Example Usage: | ||
|
||
\b | ||
verdi -p <profile_name> restapi --host 127.0.0.5 --port 6789 --config-dir <location of the config.py file> | ||
--debug True --wsgi-profile False --hookup True |
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 forget to update this after you have changed the options
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
aiida/restapi/run_api.py
Outdated
|
||
else: | ||
aiida_profile = "default" | ||
catch_internal_server = kwargs['catch_internal_server'] |
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.
Probably want to use something like kwargs.pop('catch_internal_server', False)
to avoid KeyError
if the keyword is not passed in. Here False
should then be the default value you want 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.
Done
aiida/restapi/run_api.py
Outdated
elif confs.DEFAULT_AIIDA_PROFILE is not None: | ||
aiida_profile = confs.DEFAULT_AIIDA_PROFILE | ||
# Unpack parameters | ||
default_host = kwargs['default_host'] |
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 are these called default
? They are simply the host and port that the user wants to use, no?
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
prog_name='verdi-restapi', | ||
default_host=host, | ||
default_port=port, | ||
default_config=config_dir, | ||
debug=debug, | ||
wsgi_profile=wsgi_profile, | ||
hookup=hookup, |
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 see that parse_aiida_profile
is still being passed, but I don't think it is being used in the run_api
function. If true, please remove 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.
Done
a98bb1e
to
d87b35e
Compare
Coverage increased (+0.2%) to 72.653% when pulling d87b35e0c85d72f1a8bfd280df20046efa87962e on waychal:restapi_cmdline into af9fba3 on aiidateam:develop. |
1 similar comment
Coverage increased (+0.2%) to 72.653% when pulling d87b35e0c85d72f1a8bfd280df20046efa87962e on waychal:restapi_cmdline into af9fba3 on aiidateam:develop. |
@sphuber I have made the requested changes. |
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.
You missed a few changes
@@ -26,34 +26,44 @@ | |||
|
|||
|
|||
@verdi.command('restapi') | |||
@click.option('-H', '--host', type=click.STRING, default='127.0.0.1', help='the hostname to use') | |||
@click.option('-p', '--port', type=click.INT, default=5000, help='the port to use') | |||
@click.option('-H', '--hostname', type=click.STRING, default='127.0.0.1', help='Hostname') |
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.
please use the predefined aiida.cmdline.params.options.HOSTNAME
and aiida.cmdline.params.options.PORT
for these. Note you can override the default when you call it. See other verdi commands for examples
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 have made changes for this but I am not sure if it is correct. Please let me know if I am missing anything again.
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.
nope, all good 👍
default_host=host, | ||
default_port=port, | ||
hostname=hostname, | ||
port=port, |
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 same goes for the default_config
no? As in, this should just be config
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.
Corrected.
aiida/restapi/run_api.py
Outdated
# Unpack parameters | ||
hostname = kwargs['hostname'] | ||
port = kwargs['port'] | ||
default_config_dir = kwargs['default_config'] |
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.
Same here
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
d662f3f
to
a438b50
Compare
Only your pre-commit is failing. Make sure you have updated your dependencies: |
- updated verdi restapi command and its click parameters - removed load_profile functionality from restapi code as it is already handled by verdi command - removed __main__ from restapi code as it is duplicating the functionality provided by 'verdi restapi' command
Excellent! Thanks a lot @waychal |