Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap to ruff and setuptools-scm #112

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 10 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
repos:
- repo: local
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: isort
name: "[Package] Import formatting"
language: system
entry: isort
files: \.py$

- id: black
name: "[Package] Code formatting"
language: system
entry: black
files: \.py$
- id: trailing-whitespace
- id: end-of-file-fixer

- id: flake8
name: "[Package] Linting"
- repo: local
hooks:
- id: ruff
name: Autoformat python code
language: system
entry: flake8
entry: ruff
args: [check]
files: \.py$

- id: isort-examples
name: "[Examples] Import formatting"
language: system
entry: nbqa isort
files: examples/.+\.ipynb$

- id: black-examples
name: "[Examples] Code formatting"
language: system
entry: nbqa black
files: examples/.+\.ipynb$

- id: flake8-examples
name: "[Examples] Linting"
language: system
entry: nbqa flake8 --ignore=E402
files: examples/.+\.ipynb$
25 changes: 8 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@ CONDA_ENV_RUN := conda run --no-capture-output --name $(PACKAGE_NAME)
EXAMPLES_SKIP := examples/md-simulations.ipynb
EXAMPLES := $(filter-out $(EXAMPLES_SKIP), $(wildcard examples/*.ipynb))

.PHONY: pip-install env lint format test test-examples docs-build docs-deploy docs-insiders

pip-install:
$(CONDA_ENV_RUN) pip install --no-build-isolation --no-deps -e .
.PHONY: env lint format test test-examples docs-build docs-deploy docs-insiders

env:
mamba create --name $(PACKAGE_NAME)
mamba env update --name $(PACKAGE_NAME) --file devtools/envs/base.yaml
$(CONDA_ENV_RUN) pip install --no-build-isolation --no-deps -e .
$(CONDA_ENV_RUN) pip install --no-deps -e .
$(CONDA_ENV_RUN) pre-commit install || true

lint:
$(CONDA_ENV_RUN) isort --check-only $(PACKAGE_NAME)
$(CONDA_ENV_RUN) black --check $(PACKAGE_NAME)
$(CONDA_ENV_RUN) flake8 $(PACKAGE_NAME)
$(CONDA_ENV_RUN) nbqa isort --check-only examples
$(CONDA_ENV_RUN) nbqa black --check examples
$(CONDA_ENV_RUN) nbqa flake8 --ignore=E402 examples
$(CONDA_ENV_RUN) ruff check $(PACKAGE_NAME)
$(CONDA_ENV_RUN) ruff check examples

format:
$(CONDA_ENV_RUN) isort $(PACKAGE_NAME)
$(CONDA_ENV_RUN) black $(PACKAGE_NAME)
$(CONDA_ENV_RUN) flake8 $(PACKAGE_NAME)
$(CONDA_ENV_RUN) nbqa isort examples
$(CONDA_ENV_RUN) nbqa black examples
$(CONDA_ENV_RUN) nbqa flake8 --ignore=E402 examples
$(CONDA_ENV_RUN) ruff format $(PACKAGE_NAME)
$(CONDA_ENV_RUN) ruff check --fix --select I $(PACKAGE_NAME)
$(CONDA_ENV_RUN) ruff format examples
$(CONDA_ENV_RUN) ruff check --fix --select I examples

test:
$(CONDA_ENV_RUN) pytest -v --cov=$(PACKAGE_NAME) --cov-report=xml --color=yes $(PACKAGE_NAME)/tests/
Expand Down
7 changes: 2 additions & 5 deletions devtools/envs/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ dependencies:
- scipy # test logsumexp implementation
- smirnoff-plugins

- versioneer
- setuptools_scm >=8

- pre-commit
- isort
- black
- flake8
- flake8-pyproject
- ruff
- nbqa

- pytest
Expand Down
4 changes: 2 additions & 2 deletions examples/parameter-gradients.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@
"energy.backward()\n",
"\n",
"for parameter_key, gradient in zip(\n",
" vdw_potential.parameter_keys, vdw_potential.parameters.grad.numpy()\n",
" vdw_potential.parameter_keys, vdw_potential.parameters.grad.numpy(), strict=True\n",
"):\n",
" parameter_cols = vdw_potential.parameter_cols\n",
"\n",
" parameter_grads = \", \".join(\n",
" f\"dU/d{parameter_col} = {parameter_grad: 8.3f}\"\n",
" for parameter_col, parameter_grad in zip(parameter_cols, gradient)\n",
" for parameter_col, parameter_grad in zip(parameter_cols, gradient, strict=True)\n",
" )\n",
" print(f\"{parameter_key.id.ljust(15)} - {parameter_grads}\")"
],
Expand Down
41 changes: 13 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61.0", "wheel", "versioneer"]
requires = ["setuptools>=61.0", "setuptools_scm>=8", "wheel"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -12,35 +12,20 @@ readme = "README.md"
requires-python = ">=3.10"
classifiers = ["Programming Language :: Python :: 3"]

[tool.setuptools]
zip-safe = false
include-package-data = true
[tool.setuptools.packages.find]
include = ["smee*"]

[tool.setuptools.dynamic]
version = {attr = "smee.__version__"}
[tool.setuptools_scm]

[tool.setuptools.packages.find]
namespaces = true
where = ["."]

[tool.versioneer]
VCS = "git"
style = "pep440"
versionfile_source = "smee/_version.py"
versionfile_build = "smee/_version.py"
tag_prefix = ""
parentdir_prefix = "smee-"

[tool.black]
line-length = 88

[tool.isort]
profile = "black"

[tool.flake8]
max-line-length = 88
ignore = ["E203", "E266", "E501", "W503"]
select = ["B","C","E","F","W","T4","B9"]
[tool.ruff]
extend-include = ["*.ipynb"]

[tool.ruff.lint]
ignore = ["C901","E402","E501"]
select = ["B","C","E","F","W","B9"]

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

[tool.coverage.run]
omit = ["**/tests/*", "**/_version.py"]
Expand Down
8 changes: 6 additions & 2 deletions smee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Differentiably evaluate energies of molecules using SMIRNOFF force fields
"""

from . import _version
import importlib.metadata

from ._constants import CUTOFF_ATTRIBUTE, SWITCH_ATTRIBUTE, EnergyFn, PotentialType
from ._models import (
NonbondedParameterMap,
Expand All @@ -21,7 +22,10 @@
from .geometry import add_v_site_coords, compute_v_site_coords
from .potentials import compute_energy, compute_energy_potential

__version__ = _version.get_versions()["version"]
try:
__version__ = importlib.metadata.version("smee")
except importlib.metadata.PackageNotFoundError:
__version__ = "0+unknown"

__all__ = [
"CUTOFF_ATTRIBUTE",
Expand Down
4 changes: 2 additions & 2 deletions smee/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ def n_atoms(self) -> int:
"""The number of atoms in the system."""
return sum(
topology.n_atoms * n_copies
for topology, n_copies in zip(self.topologies, self.n_copies)
for topology, n_copies in zip(self.topologies, self.n_copies, strict=True)
)

@property
def n_v_sites(self) -> int:
"""The number of v-sites in the system."""
return sum(
topology.n_v_sites * n_copies
for topology, n_copies in zip(self.topologies, self.n_copies)
for topology, n_copies in zip(self.topologies, self.n_copies, strict=True)
)

@property
Expand Down
Loading
Loading