Skip to content

Commit 456ca72

Browse files
committed
refactor!: much better typing and API
1 parent a0dbc07 commit 456ca72

File tree

7 files changed

+558
-321
lines changed

7 files changed

+558
-321
lines changed

pyproject.toml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
[tool.pytest.ini_options]
2+
addopts = "--cov=ml_project" # CHANGE (name of the importing module name)
3+
testpaths = ["tests"]
4+
5+
[tool.ruff]
6+
src = ["src"] # for ruff isort
7+
namespace-packages = ["tools", "scripts"] # for INP rule, suppress on these directories
8+
9+
[tool.ruff.lint]
10+
# OPTIONALLY ADD MORE LATER
11+
select = [
12+
# flake8
13+
"E",
14+
"F",
15+
"W",
16+
"B", # Bugbear
17+
"D", # Docstring
18+
"D213", # Multi-line docstring summary should start at the second line (replace D212)
19+
"N", # Naming
20+
"C4", # flake8-comprehensions
21+
"UP", # pyupgrade
22+
"SIM", # simplify
23+
"RUF", # ruff-specific
24+
"RET501", # return
25+
"RET502", # return
26+
"RET503", # return
27+
"PTH", # path
28+
"NPY", # numpy
29+
"PD", # pandas
30+
"PYI", # type stubs for pyright/pylance
31+
"PT", # pytest
32+
"PIE", #
33+
"LOG", # logging
34+
"COM818", # comma misplaced
35+
"COM819", # comma
36+
"DTZ", # datetime
37+
"YTT",
38+
"ASYNC",
39+
"FBT", # boolean trap
40+
"A", # Shadowing python builtins
41+
"EXE", # executable (shebang)
42+
"FA", # future annotations
43+
"ISC", # Implicit string concatenation
44+
"ICN", # Import convention
45+
"INP", # Implicit namespace package (no __init__.py)
46+
"Q", # Quotes
47+
"RSE", # raise
48+
"SLOT", # __slots__
49+
"PL", # Pylint
50+
"TRY", # try
51+
"FAST", # FastAPI
52+
"AIR", # airflow
53+
"DOC", # docstring
54+
55+
# Not important
56+
"T10", # debug statements
57+
"T20", # print statements
58+
]
59+
60+
ignore = [
61+
"E402", # Module level import not at top of file
62+
"W293", # Blank line contains whitespace
63+
"W291", # Trailing whitespace
64+
"D10", # Missing docstring in public module / function / etc.
65+
"D200", # One-line docstring should fit on one line with quotes
66+
"D212", # Multi-line docstring summary should start at the first line
67+
"D417", # require documentation for every function parameter.
68+
"D401", # require an imperative mood for all docstrings.
69+
"DOC201", # missing Return field in docstring
70+
"PTH123", # Path.open should be used instead of built-in open
71+
"PT006", # Pytest parameterize style
72+
"N812", # Lowercase `functional` imported as non-lowercase `F` (import torch.nn.functional as F)
73+
"NPY002", # legacy numpy random
74+
"UP017", # datetime.timezone.utc -> datetime.UTC
75+
"SIM108", # use ternary operator instead of if-else
76+
"TRY003", # long message in except
77+
]
78+
79+
[tool.ruff.lint.pydocstyle]
80+
convention = "google"
81+
82+
[tool.ruff.lint.pycodestyle]
83+
# Black or ruff will enforce line length to be 88, except for docstrings and comments.
84+
# We set it to 120 so we have more space for docstrings and comments.
85+
max-line-length = 120
86+
87+
[tool.ruff.lint.isort]
88+
# combine-as-imports = true
89+
known-third-party = ["wandb"]
90+
91+
## Uncomment this if you want to use Python < 3.10
92+
# required-imports = [
93+
# "from __future__ import annotations",
94+
# ]
95+
96+
[tool.ruff.lint.flake8-tidy-imports]
97+
# Ban certain modules from being imported at module level, instead requiring
98+
# that they're imported lazily (e.g., within a function definition, if TYPE_CHECKING, etc.)
99+
# NOTE: Ruff code TID is currently disabled, so this settings doesn't do anything.
100+
banned-module-level-imports = ["torch", "tensorflow"]
101+
102+
[tool.ruff.lint.pylint]
103+
max-args = 10
104+
max-bool-expr = 10
105+
max-statements = 100
106+
107+
[tool.pyright]
108+
include = ["src"]
109+
110+
typeCheckingMode = "standard"
111+
useLibraryCodeForTypes = true
112+
autoImportCompletions = true
113+
114+
# pythonPlatform = "Linux"

python/pyproject.toml

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -31,118 +31,3 @@ keywords = ["biology"]
3131

3232
[tool.setuptools.packages.find]
3333
where = ["src"]
34-
35-
[tool.pytest.ini_options]
36-
addopts = "--cov=ml_project" # CHANGE (name of the importing module name)
37-
testpaths = ["tests"]
38-
39-
[tool.ruff]
40-
src = ["src"] # for ruff isort
41-
namespace-packages = ["tools", "scripts"] # for INP rule, suppress on these directories
42-
43-
[tool.ruff.lint]
44-
# OPTIONALLY ADD MORE LATER
45-
select = [
46-
# flake8
47-
"E",
48-
"F",
49-
"W",
50-
"B", # Bugbear
51-
"D", # Docstring
52-
"D213", # Multi-line docstring summary should start at the second line (replace D212)
53-
"N", # Naming
54-
"C4", # flake8-comprehensions
55-
"UP", # pyupgrade
56-
"SIM", # simplify
57-
"RUF", # ruff-specific
58-
"RET501", # return
59-
"RET502", # return
60-
"RET503", # return
61-
"PTH", # path
62-
"NPY", # numpy
63-
"PD", # pandas
64-
"PYI", # type stubs for pyright/pylance
65-
"PT", # pytest
66-
"PIE", #
67-
"LOG", # logging
68-
"COM818", # comma misplaced
69-
"COM819", # comma
70-
"DTZ", # datetime
71-
"YTT",
72-
"ASYNC",
73-
"FBT", # boolean trap
74-
"A", # Shadowing python builtins
75-
"EXE", # executable (shebang)
76-
"FA", # future annotations
77-
"ISC", # Implicit string concatenation
78-
"ICN", # Import convention
79-
"INP", # Implicit namespace package (no __init__.py)
80-
"Q", # Quotes
81-
"RSE", # raise
82-
"SLOT", # __slots__
83-
"PL", # Pylint
84-
"TRY", # try
85-
"FAST", # FastAPI
86-
"AIR", # airflow
87-
"DOC", # docstring
88-
89-
# Not important
90-
"T10", # debug statements
91-
"T20", # print statements
92-
]
93-
94-
ignore = [
95-
"E402", # Module level import not at top of file
96-
"W293", # Blank line contains whitespace
97-
"W291", # Trailing whitespace
98-
"D10", # Missing docstring in public module / function / etc.
99-
"D200", # One-line docstring should fit on one line with quotes
100-
"D212", # Multi-line docstring summary should start at the first line
101-
"D417", # require documentation for every function parameter.
102-
"D401", # require an imperative mood for all docstrings.
103-
"DOC201", # missing Return field in docstring
104-
"PTH123", # Path.open should be used instead of built-in open
105-
"PT006", # Pytest parameterize style
106-
"N812", # Lowercase `functional` imported as non-lowercase `F` (import torch.nn.functional as F)
107-
"NPY002", # legacy numpy random
108-
"UP017", # datetime.timezone.utc -> datetime.UTC
109-
"SIM108", # use ternary operator instead of if-else
110-
"TRY003", # long message in except
111-
]
112-
113-
[tool.ruff.lint.pydocstyle]
114-
convention = "google"
115-
116-
[tool.ruff.lint.pycodestyle]
117-
# Black or ruff will enforce line length to be 88, except for docstrings and comments.
118-
# We set it to 120 so we have more space for docstrings and comments.
119-
max-line-length = 120
120-
121-
[tool.ruff.lint.isort]
122-
# combine-as-imports = true
123-
known-third-party = ["wandb"]
124-
125-
## Uncomment this if you want to use Python < 3.10
126-
# required-imports = [
127-
# "from __future__ import annotations",
128-
# ]
129-
130-
[tool.ruff.lint.flake8-tidy-imports]
131-
# Ban certain modules from being imported at module level, instead requiring
132-
# that they're imported lazily (e.g., within a function definition, if TYPE_CHECKING, etc.)
133-
# NOTE: Ruff code TID is currently disabled, so this settings doesn't do anything.
134-
banned-module-level-imports = ["torch", "tensorflow"]
135-
136-
[tool.ruff.lint.pylint]
137-
max-args = 10
138-
max-bool-expr = 10
139-
max-statements = 100
140-
141-
[tool.pyright]
142-
include = ["src"]
143-
144-
typeCheckingMode = "standard"
145-
useLibraryCodeForTypes = true
146-
autoImportCompletions = true
147-
148-
# pythonPlatform = "Linux"

python/src/apbs_binary/__init__.py

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,79 @@
1+
import os
2+
from pathlib import Path
3+
4+
BIN_DIR = Path(__file__).parent / "bin"
5+
# NOTE: lib/ only exists for macos arm64, because we built using homebrew
6+
# and it didn't build entirely statically.
7+
# Thus we have to pass DYLD_LIBRARY_PATH to the subprocess.run call.
8+
LIB_DIR = Path(__file__).parent / "lib"
9+
10+
11+
def bin_path(bin_name: str) -> Path:
12+
if os.name == "nt":
13+
return BIN_DIR / f"{bin_name}.exe"
14+
return BIN_DIR / bin_name
15+
16+
17+
# bin/
18+
APBS_BIN_PATH = bin_path("apbs")
19+
20+
# originally share/apbs/tools/bin/, but moved to bin/
21+
ANALYSIS_BIN_PATH = bin_path("analysis")
22+
BENCHMARK_BIN_PATH = bin_path("benchmark")
23+
BORN_BIN_PATH = bin_path("born")
24+
COULOMB_BIN_PATH = bin_path("coulomb")
25+
DEL2DX_BIN_PATH = bin_path("del2dx")
26+
DX2MOL_BIN_PATH = bin_path("dx2mol")
27+
DX2UHBD_BIN_PATH = bin_path("dx2uhbd")
28+
DXMATH_BIN_PATH = bin_path("dxmath")
29+
MERGEDX_BIN_PATH = bin_path("mergedx")
30+
MERGEDX2_BIN_PATH = bin_path("mergedx2")
31+
MGMESH_BIN_PATH = bin_path("mgmesh")
32+
MULTIVALUE_BIN_PATH = bin_path("multivalue")
33+
SIMILARITY_BIN_PATH = bin_path("similarity")
34+
SMOOTH_BIN_PATH = bin_path("smooth")
35+
TENSOR2DX_BIN_PATH = bin_path("tensor2dx")
36+
UHBD_ASC2BIN_BIN_PATH = bin_path("uhbd_asc2bin")
37+
VALUE_BIN_PATH = bin_path("value")
38+
39+
140
from .executable import (
2-
ANALYSIS_BIN_PATH,
3-
APBS_BIN_PATH,
4-
BENCHMARK_BIN_PATH,
5-
BIN_DIR,
6-
BORN_BIN_PATH,
7-
COULOMB_BIN_PATH,
8-
DEL2DX_BIN_PATH,
9-
DX2MOL_BIN_PATH,
10-
DX2UHBD_BIN_PATH,
11-
DXMATH_BIN_PATH,
12-
MERGEDX2_BIN_PATH,
13-
MERGEDX_BIN_PATH,
14-
MGMESH_BIN_PATH,
15-
MULTIVALUE_BIN_PATH,
16-
SIMILARITY_BIN_PATH,
17-
SMOOTH_BIN_PATH,
18-
TENSOR2DX_BIN_PATH,
19-
UHBD_ASC2BIN_BIN_PATH,
20-
VALUE_BIN_PATH,
21-
apbs,
22-
multivalue,
23-
process_run,
41+
popen_analysis,
42+
popen_apbs,
43+
popen_benchmark,
44+
popen_born,
45+
popen_coulomb,
46+
popen_del2dx,
47+
popen_dx2mol,
48+
popen_dx2uhbd,
49+
popen_dxmath,
50+
popen_mergedx,
51+
popen_mergedx2,
52+
popen_mgmesh,
53+
popen_multivalue,
54+
popen_similarity,
55+
popen_smooth,
56+
popen_tensor2dx,
57+
popen_uhbd_asc2bin,
58+
popen_value,
59+
run_analysis,
60+
run_apbs,
61+
run_benchmark,
62+
run_born,
63+
run_coulomb,
64+
run_del2dx,
65+
run_dx2mol,
66+
run_dx2uhbd,
67+
run_dxmath,
68+
run_mergedx,
69+
run_mergedx2,
70+
run_mgmesh,
71+
run_multivalue,
72+
run_similarity,
73+
run_smooth,
74+
run_tensor2dx,
75+
run_uhbd_asc2bin,
76+
run_value,
2477
)
2578

2679
__version__ = "0.0.0"
27-
28-
__all__ = [
29-
"ANALYSIS_BIN_PATH",
30-
"APBS_BIN_PATH",
31-
"BENCHMARK_BIN_PATH",
32-
"BIN_DIR",
33-
"BORN_BIN_PATH",
34-
"COULOMB_BIN_PATH",
35-
"DEL2DX_BIN_PATH",
36-
"DX2MOL_BIN_PATH",
37-
"DX2UHBD_BIN_PATH",
38-
"DXMATH_BIN_PATH",
39-
"MERGEDX2_BIN_PATH",
40-
"MERGEDX_BIN_PATH",
41-
"MGMESH_BIN_PATH",
42-
"MULTIVALUE_BIN_PATH",
43-
"SIMILARITY_BIN_PATH",
44-
"SMOOTH_BIN_PATH",
45-
"TENSOR2DX_BIN_PATH",
46-
"UHBD_ASC2BIN_BIN_PATH",
47-
"VALUE_BIN_PATH",
48-
"apbs",
49-
"multivalue",
50-
"process_run",
51-
]

0 commit comments

Comments
 (0)