Skip to content

Commit

Permalink
Fix import and formatting issues in multiple files (#11)
Browse files Browse the repository at this point in the history
* Fix import and formatting issues in multiple files

* updates

* style(pre-commit.ci): auto fixes [...]

* unsafe fixes

* upda

* fix test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
tlambert03 and pre-commit-ci[bot] authored Apr 5, 2024
1 parent e68b9b5 commit ae759e9
Show file tree
Hide file tree
Showing 25 changed files with 180 additions and 104 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ on:
pull_request:
workflow_dispatch:
schedule:
# run every week (for --pre release tests)
- cron: "0 0 * * 0"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-manifest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx run check-manifest

test:
Expand All @@ -24,16 +29,11 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
platform: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: 🐍 Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand All @@ -51,7 +51,6 @@ jobs:
- name: 🧪 Run Tests
run: pytest --color=yes --cov --cov-report=xml --cov-report=term-missing

# If something goes wrong with --pre tests, we can open an issue in the repo
- name: 📝 Report --pre Failures
if: failure() && github.event_name == 'schedule'
uses: JasonEtco/create-an-issue@v2
Expand All @@ -74,8 +73,12 @@ jobs:
if: success() && startsWith(github.ref, 'refs/tags/') && github.event_name != 'schedule'
runs-on: ubuntu-latest

permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -91,9 +94,8 @@ jobs:
- name: 🚢 Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TWINE_API_KEY }}

- uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: './dist/*'
19 changes: 10 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ ci:

repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.2
rev: v0.16
hooks:
- id: validate-pyproject

# - repo: https://github.com/crate-ci/typos
# rev: v1.20.4
# hooks:
# - id: typos

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.265
rev: v0.3.5
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--fix, --unsafe-fixes]
- id: ruff-format

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.2.0
# rev: v1.9.0
# hooks:
# - id: mypy
# files: "^src/"
Expand Down
1 change: 1 addition & 0 deletions examples/illum_widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import napari
from magicgui import magicgui

from microsim.models._illum import structillum_2d

v = napari.Viewer()
Expand Down
52 changes: 27 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ build-backend = "hatchling.build"
[tool.hatch.version]
source = "vcs"

# https://hatch.pypa.io/latest/config/build/
[tool.hatch.build.targets.wheel]
only-include = ["src"]
sources = ["src"]

# [tool.hatch.build.targets.wheel.hooks.mypyc]
# mypy-args = ["--ignore-missing-imports"]
# dependencies = ["hatch-mypyc>=0.13.0"]
Expand All @@ -22,12 +27,13 @@ license = { text = "BSD-3-Clause" }
authors = [{ name = "Talley Lambert", email = "[email protected]" }]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.12",
"Typing :: Typed",
]
# add your package dependencies here
Expand All @@ -44,14 +50,7 @@ dependencies = [
# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
[project.optional-dependencies]
test = ["pytest", "pytest-cov"]
dev = [
"black",
"ipython",
"mypy",
"pdbpp", # https://github.com/pdbpp/pdbpp
"rich", # https://github.com/Textualize/rich
"ruff",
]
dev = ["ipython", "mypy", "pdbpp", "rich", "ruff", "pre-commit"]

[project.urls]
homepage = "https://github.com/tlambert03/microsim"
Expand All @@ -60,35 +59,35 @@ repository = "https://github.com/tlambert03/microsim"
[tool.ruff]
line-length = 88
target-version = "py38"
# https://beta.ruff.rs/docs/rules/
src = ["src"]

[tool.ruff.lint]
pydocstyle = { convention = "numpy" }
select = [
"E", # style errors
"W", # style warnings
"F", # flakes
# "D", # pydocstyle
"E", # style errors
"W", # style warnings
"F", # flakes
"D", # pydocstyle
"D417", # Missing argument descriptions in Docstrings
"I", # isort
"S",
"UP", # pyupgrade
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"A001", # flake8-builtins
"RUF", # ruff-specific rules
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
]
ignore = [
"D100", # Missing docstring in public module
"D107", # Missing docstring in __init__
"D203", # 1 blank line required before class docstring
"D212", # Multi-line docstring summary should start at the first line
"D213", # Multi-line docstring summary should start at the second line
"D10", # Missing docstring in public ...
"D401", # First line should be in imperative mood
"D413", # Missing blank line after last section
"D416", # Section name should end with a colon
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["D", "S"]
"setup.py" = ["D"]


# https://mypy.readthedocs.io/en/stable/config_file.html
[tool.mypy]
files = "src/**/"
Expand All @@ -97,14 +96,15 @@ disallow_any_generics = false
disallow_subclassing_any = false
show_error_codes = true
pretty = true
plugins = "pydantic.mypy"

# [[tool.mypy.overrides]]
# module = ["numpy.*",]
# ignore_errors = true

# https://docs.pytest.org/en/6.2.x/customize.html
[tool.pytest.ini_options]
minversion = "6.0"
minversion = "7.0"
testpaths = ["tests"]
filterwarnings = ["error"]

Expand All @@ -117,9 +117,11 @@ exclude_lines = [
"except ImportError",
"\\.\\.\\.",
"raise NotImplementedError()",
"pass"
]

[tool.coverage.run]
source = ["src"]
source = ["microsim"]

# https://github.com/mgedmin/check-manifest#configuration
# add files that you want check-manifest to explicitly ignore here
Expand Down
1 change: 1 addition & 0 deletions src/microsim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Light microscopy simulation in python."""

from importlib.metadata import PackageNotFoundError, version

try:
Expand Down
8 changes: 5 additions & 3 deletions src/microsim/_operator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .models._renderable import Renderable
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from microsim.models._renderable import Renderable

def convolve(a, b) -> "Renderable":
...

def convolve(a, b) -> "Renderable": ...
22 changes: 13 additions & 9 deletions src/microsim/illum/_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from functools import lru_cache
from itertools import product
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Any, Iterable, Sequence

import numpy as np
from tqdm import tqdm
Expand Down Expand Up @@ -123,7 +123,9 @@ def create(self, shape: tuple[int, int, int], dz: float, dx: float) -> np.ndarra
print(out.shape, "out")
return out

def _render_plane(self, sim_plane, coords, theta, phase):
def _render_plane(
self, sim_plane: NDArray, coords: NDArray, theta: float, phase: float
) -> NDArray:
if map_coordinates.__module__.startswith("cupy"):
_i = []
CHUNKSIZE = 128 # TODO: determine better strategy
Expand All @@ -136,11 +138,11 @@ def _render_plane(self, sim_plane, coords, theta, phase):
img = map_coordinates(sim_plane, new_coords, order=1)
return img

def _map_coords(self, coords: np.ndarray, theta: float, phase: float) -> NDArray:
"""Map a set of image coordinates to new coords after phaseshift and rotation"""
def _map_coords(self, coords: NDArray, theta: float, phase: float) -> NDArray:
"""Map a set of img coordinates to new coords after phaseshift and rotation."""
matrix = self._get_matrix(theta, phase)
new_coordinates = (matrix[:-1, :-1] @ coords)[:2]
return new_coordinates + xp.expand_dims(xp.asarray(matrix[:2, -1]), -1)
return new_coordinates + xp.expand_dims(xp.asarray(matrix[:2, -1]), -1) # type: ignore

def _get_matrix(self, theta: float, phase: float) -> NDArray:
"""Get matrix to transform output coordinates to axial sim plane.
Expand Down Expand Up @@ -172,7 +174,7 @@ def _get_matrix(self, theta: float, phase: float) -> NDArray:
]
)

return scale @ translate @ rotate
return scale @ translate @ rotate # type: ignore


class SIMIllum3D(SIMIllum2D):
Expand All @@ -183,8 +185,8 @@ class SIMIllum3D(SIMIllum2D):
TAU = 1j * 2 * np.pi


def efield(kvec: tuple[float, float], zarr: NDArray, xarr: NDArray):
return xp.exp(TAU * (kvec[0] * xarr + kvec[1] * zarr))
def efield(kvec: tuple[float, float], zarr: NDArray, xarr: NDArray) -> NDArray:
return xp.exp(TAU * (kvec[0] * xarr + kvec[1] * zarr)) # type: ignore


@lru_cache(maxsize=128)
Expand Down Expand Up @@ -313,5 +315,7 @@ def structillum_2d(
return intensity


def _enumerated_product(*args):
def _enumerated_product(
*args: Any,
) -> Iterable[tuple[tuple[int, int], tuple[Any, ...]]]:
yield from zip(product(*(range(len(x)) for x in args)), product(*args))
2 changes: 1 addition & 1 deletion src/microsim/illum/_widefield.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..models import Illumination
from microsim.models import Illumination


class Widefield(Illumination):
Expand Down
8 changes: 3 additions & 5 deletions src/microsim/models/_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def simulate(
add_poisson : bool, optional
_description_, by default True
"""
from ..simulate import simulate_camera
from microsim.simulate import simulate_camera

return simulate_camera(
self, image, exposure, binning=binning, add_poisson=add_poisson
Expand All @@ -64,8 +64,7 @@ def quantize_electrons(self, total_electrons: np.ndarray) -> np.ndarray:
return np.round((voltage / self.adc_gain) + self.offset)


class CameraCCD(Camera):
...
class CameraCCD(Camera): ...


class CameraEMCCD(Camera):
Expand All @@ -86,8 +85,7 @@ def apply_em_gain(self, electron_image):
return np.minimum(electron_image, self.em_full_well)


class CameraCMOS(Camera):
...
class CameraCMOS(Camera): ...


ICX285 = CameraCCD(
Expand Down
Loading

0 comments on commit ae759e9

Please sign in to comment.