-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI scripts to pyproject with script for auto-updating pyproject.…
…toml
- Loading branch information
Showing
2 changed files
with
98 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "[email protected]"}] | ||
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 = "[email protected]" | ||
|
||
[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*",] |
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,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) |