Skip to content

Add a set of click based cli utilities to simplify writing launch scripts#1194

Merged
sphuber merged 1 commit into
aiidateam:workflowsfrom
sphuber:fix_1193_click_cli_utils
Feb 27, 2018
Merged

Add a set of click based cli utilities to simplify writing launch scripts#1194
sphuber merged 1 commit into
aiidateam:workflowsfrom
sphuber:fix_1193_click_cli_utils

Conversation

@sphuber
Copy link
Copy Markdown
Contributor

@sphuber sphuber commented Feb 27, 2018

Fixes #1193

Note: I know Rico has been working on porting verdi to click at which point part of this may be tackled, but until that time I really need this functionality in different plugins that is currently included in aiida-quantumespresso.

These utilities simplify the writing of command line interface scripts
that are very useful for plugin developers to write launch scripts with
minimal effort. It provides a decorator @command that will turn a
function into a click command that automatically loads the database
environment. It also provides various other @option like decorators
which predefine commonly used input arguments and their validators for
AiiDA types such as Code, StructureData and Calculation. For
example a minimal script that will take a structure data id and print
its cell would look like:

# -*- coding: utf-8 -*-
import click
from aiida.utils.cli import command
from aiida.utils.cli import options

@options.structure()
def launch(structure):
	click.echo(structure.cell)

giovannipizzi
giovannipizzi previously approved these changes Feb 27, 2018
Copy link
Copy Markdown
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

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

Awesome! Could you add some documentation for developers (form the PR message) and convert at least one command to this format, so we have an example of how it works?

@sphuber
Copy link
Copy Markdown
Contributor Author

sphuber commented Feb 27, 2018

I explicitly did not add documentation here, because I wasn't sure whether this would stay in in this form for a long time, given that Rico would be porting the verdi stuff and he might do it differently. Adding docs now, sort of guarantees that it is going to be supported like this for a while. But if you think that is fine, than I will gladly add some documentation.

…ipts

These utilities simplify the writing of command line interface scripts
that are very useful for plugin developers to write launch scripts with
minimal effort. It provides a decorator `@command` that will turn a
function into a click command that automatically loads the database
environment. It also provides various other `@option` like decorators
which predefine commonly used input arguments and their validators for
AiiDA types such as `Code`, `StructureData` and `Calculation`. For
example a minimal script that will take a structure data id and print
its cell would look like:

	# -*- coding: utf-8 -*-
	import click
	from aiida.utils.cli import command
	from aiida.utils.cli import options

	@options.structure()
	def launch(structure):
		click.echo(structure.cell)
@sphuber sphuber force-pushed the fix_1193_click_cli_utils branch from 69fde3b to 139848f Compare February 27, 2018 18:23
@sphuber sphuber merged commit cd6b402 into aiidateam:workflows Feb 27, 2018
@sphuber sphuber deleted the fix_1193_click_cli_utils branch February 27, 2018 18:43
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.

2 participants