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

changes in verdi restapi command (#2384) #2853

Merged
merged 1 commit into from
May 9, 2019

Conversation

waychal
Copy link
Contributor

@waychal 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

@waychal waychal requested a review from sphuber May 8, 2019 12:07
Copy link
Contributor

@sphuber sphuber left a 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')
Copy link
Contributor

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.

else:
aiida_profile = "default"
catch_internal_server = kwargs['catch_internal_server']
debug = kwargs["debug"]
Copy link
Contributor

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

Copy link
Contributor Author

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')
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


else:
aiida_profile = "default"
catch_internal_server = kwargs['catch_internal_server']
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

elif confs.DEFAULT_AIIDA_PROFILE is not None:
aiida_profile = confs.DEFAULT_AIIDA_PROFILE
# Unpack parameters
default_host = kwargs['default_host']
Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@waychal waychal force-pushed the restapi_cmdline branch 2 times, most recently from a98bb1e to d87b35e Compare May 8, 2019 14:17
@coveralls
Copy link

coveralls commented May 8, 2019

Coverage Status

Coverage increased (+0.2%) to 72.731% when pulling 16e4020 on waychal:restapi_cmdline into 8836a8f on aiidateam:develop.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 72.653% when pulling d87b35e0c85d72f1a8bfd280df20046efa87962e on waychal:restapi_cmdline into af9fba3 on aiidateam:develop.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 72.653% when pulling d87b35e0c85d72f1a8bfd280df20046efa87962e on waychal:restapi_cmdline into af9fba3 on aiidateam:develop.

@waychal
Copy link
Contributor Author

waychal commented May 8, 2019

@sphuber I have made the requested changes.

Copy link
Contributor

@sphuber sphuber left a 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')
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

# Unpack parameters
hostname = kwargs['hostname']
port = kwargs['port']
default_config_dir = kwargs['default_config']
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@waychal waychal force-pushed the restapi_cmdline branch 2 times, most recently from d662f3f to a438b50 Compare May 9, 2019 09:02
@sphuber
Copy link
Contributor

sphuber commented May 9, 2019

Only your pre-commit is failing. Make sure you have updated your dependencies: pip install -e .[dev_precommit] --upgrade. If you fix those and push, I will approve. Thanks!

- 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
@waychal waychal force-pushed the restapi_cmdline branch from a438b50 to 16e4020 Compare May 9, 2019 13:34
@sphuber sphuber merged commit e9650cc into aiidateam:develop May 9, 2019
@sphuber
Copy link
Contributor

sphuber commented May 9, 2019

Excellent! Thanks a lot @waychal

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.

3 participants