From 2c958ad01c3526bca27f73f3471ec40fa538de1f Mon Sep 17 00:00:00 2001 From: Ben Galewsky Date: Tue, 17 Dec 2024 08:04:58 -0600 Subject: [PATCH] Add servicex deliver command line to submit a yaml file --- docs/command_line.rst | 7 +++++++ servicex/app/main.py | 16 ++++++++++++++++ tests/app/test_app.py | 15 +++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/docs/command_line.rst b/docs/command_line.rst index 0949ae39..adc162ce 100644 --- a/docs/command_line.rst +++ b/docs/command_line.rst @@ -20,6 +20,13 @@ Common command line arguments: If no backend is specified then the client will attempt to use the ``default_endpoint`` value to determine who to talk to. +deliver +~~~~~~~ +This command is used to submit a yaml configuration file to the serviceX backend. +It will print the paths to the resulting files. + +Provide the path to the configuration file as an argument to the command. + codegens ~~~~~~~~ diff --git a/servicex/app/main.py b/servicex/app/main.py index 840ef8a2..83d78f20 100644 --- a/servicex/app/main.py +++ b/servicex/app/main.py @@ -30,7 +30,9 @@ import rich import typer +from servicex import servicex_client from servicex._version import __version__ +from servicex.app.cli_options import backend_cli_option, config_file_option from servicex.app.datasets import datasets_app from servicex.app.transforms import transforms_app from servicex.app.cache import cache_app @@ -63,5 +65,19 @@ def main_info( pass +@app.command() +def deliver( + backend: Optional[str] = backend_cli_option, + config_path: Optional[str] = config_file_option, + spec_file: str = typer.Argument(..., help="Spec file to submit to serviceX")): + """ + Deliver a file to the ServiceX cache. + """ + + print(f"Delivering {spec_file} to ServiceX cache") + results = servicex_client.deliver(spec_file, servicex_name=backend, config_path=config_path) + rich.print(results) + + if __name__ == "__main__": app() diff --git a/tests/app/test_app.py b/tests/app/test_app.py index f7b30292..ed8d103a 100644 --- a/tests/app/test_app.py +++ b/tests/app/test_app.py @@ -25,6 +25,7 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from unittest.mock import Mock, patch def test_app_version(script_runner): @@ -32,3 +33,17 @@ def test_app_version(script_runner): result = script_runner.run(['servicex', '--version']) assert result.returncode == 0 assert result.stdout == f'ServiceX {servicex._version.__version__}\n' + + +def test_deliver(script_runner): + with patch('servicex.app.main.servicex_client') as mock_servicex_client: + mock_servicex_client.deliver = Mock(return_value={ + "UprootRaw_YAML": [ + "/tmp/foo.root", + "/tmp/bar.root" + ]}) + result = script_runner.run(['servicex', 'deliver', "foo.yaml"]) + assert result.returncode == 0 + result_rows = result.stdout.split('\n') + assert result_rows[0] == 'Delivering foo.yaml to ServiceX cache' + assert result_rows[1] == "{'UprootRaw_YAML': ['/tmp/foo.root', '/tmp/bar.root']}"