-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add CLI #59
Merged
Merged
feat: add CLI #59
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.. _cli-reference: | ||
|
||
Command-line interface | ||
---------------------- | ||
|
||
Some ``wags-tails`` functions are executable via a provided command-line interface, | ||
enabling usage from non-Python environments or for general data management purposes. | ||
|
||
.. note:: | ||
|
||
Currently, the CLI routes data requests through the explicitly defined source modules within ``wags-tails``. This means that the CLI cannot be used to manage custom sources. | ||
|
||
.. click:: wags_tails.cli:cli | ||
:prog: wags_tails | ||
:nested: full |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
wags_tails.moa | ||
============== | ||
|
||
.. automodule:: wags_tails.moa | ||
:members: | ||
:undoc-members: | ||
:special-members: __init__ | ||
:inherited-members: | ||
:exclude-members: model_fields, model_config, count, index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"""Provide a CLI application for accessing basic wags-tails functions.""" | ||
|
||
import inspect | ||
import logging | ||
|
||
import click | ||
|
||
import wags_tails | ||
from wags_tails.utils.storage import get_data_dir | ||
|
||
|
||
def _configure_logs(log_level: int = logging.INFO) -> None: | ||
"""Configure logging. | ||
|
||
:param log_level: global log level to set | ||
""" | ||
logging.basicConfig( | ||
filename="wags_tails.log", | ||
format="[%(asctime)s] - %(name)s - %(levelname)s : %(message)s", | ||
) | ||
logger = logging.getLogger(__package__) | ||
logger.setLevel(log_level) | ||
|
||
|
||
@click.group() | ||
def cli() -> None: | ||
"""Manage data files from genomics databases and knowledge sources.""" | ||
_configure_logs() | ||
|
||
|
||
@cli.command() | ||
def path() -> None: | ||
"""Get path to wags-tails storage directory given current environment configuration.""" | ||
click.echo(get_data_dir()) | ||
|
||
|
||
_DATA_SOURCES = { | ||
obj._src_name: obj # noqa: SLF001 | ||
for _, obj in inspect.getmembers(wags_tails, inspect.isclass) | ||
if obj.__name__ not in {"CustomData", "DataSource", "RemoteDataError"} | ||
} | ||
|
||
|
||
@cli.command | ||
@click.argument("data", nargs=1, type=click.Choice(list(_DATA_SOURCES.keys()))) | ||
@click.option( | ||
"--silent", | ||
"-s", | ||
is_flag=True, | ||
default=False, | ||
help="Suppress intermediary printing to stdout.", | ||
) | ||
@click.option( | ||
"--from_local", | ||
is_flag=True, | ||
default=False, | ||
help="Use latest available local file.", | ||
) | ||
@click.option( | ||
"--force_refresh", | ||
is_flag=True, | ||
default=False, | ||
help="Retrieve data from source regardless of local availability.", | ||
) | ||
def get_latest(data: str, silent: bool, from_local: bool, force_refresh: bool) -> None: | ||
"""Get latest version of specified data. | ||
|
||
For example, to retrieve the latest Disease Ontology release: | ||
|
||
% wags-tails get-version do | ||
|
||
Unless --from_local is declared, wags-tails will first make an API call | ||
against the resource to determine the most recent release version, and then either | ||
provide a local copy if already available, or first download from the data origin | ||
and then return a link. | ||
|
||
The --help option for this command will display all legal inputs for DATA; alternatively, | ||
use the list-sources command to show them in a computable (line-delimited) format. | ||
""" | ||
data_class = _DATA_SOURCES[data] | ||
result, _ = data_class(silent=silent).get_latest(from_local, force_refresh) | ||
click.echo(result) | ||
|
||
|
||
@cli.command | ||
def list_sources() -> None: | ||
"""List supported sources.""" | ||
for source in _DATA_SOURCES: | ||
click.echo(source) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should param/return be included in docstrings for modules in docs?
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 haven't been bothering too much with these dev-only methods (and tbh, we are more aggressive than almost everyone in requiring them in private methods in runnable code). We could maybe discuss in a future dev meeting?