-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding initial cli using click, tests todo
addressing #11
- Loading branch information
1 parent
480372e
commit 7f87d95
Showing
6 changed files
with
132 additions
and
78 deletions.
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 was deleted.
Oops, something went wrong.
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 os | ||
import unittest | ||
from unittest.mock import patch | ||
import pkg_resources | ||
from click.testing import CliRunner | ||
from topic2shiny import main | ||
|
||
resource_package = 'topic_model_to_Shiny_app' | ||
|
||
test_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
class CLI_test(unittest.TestCase): | ||
|
||
def test_CLI(self): | ||
# these are examples and will fail | ||
# TODO: update these to actually test CLI | ||
runner = CliRunner() | ||
result = runner.invoke(cli, ['--debug', 'sync']) | ||
assert result.exit_code == 0 | ||
assert 'Debug mode is on' in result.output | ||
assert 'Syncing' in result.output | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
||
unittest.main(verbosity=2) |
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,74 @@ | ||
import time | ||
# consider security imp of subprocess | ||
import subprocess | ||
import click | ||
from topic_model_to_Shiny_app.text_preprocessing import preprocessing | ||
from topic_model_to_Shiny_app.topic_number_selex import topic_number_selector | ||
from topic_model_to_Shiny_app.dominant_topic_processing import topic_processing | ||
import pkg_resources | ||
import pathlib | ||
|
||
# specify top level package folder | ||
resource_package = 'topic_model_to_Shiny_app' | ||
|
||
@click.command() | ||
@click.option('-i', '--input-path', prompt='Specify input data path', type=str, | ||
help='The absolute path to the input data file.') | ||
@click.option('-o', '--output-directory', prompt='Specify directory for outputs', type=str, | ||
help='The absolute path to an directory for outputs, will create a new directory if required.') | ||
@click.option('-n', '--num-runs', prompt='Please specify the number of LDA repeats for topic number selection', type=int, | ||
help='The number of LDA repeat runs desired to establish working topic number.') | ||
@click.option('-p', '--pretrained', default=False, type=bool, | ||
help='A boolean to check if user wishes to use a pretrained model.') | ||
@click.option('-m', '--pretrained-model', type=str, | ||
help='The absolute path to the pretrained model file.') | ||
@click.option('-s', '--shiny-start', default=True, type=bool, | ||
help='A boolean to confirm if user wishes Shiny app instance to start.') | ||
|
||
def main(input_path : str, | ||
output_directory : str, | ||
num_runs : int, | ||
pretrained : bool, | ||
pretrained_model : str, | ||
shiny_start : bool): | ||
""" | ||
The main function handling CLI | ||
\b | ||
:param input_path: this is a first param | ||
:param output_directory: this is a second param | ||
:param n_runs: an integer of the number of repeat runs of LDA to perform | ||
:param pretrained: a boolean of whether user wants to use a pretrained model | ||
:param pretrained_model: a string of the path to the pretrained model | ||
:param shiny_start: a boolean of whether to start shiny app at the end of processing | ||
:returns: None (loads shiny app) | ||
""" | ||
# take the output directory and create it if it doesn't exist | ||
pathlib.Path(output_directory).mkdir(parents=True, exist_ok=True) | ||
|
||
# check if you need a new model | ||
if not pretrained: | ||
|
||
transformed_data = preprocessing(input_path) | ||
|
||
topic_number_selector(processed_data = transformed_data, output_path=output_directory, | ||
narrow_iter = num_runs, wide_iter = 100) | ||
|
||
else: | ||
# TODO: write in how to load a pretrained model | ||
pass | ||
|
||
topic_processing(output_path=output_directory) | ||
|
||
if shiny_start: | ||
|
||
print('Initialising Shiny dashboard.') | ||
|
||
shiny_dir = pkg_resources.resource_filename(resource_package, "Shiny/combined.R") | ||
|
||
# process to call shiny app | ||
subprocess.call([shiny_dir]) | ||
|
||
if __name__ == '__main__': | ||
|
||
main() |