From 347ccddb979e2465acb999671869ca19989f951c Mon Sep 17 00:00:00 2001 From: richard gowers Date: Tue, 21 Nov 2023 10:15:15 +0000 Subject: [PATCH 1/2] start using click.ground to nest subcommands under openfe_analysis adds RFE_analysis as first subcommand (was previously only command) --- pyproject.toml | 2 +- src/openfe_analysis/cli.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 777485c..01e2d0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ test = [ "Homepage" = "https://github.com/OpenFreeEnergy/openfe_analysis" [project.scripts] -openfe_analysis = "openfe_analysis.cli:main" +openfe_analysis = "openfe_analysis.cli:cli" [tool.versioningit] default-version = "1+unknown" diff --git a/src/openfe_analysis/cli.py b/src/openfe_analysis/cli.py index fb39f9d..cc127ca 100644 --- a/src/openfe_analysis/cli.py +++ b/src/openfe_analysis/cli.py @@ -5,13 +5,18 @@ from . import rmsd -@click.command +@click.group() +def cli(): + pass + + +@cli.command(name="RFE_analysis") @click.argument('loc', type=click.Path(exists=True, readable=True, file_okay=False, dir_okay=True, path_type=pathlib.Path)) -def main(loc): +def rfe_analysis(loc): pdb = loc / "hybrid_system.pdb" trj = loc / "simulation.nc" From 75d8af5d5dc4bb59eb0be0c19af470b09e872e48 Mon Sep 17 00:00:00 2001 From: richard gowers Date: Tue, 21 Nov 2023 13:01:27 +0000 Subject: [PATCH 2/2] require output directory for RFE_analysis command --- src/openfe_analysis/cli.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/openfe_analysis/cli.py b/src/openfe_analysis/cli.py index cc127ca..42826cc 100644 --- a/src/openfe_analysis/cli.py +++ b/src/openfe_analysis/cli.py @@ -16,9 +16,14 @@ def cli(): file_okay=False, dir_okay=True, path_type=pathlib.Path)) -def rfe_analysis(loc): +@click.argument('output', type=click.Path(writable=True, + dir_okay=False, + path_type=pathlib.Path)) +def rfe_analysis(loc, output): pdb = loc / "hybrid_system.pdb" trj = loc / "simulation.nc" data = rmsd.gather_rms_data(pdb, trj) - click.echo(json.dumps(data)) + + with click.open_file(output, 'w') as f: + f.write(json.dumps(data))