Skip to content

Commit

Permalink
Run doctests in pytest. Add linters to pre-commit. Add a pre-commit w…
Browse files Browse the repository at this point in the history
…orkflow. (#96)

- Adds doctests for pyi and md files.
- Pulls pytest arguments used in build / test workflows into
pyproject.toml.
- Adds [ruff](https://docs.astral.sh/ruff/) and
[rustfmt](https://github.com/rust-lang/rustfmt) checks to pre-commit.
- Adds a pre-commit check workflow that runs on PRs into main.
  • Loading branch information
aliddell authored Dec 13, 2023
1 parent 2f3ec2a commit c04f714
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 128 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run pre-commit

on:
pull_request:
push:
branches: [ main ]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install
run: |
pip install --upgrade pip
pip install -e '.[testing]'
- name: Run pre-commit
uses: pre-commit/[email protected]
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ jobs:

- name: Test artifact
run: |
python -m pytest -k test_basic --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0
python -m pytest -k test_zarr --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0
python -m pytest -k test_basic
python -m pytest -k test_zarr
- name: Upload wheels
uses: actions/upload-artifact@v3
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ jobs:
ZARR_V3_EXPERIMENTAL_API: "1"
ZARR_V3_SHARDING: "1"
run: |
python -m pytest -k test_basic --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0
python -m pytest -k test_zarr --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0
python -m pytest -k test_basic
python -m pytest -k test_zarr
dcam:
name: Python ${{ matrix.python }} (DCAM)
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
- name: Test
run: |
python -m pytest -k test_dcam --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0
python -m pytest -k test_dcam
egrabber:
name: Python ${{ matrix.python }} (eGrabber)
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
- name: Test
run: |
python -m pytest -k test_egrabber --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0
python -m pytest -k test_egrabber
spinnaker:
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
- name: Test
run: |
python -m pytest -k test_spinnaker --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0
python -m pytest -k test_spinnaker
typing:
Expand Down
42 changes: 28 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
repos:
- repo: https://github.com/psf/black
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
pass_filenames: true
- repo: https://github.com/PyCQA/flake8
- id: black
pass_filenames: true
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports]
pass_filenames: true
exclude: __init__.py
- repo: https://github.com/asottile/pyupgrade
- id: flake8
additional_dependencies: [ flake8-typing-imports ]
pass_filenames: true
exclude: __init__.py
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: ["--py38-plus", "--keep-runtime-typing"]
- repo: https://github.com/seddonym/import-linter
- id: pyupgrade
args: [ "--py38-plus", "--keep-runtime-typing" ]
- repo: https://github.com/seddonym/import-linter
rev: v1.2.7
hooks:
- id: import-linter
stages: [manual]
- id: import-linter
stages: [ manual ]
- repo: local
hooks:
- id: ruff
name: Lint Python files
entry: python -m ruff check .
language: system
types: [ file ]
files: \.py$
- id: cargo-fmt
name: Format Rust files
entry: cargo fmt --all -- --check
language: system
types: [ file ]
files: \.rs$
13 changes: 12 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ testing = [
"zarr",
"dask",
"ome-zarr",
"ruff",
]

[project.entry-points."napari.manifest"]
Expand Down Expand Up @@ -57,7 +58,17 @@ profile = "black"

[tool.pytest.ini_options]
minversion = "7.0"
addopts = "--tb=short -s"
addopts = '--tb=short -s --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0 --doctest-glob="*.pyi" --doctest-glob="*.md"'
# log_format = "%(asctime)s %(levelname)s %(message)s"
# log_date_format = "%Y-%m-%d %H:%M:%S"
log_cli = true # when true, messages are printed immediately

[tool.ruff]
exclude = [
"__init__.py"
]

ignore = [
"F403",
"F405",
]
2 changes: 1 addition & 1 deletion python/acquire/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from typing import List, Optional, Union

import napari # type: ignore

from .acquire import *
from .acquire import Runtime, Properties

def setup(
runtime: Runtime,
Expand Down
68 changes: 33 additions & 35 deletions python/acquire/acquire.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ class DeviceIdentifier:

@final
class DeviceKind:
Camera: ClassVar[DeviceKind] = DeviceKind.Camera
NONE: ClassVar[DeviceKind] = DeviceKind.NONE
Signals: ClassVar[DeviceKind] = DeviceKind.Signals
StageAxis: ClassVar[DeviceKind] = DeviceKind.StageAxis
Storage: ClassVar[DeviceKind] = DeviceKind.Storage
Camera: ClassVar[DeviceKind]
NONE: ClassVar[DeviceKind]
Signals: ClassVar[DeviceKind]
StageAxis: ClassVar[DeviceKind]
Storage: ClassVar[DeviceKind]
def __init__(self, *args: None, **kwargs: Any) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
Expand All @@ -120,12 +120,10 @@ class DeviceManager:

@final
class DeviceState:
Closed: ClassVar[DeviceState] = DeviceState.Closed
AwaitingConfiguration: ClassVar[
DeviceState
] = DeviceState.AwaitingConfiguration
Armed: ClassVar[DeviceState] = DeviceState.Armed
Running: ClassVar[DeviceState] = DeviceState.Running
Closed: ClassVar[DeviceState]
AwaitingConfiguration: ClassVar[DeviceState]
Armed: ClassVar[DeviceState]
Running: ClassVar[DeviceState]
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
Expand All @@ -142,8 +140,8 @@ class DigitalLineCapabilities:

@final
class Direction:
Backward: ClassVar[Direction] = Direction.Backward
Forward: ClassVar[Direction] = Direction.Forward
Backward: ClassVar[Direction]
Forward: ClassVar[Direction]
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
Expand Down Expand Up @@ -196,10 +194,10 @@ class Property:

@final
class PropertyType:
FixedPrecision: ClassVar[PropertyType] = PropertyType.FixedPrecision
FloatingPrecision: ClassVar[PropertyType] = PropertyType.FloatingPrecision
Enum: ClassVar[PropertyType] = PropertyType.Enum
String: ClassVar[PropertyType] = PropertyType.String
FixedPrecision: ClassVar[PropertyType]
FloatingPrecision: ClassVar[PropertyType]
Enum: ClassVar[PropertyType]
String: ClassVar[PropertyType]
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
Expand Down Expand Up @@ -237,14 +235,14 @@ class SampleRateHz:

@final
class SampleType:
F32: ClassVar[SampleType] = SampleType.F32
I16: ClassVar[SampleType] = SampleType.I16
I8: ClassVar[SampleType] = SampleType.I8
U16: ClassVar[SampleType] = SampleType.U16
U8: ClassVar[SampleType] = SampleType.U8
U10: ClassVar[SampleType] = SampleType.U10
U12: ClassVar[SampleType] = SampleType.U12
U14: ClassVar[SampleType] = SampleType.U14
F32: ClassVar[SampleType]
I16: ClassVar[SampleType]
I8: ClassVar[SampleType]
U16: ClassVar[SampleType]
U8: ClassVar[SampleType]
U10: ClassVar[SampleType]
U12: ClassVar[SampleType]
U14: ClassVar[SampleType]
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
Expand All @@ -270,8 +268,8 @@ class ShardingCapabilities:

@final
class SignalIOKind:
Input: ClassVar[SignalIOKind] = SignalIOKind.Input
Output: ClassVar[SignalIOKind] = SignalIOKind.Output
Input: ClassVar[SignalIOKind]
Output: ClassVar[SignalIOKind]
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
Expand All @@ -282,8 +280,8 @@ class SignalIOKind:

@final
class SignalType:
Analog: ClassVar[SignalType] = SignalType.Analog
Digital: ClassVar[SignalType] = SignalType.Digital
Analog: ClassVar[SignalType]
Digital: ClassVar[SignalType]
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
Expand Down Expand Up @@ -334,12 +332,12 @@ class TriggerCapabilities:

@final
class TriggerEdge:
Falling: ClassVar[TriggerEdge] = TriggerEdge.Falling
NotApplicable: ClassVar[TriggerEdge] = TriggerEdge.NotApplicable
Rising: ClassVar[TriggerEdge] = TriggerEdge.Rising
AnyEdge: ClassVar[TriggerEdge] = TriggerEdge.AnyEdge
LevelLow: ClassVar[TriggerEdge] = TriggerEdge.LevelLow
LevelHigh: ClassVar[TriggerEdge] = TriggerEdge.LevelHigh
Falling: ClassVar[TriggerEdge]
NotApplicable: ClassVar[TriggerEdge]
Rising: ClassVar[TriggerEdge]
AnyEdge: ClassVar[TriggerEdge]
LevelLow: ClassVar[TriggerEdge]
LevelHigh: ClassVar[TriggerEdge]
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
Expand Down
Loading

0 comments on commit c04f714

Please sign in to comment.