Skip to content

Commit

Permalink
refactor!: much better typing and API
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Oct 18, 2024
1 parent a0dbc07 commit 456ca72
Show file tree
Hide file tree
Showing 7 changed files with 558 additions and 321 deletions.
114 changes: 114 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[tool.pytest.ini_options]
addopts = "--cov=ml_project" # CHANGE (name of the importing module name)
testpaths = ["tests"]

[tool.ruff]
src = ["src"] # for ruff isort
namespace-packages = ["tools", "scripts"] # for INP rule, suppress on these directories

[tool.ruff.lint]
# OPTIONALLY ADD MORE LATER
select = [
# flake8
"E",
"F",
"W",
"B", # Bugbear
"D", # Docstring
"D213", # Multi-line docstring summary should start at the second line (replace D212)
"N", # Naming
"C4", # flake8-comprehensions
"UP", # pyupgrade
"SIM", # simplify
"RUF", # ruff-specific
"RET501", # return
"RET502", # return
"RET503", # return
"PTH", # path
"NPY", # numpy
"PD", # pandas
"PYI", # type stubs for pyright/pylance
"PT", # pytest
"PIE", #
"LOG", # logging
"COM818", # comma misplaced
"COM819", # comma
"DTZ", # datetime
"YTT",
"ASYNC",
"FBT", # boolean trap
"A", # Shadowing python builtins
"EXE", # executable (shebang)
"FA", # future annotations
"ISC", # Implicit string concatenation
"ICN", # Import convention
"INP", # Implicit namespace package (no __init__.py)
"Q", # Quotes
"RSE", # raise
"SLOT", # __slots__
"PL", # Pylint
"TRY", # try
"FAST", # FastAPI
"AIR", # airflow
"DOC", # docstring

# Not important
"T10", # debug statements
"T20", # print statements
]

ignore = [
"E402", # Module level import not at top of file
"W293", # Blank line contains whitespace
"W291", # Trailing whitespace
"D10", # Missing docstring in public module / function / etc.
"D200", # One-line docstring should fit on one line with quotes
"D212", # Multi-line docstring summary should start at the first line
"D417", # require documentation for every function parameter.
"D401", # require an imperative mood for all docstrings.
"DOC201", # missing Return field in docstring
"PTH123", # Path.open should be used instead of built-in open
"PT006", # Pytest parameterize style
"N812", # Lowercase `functional` imported as non-lowercase `F` (import torch.nn.functional as F)
"NPY002", # legacy numpy random
"UP017", # datetime.timezone.utc -> datetime.UTC
"SIM108", # use ternary operator instead of if-else
"TRY003", # long message in except
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.pycodestyle]
# Black or ruff will enforce line length to be 88, except for docstrings and comments.
# We set it to 120 so we have more space for docstrings and comments.
max-line-length = 120

[tool.ruff.lint.isort]
# combine-as-imports = true
known-third-party = ["wandb"]

## Uncomment this if you want to use Python < 3.10
# required-imports = [
# "from __future__ import annotations",
# ]

[tool.ruff.lint.flake8-tidy-imports]
# Ban certain modules from being imported at module level, instead requiring
# that they're imported lazily (e.g., within a function definition, if TYPE_CHECKING, etc.)
# NOTE: Ruff code TID is currently disabled, so this settings doesn't do anything.
banned-module-level-imports = ["torch", "tensorflow"]

[tool.ruff.lint.pylint]
max-args = 10
max-bool-expr = 10
max-statements = 100

[tool.pyright]
include = ["src"]

typeCheckingMode = "standard"
useLibraryCodeForTypes = true
autoImportCompletions = true

# pythonPlatform = "Linux"
115 changes: 0 additions & 115 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,118 +31,3 @@ keywords = ["biology"]

[tool.setuptools.packages.find]
where = ["src"]

[tool.pytest.ini_options]
addopts = "--cov=ml_project" # CHANGE (name of the importing module name)
testpaths = ["tests"]

[tool.ruff]
src = ["src"] # for ruff isort
namespace-packages = ["tools", "scripts"] # for INP rule, suppress on these directories

[tool.ruff.lint]
# OPTIONALLY ADD MORE LATER
select = [
# flake8
"E",
"F",
"W",
"B", # Bugbear
"D", # Docstring
"D213", # Multi-line docstring summary should start at the second line (replace D212)
"N", # Naming
"C4", # flake8-comprehensions
"UP", # pyupgrade
"SIM", # simplify
"RUF", # ruff-specific
"RET501", # return
"RET502", # return
"RET503", # return
"PTH", # path
"NPY", # numpy
"PD", # pandas
"PYI", # type stubs for pyright/pylance
"PT", # pytest
"PIE", #
"LOG", # logging
"COM818", # comma misplaced
"COM819", # comma
"DTZ", # datetime
"YTT",
"ASYNC",
"FBT", # boolean trap
"A", # Shadowing python builtins
"EXE", # executable (shebang)
"FA", # future annotations
"ISC", # Implicit string concatenation
"ICN", # Import convention
"INP", # Implicit namespace package (no __init__.py)
"Q", # Quotes
"RSE", # raise
"SLOT", # __slots__
"PL", # Pylint
"TRY", # try
"FAST", # FastAPI
"AIR", # airflow
"DOC", # docstring

# Not important
"T10", # debug statements
"T20", # print statements
]

ignore = [
"E402", # Module level import not at top of file
"W293", # Blank line contains whitespace
"W291", # Trailing whitespace
"D10", # Missing docstring in public module / function / etc.
"D200", # One-line docstring should fit on one line with quotes
"D212", # Multi-line docstring summary should start at the first line
"D417", # require documentation for every function parameter.
"D401", # require an imperative mood for all docstrings.
"DOC201", # missing Return field in docstring
"PTH123", # Path.open should be used instead of built-in open
"PT006", # Pytest parameterize style
"N812", # Lowercase `functional` imported as non-lowercase `F` (import torch.nn.functional as F)
"NPY002", # legacy numpy random
"UP017", # datetime.timezone.utc -> datetime.UTC
"SIM108", # use ternary operator instead of if-else
"TRY003", # long message in except
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.pycodestyle]
# Black or ruff will enforce line length to be 88, except for docstrings and comments.
# We set it to 120 so we have more space for docstrings and comments.
max-line-length = 120

[tool.ruff.lint.isort]
# combine-as-imports = true
known-third-party = ["wandb"]

## Uncomment this if you want to use Python < 3.10
# required-imports = [
# "from __future__ import annotations",
# ]

[tool.ruff.lint.flake8-tidy-imports]
# Ban certain modules from being imported at module level, instead requiring
# that they're imported lazily (e.g., within a function definition, if TYPE_CHECKING, etc.)
# NOTE: Ruff code TID is currently disabled, so this settings doesn't do anything.
banned-module-level-imports = ["torch", "tensorflow"]

[tool.ruff.lint.pylint]
max-args = 10
max-bool-expr = 10
max-statements = 100

[tool.pyright]
include = ["src"]

typeCheckingMode = "standard"
useLibraryCodeForTypes = true
autoImportCompletions = true

# pythonPlatform = "Linux"
122 changes: 75 additions & 47 deletions python/src/apbs_binary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,79 @@
import os
from pathlib import Path

BIN_DIR = Path(__file__).parent / "bin"
# NOTE: lib/ only exists for macos arm64, because we built using homebrew
# and it didn't build entirely statically.
# Thus we have to pass DYLD_LIBRARY_PATH to the subprocess.run call.
LIB_DIR = Path(__file__).parent / "lib"


def bin_path(bin_name: str) -> Path:
if os.name == "nt":
return BIN_DIR / f"{bin_name}.exe"
return BIN_DIR / bin_name


# bin/
APBS_BIN_PATH = bin_path("apbs")

# originally share/apbs/tools/bin/, but moved to bin/
ANALYSIS_BIN_PATH = bin_path("analysis")
BENCHMARK_BIN_PATH = bin_path("benchmark")
BORN_BIN_PATH = bin_path("born")
COULOMB_BIN_PATH = bin_path("coulomb")
DEL2DX_BIN_PATH = bin_path("del2dx")
DX2MOL_BIN_PATH = bin_path("dx2mol")
DX2UHBD_BIN_PATH = bin_path("dx2uhbd")
DXMATH_BIN_PATH = bin_path("dxmath")
MERGEDX_BIN_PATH = bin_path("mergedx")
MERGEDX2_BIN_PATH = bin_path("mergedx2")
MGMESH_BIN_PATH = bin_path("mgmesh")
MULTIVALUE_BIN_PATH = bin_path("multivalue")
SIMILARITY_BIN_PATH = bin_path("similarity")
SMOOTH_BIN_PATH = bin_path("smooth")
TENSOR2DX_BIN_PATH = bin_path("tensor2dx")
UHBD_ASC2BIN_BIN_PATH = bin_path("uhbd_asc2bin")
VALUE_BIN_PATH = bin_path("value")


from .executable import (
ANALYSIS_BIN_PATH,
APBS_BIN_PATH,
BENCHMARK_BIN_PATH,
BIN_DIR,
BORN_BIN_PATH,
COULOMB_BIN_PATH,
DEL2DX_BIN_PATH,
DX2MOL_BIN_PATH,
DX2UHBD_BIN_PATH,
DXMATH_BIN_PATH,
MERGEDX2_BIN_PATH,
MERGEDX_BIN_PATH,
MGMESH_BIN_PATH,
MULTIVALUE_BIN_PATH,
SIMILARITY_BIN_PATH,
SMOOTH_BIN_PATH,
TENSOR2DX_BIN_PATH,
UHBD_ASC2BIN_BIN_PATH,
VALUE_BIN_PATH,
apbs,
multivalue,
process_run,
popen_analysis,
popen_apbs,
popen_benchmark,
popen_born,
popen_coulomb,
popen_del2dx,
popen_dx2mol,
popen_dx2uhbd,
popen_dxmath,
popen_mergedx,
popen_mergedx2,
popen_mgmesh,
popen_multivalue,
popen_similarity,
popen_smooth,
popen_tensor2dx,
popen_uhbd_asc2bin,
popen_value,
run_analysis,
run_apbs,
run_benchmark,
run_born,
run_coulomb,
run_del2dx,
run_dx2mol,
run_dx2uhbd,
run_dxmath,
run_mergedx,
run_mergedx2,
run_mgmesh,
run_multivalue,
run_similarity,
run_smooth,
run_tensor2dx,
run_uhbd_asc2bin,
run_value,
)

__version__ = "0.0.0"

__all__ = [
"ANALYSIS_BIN_PATH",
"APBS_BIN_PATH",
"BENCHMARK_BIN_PATH",
"BIN_DIR",
"BORN_BIN_PATH",
"COULOMB_BIN_PATH",
"DEL2DX_BIN_PATH",
"DX2MOL_BIN_PATH",
"DX2UHBD_BIN_PATH",
"DXMATH_BIN_PATH",
"MERGEDX2_BIN_PATH",
"MERGEDX_BIN_PATH",
"MGMESH_BIN_PATH",
"MULTIVALUE_BIN_PATH",
"SIMILARITY_BIN_PATH",
"SMOOTH_BIN_PATH",
"TENSOR2DX_BIN_PATH",
"UHBD_ASC2BIN_BIN_PATH",
"VALUE_BIN_PATH",
"apbs",
"multivalue",
"process_run",
]
Loading

0 comments on commit 456ca72

Please sign in to comment.