-
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 vlmd cli #15
Open
george42-ctds
wants to merge
6
commits into
master
Choose a base branch
from
feat/add-vlmd-cli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6cd6175
(HP-1728): Add CLI functions for extract and validate
george42-ctds 43bdc73
(HP-1728): add cli script to pyproject.toml
george42-ctds 28a5e5f
(HP-1728): update README with section for CLI
george42-ctds d401a55
(HP-1728): simplify heal_cli
george42-ctds 4c81ab8
(HP-1728): update contact email in pyproject.toml
george42-ctds 3eea528
(HP-1728): add unit tests
george42-ctds 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ In the notebooks directory there are jupyter notebooks that may be used to downl | |
|
||
These notebooks perform optimally within a HEAL Gen3 Workspace and the notebooks will be automatically installed to a user's workspace when the workspace is initiated. However, you may also use these notebooks on your local machine. | ||
|
||
### VLMD validation | ||
### VLMD extraction and validation | ||
|
||
The [VLMD validation docs](heal/vlmd/README.md) describe how to use the SDK for validating VLMD dictionaries. | ||
The [VLMD documentation](heal/vlmd/README.md) describe how to use the SDK for extracting and validating VLMD dictionaries. | ||
|
||
### Run tests | ||
|
||
|
@@ -49,3 +49,22 @@ The specification can also be listed in requirements.txt file | |
``` | ||
pip install -e git+https://github.com/uc-cdis/[email protected]#egg=heal | ||
``` | ||
|
||
### CLI | ||
|
||
The SDK exposes a Command Line Interface (CLI) for some functions. | ||
|
||
The CLI can be invoked as follows | ||
|
||
`heal [OPTIONS] COMMAND [ARGS]` | ||
|
||
For a list of commands and options run | ||
|
||
`heal --help` | ||
|
||
For example, the following can validate a VLMD file in csv format: | ||
|
||
`heal vlmd validate --input_file "vlmd_for_validation.csv"` | ||
|
||
The [VLMD documentation](heal/VLMD/README.md) provides information on | ||
using the VLMD functions, such as `extract` and `validate`. |
Empty file.
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,34 @@ | ||
import click | ||
|
||
from cdislogging import get_logger | ||
|
||
from heal.vlmd.extract.extract import vlmd_extract | ||
|
||
logging = get_logger("__name__") | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--input_file", | ||
"input_file", | ||
help="name of file to extract HEAL-compliant VLMD file", | ||
type=click.Path(writable=True), | ||
) | ||
@click.option( | ||
"--output_dir", | ||
"output_dir", | ||
help="directory to write converted dictionary'", | ||
default=".", | ||
type=click.Path(writable=True), | ||
show_default=True, | ||
) | ||
def extract(input_file, output_dir): | ||
"""Extract HEAL-compliant VLMD file from input file""" | ||
|
||
logging.info(f"Extracting VLMD from {input_file}") | ||
|
||
try: | ||
vlmd_extract(input_file, output_dir=output_dir) | ||
except Exception as e: | ||
logging.warning(str(e)) | ||
raise e |
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,31 @@ | ||
import click | ||
import logging | ||
|
||
import cdislogging | ||
import heal.cli.vlmd as vlmd | ||
|
||
|
||
@click.group() | ||
@click.option( | ||
"--silent", | ||
"silent", | ||
is_flag=True, | ||
default=False, | ||
help="don't show ANY logs", | ||
) | ||
@click.pass_context | ||
def main(ctx, silent): | ||
"""HEAL-Platform SDK Command Line Interface""" | ||
ctx.ensure_object(dict) | ||
|
||
if silent: | ||
# we still need to define the logger, the log_level here doesn't | ||
# really matter b/c we immediately disable all logging | ||
logger = cdislogging.get_logger("heal_cli", log_level="debug") | ||
# disables all logging | ||
logging.disable(logging.CRITICAL) | ||
|
||
|
||
main.add_command(vlmd.vlmd) | ||
if __name__ == "__main__": | ||
main() |
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,27 @@ | ||
import click | ||
|
||
from cdislogging import get_logger | ||
|
||
from heal.vlmd.validate.validate import vlmd_validate | ||
|
||
logging = get_logger("__name__") | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--input_file", | ||
"input_file", | ||
help="name of file to validate", | ||
type=click.Path(writable=True), | ||
) | ||
def validate(input_file): | ||
"""Validate VLMD input file""" | ||
|
||
logging.info(f"Validating VLMD file{input_file}") | ||
|
||
try: | ||
vlmd_validate(input_file) | ||
except Exception as e: | ||
logging.warning(str(e)) | ||
raise e | ||
logging.info("Valid") |
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,19 @@ | ||
import click | ||
|
||
from heal.cli import extract, validate | ||
|
||
|
||
@click.group() | ||
def main(): | ||
"""HEAL Command Line Interface""" | ||
pass | ||
|
||
|
||
@click.group() | ||
def vlmd(): | ||
"""Commands for VLMD""" | ||
pass | ||
|
||
|
||
vlmd.add_command(extract.extract) | ||
vlmd.add_command(validate.validate) |
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,83 @@ | ||
import os | ||
|
||
from click.testing import CliRunner | ||
import pytest | ||
|
||
import heal.vlmd.file_utils as file_utils | ||
import heal.cli.heal_cli as cli_module | ||
|
||
|
||
def test_help(): | ||
runner = CliRunner() | ||
expected_text = "HEAL-Platform SDK Command Line Interface" | ||
expected_commands = ["vlmd Commands for VLMD"] | ||
result = runner.invoke(cli_module.main, ["--help"]) | ||
assert result.exit_code == 0 | ||
assert expected_text in result.output | ||
for command_text in expected_commands: | ||
assert command_text in result.output | ||
|
||
|
||
def test_vlmd_help(): | ||
runner = CliRunner() | ||
expected_text = "Commands for VLMD" | ||
expected_commands = [ | ||
"extract Extract HEAL-compliant VLMD file from input file", | ||
"validate Validate VLMD input file", | ||
] | ||
result = runner.invoke(cli_module.main, ["vlmd", "--help"]) | ||
assert result.exit_code == 0 | ||
assert expected_text in result.output | ||
for command_text in expected_commands: | ||
assert command_text in result.output | ||
|
||
|
||
def test_extract_help(): | ||
runner = CliRunner() | ||
expected_text = "Extract HEAL-compliant VLMD file from input file" | ||
expected_commands = [ | ||
"--input_file PATH name of file to extract HEAL-compliant VLMD file", | ||
"--output_dir PATH directory to write converted dictionary' [default: .]", | ||
] | ||
result = runner.invoke(cli_module.main, ["vlmd", "extract", "--help"]) | ||
assert result.exit_code == 0 | ||
assert expected_text in result.output | ||
for command_text in expected_commands: | ||
assert command_text in result.output | ||
|
||
|
||
def test_extract(tmp_path): | ||
runner = CliRunner() | ||
input_file = "tests/test_data/vlmd/valid/vlmd_valid.csv" | ||
expected_output_file = file_utils.get_output_filepath( | ||
tmp_path, input_file, output_type="json" | ||
) | ||
print(f"Expected output file {expected_output_file}") | ||
result = runner.invoke( | ||
cli_module.main, | ||
["vlmd", "extract", "--input_file", input_file, "--output_dir", tmp_path], | ||
) | ||
assert result.exit_code == 0 | ||
assert os.path.isfile(expected_output_file) | ||
|
||
|
||
def test_validate_help(): | ||
runner = CliRunner() | ||
expected_text = "Validate VLMD input file" | ||
expected_commands = [ | ||
"--input_file PATH name of file to validate", | ||
] | ||
result = runner.invoke(cli_module.main, ["vlmd", "validate", "--help"]) | ||
assert result.exit_code == 0 | ||
assert expected_text in result.output | ||
for command_text in expected_commands: | ||
assert command_text in result.output | ||
|
||
|
||
def test_validate(tmp_path): | ||
runner = CliRunner() | ||
input_file = "tests/test_data/vlmd/valid/vlmd_valid.json" | ||
result = runner.invoke( | ||
cli_module.main, ["vlmd", "validate", "--input_file", input_file] | ||
) | ||
assert result.exit_code == 0 |
Oops, something went wrong.
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.
This won't work here until the
extract
PR is merged and we pull master into this PR.