From ddd942d3dfe3884a97a855446410166c3c9f16d9 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Thu, 12 Aug 2021 18:36:13 +0100 Subject: [PATCH] Switch click CLI to use underscores instead of dashes for consistency with JSON arg parse (#652) * Switch commands to use underscore instead of dash * Switch to underscore --- docs/source/reference/audio_classification.rst | 4 ++-- docs/source/reference/graph_classification.rst | 4 ++-- docs/source/reference/image_classification.rst | 4 ++-- docs/source/reference/image_classification_multi_label.rst | 4 ++-- docs/source/reference/object_detection.rst | 4 ++-- docs/source/reference/pointcloud_object_detection.rst | 4 ++-- docs/source/reference/pointcloud_segmentation.rst | 4 ++-- docs/source/reference/semantic_segmentation.rst | 4 ++-- docs/source/reference/speech_recognition.rst | 4 ++-- docs/source/reference/style_transfer.rst | 4 ++-- docs/source/reference/tabular_classification.rst | 4 ++-- docs/source/reference/text_classification.rst | 4 ++-- docs/source/reference/text_classification_multi_label.rst | 4 ++-- docs/source/reference/video_classification.rst | 4 ++-- flash/__main__.py | 3 ++- flash/graph/classification/model.py | 4 ++-- tests/audio/classification/test_model.py | 2 +- tests/audio/speech_recognition/test_model.py | 2 +- tests/graph/classification/test_model.py | 2 +- tests/image/classification/test_model.py | 2 +- tests/image/detection/test_model.py | 2 +- tests/image/segmentation/test_model.py | 2 +- tests/image/style_transfer/test_model.py | 2 +- tests/text/classification/test_model.py | 4 ++-- tests/video/classification/test_model.py | 2 +- 25 files changed, 42 insertions(+), 41 deletions(-) diff --git a/docs/source/reference/audio_classification.rst b/docs/source/reference/audio_classification.rst index 4b5e10409b..97c8df79b3 100644 --- a/docs/source/reference/audio_classification.rst +++ b/docs/source/reference/audio_classification.rst @@ -83,10 +83,10 @@ You can run the above example with: .. code-block:: bash - flash audio-classification + flash audio_classification To view configuration options and options for running the audio classifier with your own data, use: .. code-block:: bash - flash audio-classification --help + flash audio_classification --help diff --git a/docs/source/reference/graph_classification.rst b/docs/source/reference/graph_classification.rst index dc3a43ed06..84cc8d12d4 100644 --- a/docs/source/reference/graph_classification.rst +++ b/docs/source/reference/graph_classification.rst @@ -43,10 +43,10 @@ You can run the above example with: .. code-block:: bash - flash graph-classifier + flash graph_classification To view configuration options and options for running the graph classifier with your own data, use: .. code-block:: bash - flash graph-classifier --help + flash graph_classification --help diff --git a/docs/source/reference/image_classification.rst b/docs/source/reference/image_classification.rst index 08995a7e90..4116128f2a 100644 --- a/docs/source/reference/image_classification.rst +++ b/docs/source/reference/image_classification.rst @@ -117,13 +117,13 @@ You can run the hymenoptera example with: .. code-block:: bash - flash image-classification + flash image_classification To view configuration options and options for running the image classifier with your own data, use: .. code-block:: bash - flash image-classification --help + flash image_classification --help ------ diff --git a/docs/source/reference/image_classification_multi_label.rst b/docs/source/reference/image_classification_multi_label.rst index f36beb7a49..77e447c705 100644 --- a/docs/source/reference/image_classification_multi_label.rst +++ b/docs/source/reference/image_classification_multi_label.rst @@ -61,13 +61,13 @@ You can run the movie posters example with: .. code-block:: bash - flash image-classification from_movie_posters + flash image_classification from_movie_posters To view configuration options and options for running the image classifier with your own data, use: .. code-block:: bash - flash image-classification --help + flash image_classification --help ------ diff --git a/docs/source/reference/object_detection.rst b/docs/source/reference/object_detection.rst index 8ac2d625d0..d0e2baf74d 100644 --- a/docs/source/reference/object_detection.rst +++ b/docs/source/reference/object_detection.rst @@ -59,10 +59,10 @@ You can run the above example with: .. code-block:: bash - flash object-detection + flash object_detection To view configuration options and options for running the object detector with your own data, use: .. code-block:: bash - flash object-detection --help + flash object_detection --help diff --git a/docs/source/reference/pointcloud_object_detection.rst b/docs/source/reference/pointcloud_object_detection.rst index 5ab1daa99c..1be71919f3 100644 --- a/docs/source/reference/pointcloud_object_detection.rst +++ b/docs/source/reference/pointcloud_object_detection.rst @@ -90,10 +90,10 @@ You can run the above example with: .. code-block:: bash - flash pointcloud-detection + flash pointcloud_detection To view configuration options and options for running the point cloud object detector with your own data, use: .. code-block:: bash - flash pointcloud-detection --help + flash pointcloud_detection --help diff --git a/docs/source/reference/pointcloud_segmentation.rst b/docs/source/reference/pointcloud_segmentation.rst index 2576198001..1777313521 100644 --- a/docs/source/reference/pointcloud_segmentation.rst +++ b/docs/source/reference/pointcloud_segmentation.rst @@ -81,10 +81,10 @@ You can run the above example with: .. code-block:: bash - flash pointcloud-segmentation + flash pointcloud_segmentation To view configuration options and options for running the point cloud segmentation task with your own data, use: .. code-block:: bash - flash pointcloud-segmentation --help + flash pointcloud_segmentation --help diff --git a/docs/source/reference/semantic_segmentation.rst b/docs/source/reference/semantic_segmentation.rst index 8f4c72c002..92cbe67314 100644 --- a/docs/source/reference/semantic_segmentation.rst +++ b/docs/source/reference/semantic_segmentation.rst @@ -56,13 +56,13 @@ You can run the above example with: .. code-block:: bash - flash semantic-segmentation + flash semantic_segmentation To view configuration options and options for running the semantic segmentation task with your own data, use: .. code-block:: bash - flash semantic-segmentation --help + flash semantic_segmentation --help ------ diff --git a/docs/source/reference/speech_recognition.rst b/docs/source/reference/speech_recognition.rst index b7fa0fe400..2b6918078c 100644 --- a/docs/source/reference/speech_recognition.rst +++ b/docs/source/reference/speech_recognition.rst @@ -58,13 +58,13 @@ You can run the above example with: .. code-block:: bash - flash speech-recognition + flash speech_recognition To view configuration options and options for running the speech recognition task with your own data, use: .. code-block:: bash - flash speech-recognition --help + flash speech_recognition --help ------ diff --git a/docs/source/reference/style_transfer.rst b/docs/source/reference/style_transfer.rst index 1200e315b0..4b19c940ef 100644 --- a/docs/source/reference/style_transfer.rst +++ b/docs/source/reference/style_transfer.rst @@ -45,10 +45,10 @@ You can run the above example with: .. code-block:: bash - flash style-transfer + flash style_transfer To view configuration options and options for running the style transfer task with your own data, use: .. code-block:: bash - flash style-transfer --help + flash style_transfer --help diff --git a/docs/source/reference/tabular_classification.rst b/docs/source/reference/tabular_classification.rst index 6bb68ba585..48ce18a872 100644 --- a/docs/source/reference/tabular_classification.rst +++ b/docs/source/reference/tabular_classification.rst @@ -57,13 +57,13 @@ You can run the above example with: .. code-block:: bash - flash tabular-classifier + flash tabular_classifier To view configuration options and options for running the tabular classifier with your own data, use: .. code-block:: bash - flash tabular-classifier --help + flash tabular_classifier --help ------ diff --git a/docs/source/reference/text_classification.rst b/docs/source/reference/text_classification.rst index e4a26828eb..42424cc980 100644 --- a/docs/source/reference/text_classification.rst +++ b/docs/source/reference/text_classification.rst @@ -58,13 +58,13 @@ You can run the above example with: .. code-block:: bash - flash text-classifier + flash text_classification To view configuration options and options for running the text classifier with your own data, use: .. code-block:: bash - flash text-classifier --help + flash text_classification --help ------ diff --git a/docs/source/reference/text_classification_multi_label.rst b/docs/source/reference/text_classification_multi_label.rst index e5aa304936..54929122ab 100644 --- a/docs/source/reference/text_classification_multi_label.rst +++ b/docs/source/reference/text_classification_multi_label.rst @@ -56,13 +56,13 @@ You can run the above example with: .. code-block:: bash - flash text-classifier from_toxic + flash text_classification from_toxic To view configuration options and options for running the text classifier with your own data, use: .. code-block:: bash - flash text-classifier --help + flash text_classification --help ------ diff --git a/docs/source/reference/video_classification.rst b/docs/source/reference/video_classification.rst index 5728248d6b..4a60280ad8 100644 --- a/docs/source/reference/video_classification.rst +++ b/docs/source/reference/video_classification.rst @@ -68,10 +68,10 @@ You can run the above example with: .. code-block:: bash - flash video-classifier + flash video_classification To view configuration options and options for running the video classifier with your own data, use: .. code-block:: bash - flash video-classifier --help + flash video_classification --help diff --git a/flash/__main__.py b/flash/__main__.py index f4eb704a76..d967149d56 100644 --- a/flash/__main__.py +++ b/flash/__main__.py @@ -25,10 +25,11 @@ def main(): def register_command(command): @main.command( + command.__name__, context_settings=dict( help_option_names=[], ignore_unknown_options=True, - ) + ), ) @click.argument("cli_args", nargs=-1, type=click.UNPROCESSED) @functools.wraps(command) diff --git a/flash/graph/classification/model.py b/flash/graph/classification/model.py index e4d96c2d92..d8878c73c3 100644 --- a/flash/graph/classification/model.py +++ b/flash/graph/classification/model.py @@ -19,9 +19,9 @@ from torch.nn import Linear from flash.core.classification import ClassificationTask -from flash.core.utilities.imports import _TORCH_GEOMETRIC_AVAILABLE +from flash.core.utilities.imports import _GRAPH_AVAILABLE -if _TORCH_GEOMETRIC_AVAILABLE: +if _GRAPH_AVAILABLE: from torch_geometric.nn import BatchNorm, GCNConv, global_mean_pool, MessagePassing else: MessagePassing = None diff --git a/tests/audio/classification/test_model.py b/tests/audio/classification/test_model.py index f94b1cb581..0e5a4fa3fc 100644 --- a/tests/audio/classification/test_model.py +++ b/tests/audio/classification/test_model.py @@ -23,7 +23,7 @@ @pytest.mark.skipif(not _IMAGE_AVAILABLE, reason="image libraries aren't installed.") @pytest.mark.skipif(not _AUDIO_TESTING, reason="audio libraries aren't installed.") def test_cli(): - cli_args = ["flash", "audio-classification", "--trainer.fast_dev_run", "True"] + cli_args = ["flash", "audio_classification", "--trainer.fast_dev_run", "True"] with mock.patch("sys.argv", cli_args): try: main() diff --git a/tests/audio/speech_recognition/test_model.py b/tests/audio/speech_recognition/test_model.py index f1b1f55ee5..5ce932cd4d 100644 --- a/tests/audio/speech_recognition/test_model.py +++ b/tests/audio/speech_recognition/test_model.py @@ -94,7 +94,7 @@ def test_load_from_checkpoint_dependency_error(): @pytest.mark.skipif(not _AUDIO_TESTING, reason="audio libraries aren't installed.") def test_cli(): - cli_args = ["flash", "speech-recognition", "--trainer.fast_dev_run", "True"] + cli_args = ["flash", "speech_recognition", "--trainer.fast_dev_run", "True"] with mock.patch("sys.argv", cli_args): try: main() diff --git a/tests/graph/classification/test_model.py b/tests/graph/classification/test_model.py index 656d69f729..0813a6fb3a 100644 --- a/tests/graph/classification/test_model.py +++ b/tests/graph/classification/test_model.py @@ -80,7 +80,7 @@ def test_predict_dataset(tmpdir): @pytest.mark.skipif(not _GRAPH_TESTING, reason="pytorch geometric isn't installed") def test_cli(): - cli_args = ["flash", "graph-classification", "--trainer.fast_dev_run", "True"] + cli_args = ["flash", "graph_classification", "--trainer.fast_dev_run", "True"] with mock.patch("sys.argv", cli_args): try: main() diff --git a/tests/image/classification/test_model.py b/tests/image/classification/test_model.py index 3fb01b87f2..d9014464eb 100644 --- a/tests/image/classification/test_model.py +++ b/tests/image/classification/test_model.py @@ -151,7 +151,7 @@ def test_load_from_checkpoint_dependency_error(): @pytest.mark.skipif(not _IMAGE_TESTING, reason="image libraries aren't installed.") def test_cli(): - cli_args = ["flash", "image-classification", "--trainer.fast_dev_run", "True"] + cli_args = ["flash", "image_classification", "--trainer.fast_dev_run", "True"] with mock.patch("sys.argv", cli_args): try: main() diff --git a/tests/image/detection/test_model.py b/tests/image/detection/test_model.py index cfc5e57d23..cae495794a 100644 --- a/tests/image/detection/test_model.py +++ b/tests/image/detection/test_model.py @@ -111,7 +111,7 @@ def test_load_from_checkpoint_dependency_error(): @pytest.mark.skipif(not _IMAGE_AVAILABLE, reason="image libraries aren't installed.") @pytest.mark.skipif(not _COCO_AVAILABLE, reason="pycocotools is not installed for testing.") def test_cli(): - cli_args = ["flash", "object-detection", "--trainer.fast_dev_run", "True"] + cli_args = ["flash", "object_detection", "--trainer.fast_dev_run", "True"] with mock.patch("sys.argv", cli_args): try: main() diff --git a/tests/image/segmentation/test_model.py b/tests/image/segmentation/test_model.py index 79058bec3f..6715ebfc50 100644 --- a/tests/image/segmentation/test_model.py +++ b/tests/image/segmentation/test_model.py @@ -165,7 +165,7 @@ def test_available_pretrained_weights(): @pytest.mark.skipif(not _IMAGE_TESTING, reason="image libraries aren't installed.") def test_cli(): - cli_args = ["flash", "semantic-segmentation", "--trainer.fast_dev_run", "True"] + cli_args = ["flash", "semantic_segmentation", "--trainer.fast_dev_run", "True"] with mock.patch("sys.argv", cli_args): try: main() diff --git a/tests/image/style_transfer/test_model.py b/tests/image/style_transfer/test_model.py index 93ccb32ece..8573b70784 100644 --- a/tests/image/style_transfer/test_model.py +++ b/tests/image/style_transfer/test_model.py @@ -70,7 +70,7 @@ def test_load_from_checkpoint_dependency_error(): @pytest.mark.skipif(not _IMAGE_TESTING, reason="image libraries aren't installed.") def test_cli(): - cli_args = ["flash", "style-transfer", "--trainer.fast_dev_run", "True"] + cli_args = ["flash", "style_transfer", "--trainer.fast_dev_run", "True"] with mock.patch("sys.argv", cli_args): try: main() diff --git a/tests/text/classification/test_model.py b/tests/text/classification/test_model.py index 73da369e25..7ca20d92c7 100644 --- a/tests/text/classification/test_model.py +++ b/tests/text/classification/test_model.py @@ -93,8 +93,8 @@ def test_load_from_checkpoint_dependency_error(): @pytest.mark.parametrize( "cli_args", ( - ["flash", "text-classification", "--trainer.fast_dev_run", "True"], - ["flash", "text-classification", "--trainer.fast_dev_run", "True", "from_toxic"], + ["flash", "text_classification", "--trainer.fast_dev_run", "True"], + ["flash", "text_classification", "--trainer.fast_dev_run", "True", "from_toxic"], ), ) def test_cli(cli_args): diff --git a/tests/video/classification/test_model.py b/tests/video/classification/test_model.py index dca5dc81ab..8d11b672cd 100644 --- a/tests/video/classification/test_model.py +++ b/tests/video/classification/test_model.py @@ -301,7 +301,7 @@ def test_load_from_checkpoint_dependency_error(): @pytest.mark.skipif(not _VIDEO_TESTING, reason="PyTorchVideo isn't installed.") def test_cli(): - cli_args = ["flash", "video-classification", "--trainer.fast_dev_run", "True", "num_workers", "0"] + cli_args = ["flash", "video_classification", "--trainer.fast_dev_run", "True", "num_workers", "0"] with mock.patch("sys.argv", cli_args): try: main()