From 0b808671debb8c4333063a5bdfe3d160fa7398b0 Mon Sep 17 00:00:00 2001 From: finlayclark Date: Mon, 22 Apr 2024 10:10:44 +0100 Subject: [PATCH] Add CLI scripts to pyproject with script for auto-updating pyproject.toml --- pyproject.toml | 69 ++++++++++++++++++++++++++------------------- update_pyproject.py | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 update_pyproject.py diff --git a/pyproject.toml b/pyproject.toml index e47ea4e..f972a73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,43 +1,42 @@ [build-system] -requires = ["setuptools"] +requires = [ "setuptools",] build-backend = "setuptools.build_meta" [project] name = "maize-biosimspace" description = "Custom maize nodes and subgraphs" version = "0.1.0" -authors = [{name = "Finlay CLark"}] -maintainers = [{name = "Finlay Clark", email = "finlay.clark@ed.ac.uk"}] requires-python = ">=3.10" -dependencies = [ - "maize>=0.6.0", - "rdkit>=2022.9.5", - "pandas>=2.0.0", - "biosimspace" -] +dependencies = [ "maize>=0.6.0", "rdkit>=2022.9.5", "pandas>=2.0.0", "biosimspace",] +[[project.authors]] +name = "Finlay CLark" +[[project.maintainers]] +name = "Finlay Clark" +email = "finlay.clark@ed.ac.uk" [project.scripts] -bss_system_prep_free = "maize.graphs.exs.biosimspace.system_preparation:system_preparation_free" -bss_system_prep_bound = "maize.graphs.exs.biosimspace.system_preparation:system_preparation_bound" - -# Not quite sure why this is required (rather than listing the packages explicitly), -# but without this will only install using --editable, see also: -# https://stackoverflow.com/questions/43430852/import-only-works-when-module-installed-using-editable-pip-flag -[tool.setuptools.packages.find] -include = ["maize*"] - -[tool.pytest.ini_options] -config = "test-config.toml" -log_cli = true -log_cli_level = "DEBUG" -addopts = ["-vv"] -python_files = ["*.py"] -python_classes = ["TestSuite*"] -testpaths = [ - "maize/steps", - "tests", -] +bss_system_prep_free = "maize.graphs.exs.biosimspace.system_preparation:system_prep_free_exposed" +bss_system_prep_bound = "maize.graphs.exs.biosimspace.system_preparation:system_prep_bound_exposed" +bss_abfe_no_prep = "maize.graphs.exs.biosimspace.abfe:abfe_no_prep_exposed" +bss_abfe_with_prep = "maize.graphs.exs.biosimspace.abfe:abfe_with_prep_exposed" +bss_parameterise = "maize.steps.exs.biosimspace.parameterise:parameterise_exposed" +bss_solvate = "maize.steps.exs.biosimspace.solvate:solvate_exposed" +bss_minimise_gromacs = "maize.steps.exs.biosimspace.minimise:minimise_gromacs_exposed" +bss_minimise_pmemd_cuda = "maize.steps.exs.biosimspace.minimise:minimise_pmemd_cuda_exposed" +bss_minimise_pmemd = "maize.steps.exs.biosimspace.minimise:minimise_pmemd_exposed" +bss_minimise_sander = "maize.steps.exs.biosimspace.minimise:minimise_sander_exposed" +bss_minimise_somd = "maize.steps.exs.biosimspace.minimise:minimise_somd_exposed" +bss_equilibrate_gromacs = "maize.steps.exs.biosimspace.equilibrate:equilibrate_gromacs_exposed" +bss_equilibrate_pmemd_cuda = "maize.steps.exs.biosimspace.equilibrate:equilibrate_pmemd_cuda_exposed" +bss_equilibrate_pmemd = "maize.steps.exs.biosimspace.equilibrate:equilibrate_pmemd_exposed" +bss_equilibrate_sander = "maize.steps.exs.biosimspace.equilibrate:equilibrate_sander_exposed" +bss_equilibrate_somd = "maize.steps.exs.biosimspace.equilibrate:equilibrate_somd_exposed" +bss_production_gromacs = "maize.steps.exs.biosimspace.production:production_gromacs_exposed" +bss_production_pmemd_cuda = "maize.steps.exs.biosimspace.production:production_pmemd_cuda_exposed" +bss_production_pmemd = "maize.steps.exs.biosimspace.production:production_pmemd_exposed" +bss_production_sander = "maize.steps.exs.biosimspace.production:production_sander_exposed" +bss_production_somd = "maize.steps.exs.biosimspace.production:production_somd_exposed" [tool.mypy] follow_imports = "silent" @@ -51,3 +50,15 @@ line-length = 100 [tool.ruff] line-length = 100 + +[tool.pytest.ini_options] +config = "test-config.toml" +log_cli = true +log_cli_level = "DEBUG" +addopts = [ "-vv",] +python_files = [ "*.py",] +python_classes = [ "TestSuite*",] +testpaths = [ "maize/steps", "tests",] + +[tool.setuptools.packages.find] +include = [ "maize*",] diff --git a/update_pyproject.py b/update_pyproject.py new file mode 100644 index 0000000..b6b11c5 --- /dev/null +++ b/update_pyproject.py @@ -0,0 +1,58 @@ +""" +Script to automatically update pyproject.toml with auto-generated +command-line functions in the project.scripts section. +""" + +import os +from setuptools import setup, find_packages +import toml + +CLI_MODULES = [ + # Steps + "maize.steps.exs.biosimspace.parameterise", + "maize.steps.exs.biosimspace.solvate", + "maize.steps.exs.biosimspace.minimise", + "maize.steps.exs.biosimspace.equilibrate", + "maize.steps.exs.biosimspace.production", + # Graphs + "maize.graphs.exs.biosimspace.system_preparation", + "maize.graphs.exs.biosimspace.abfe", +] + +def get_cli_functions(cli_modules: list[str]) -> dict[str, str]: + """Get a dictionary of command-line functions and their entry points.""" + + cli_functions = {} + for module_name_full in cli_modules: + # Find all functions called "exposed" in the module + module_name_short = module_name_full.split('.')[-1] + module = __import__(module_name_full, fromlist=[module_name_short]) + for name in dir(module): + if name.endswith("_exposed"): + cli_name = f"bss_{name.replace('_exposed', '')}" + cli_functions[cli_name] = f"{module_name_full}:{name}" + + return cli_functions + + +def update_pyproject_toml(cli_modules: list[str]) -> None: + """Update pyproject.toml with auto-generated command-line functions.""" + + pyproject_path = 'pyproject.toml' + if os.path.exists(pyproject_path): + pyproject_data = toml.load(pyproject_path) + else: + pyproject_data = {} + + # Define the command-line functions and their entry points + cli_functions = get_cli_functions(cli_modules) + + # Update the pyproject.toml data in the project.scripts section + pyproject_data.setdefault('project', {}).setdefault('scripts', {}).update(cli_functions) + + # Write the updated data back to pyproject.toml + with open(pyproject_path, 'w') as toml_file: + toml.dump(pyproject_data, toml_file) + +if __name__ == "__main__": + update_pyproject_toml(CLI_MODULES)