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

Run doctests in pytest. Add linters to pre-commit. Add a pre-commit workflow. #96

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9774ec4
add test_docs.py
aliddell Oct 6, 2023
0013842
doctest all python files
aliddell Oct 6, 2023
f8b98fa
add pre-commit.yml
aliddell Oct 6, 2023
9035cba
always_run: false, types are markdown, text, and python
aliddell Oct 6, 2023
82e293f
.md/.py
aliddell Oct 6, 2023
f13049a
remove doctest from pyproject.toml (part of the standard library �)
aliddell Oct 6, 2023
0d00968
check rust files in doctests
aliddell Oct 6, 2023
03245c8
Install dependencies for pre-commit workflow
aliddell Oct 6, 2023
cf6ee4d
don't forget test_rust_sources
aliddell Oct 6, 2023
edd81ab
reformat test_spinnaker.py
aliddell Oct 6, 2023
0961751
add ruff and cargo-fmt to pre-commit
aliddell Oct 9, 2023
39d81fe
remove 'triggered' label from 'Finite triggered acquisition'
aliddell Oct 9, 2023
5f1452e
install ruff with testing dependencies
aliddell Oct 9, 2023
8b4f482
wip
aliddell Oct 9, 2023
a9c8135
wip
aliddell Oct 9, 2023
5690cd7
wip
aliddell Oct 9, 2023
419b48d
skip .pyi files when ruff linting
aliddell Oct 9, 2023
07a3fcb
permit from acquire import * in __init__.py, instruct ruff to ignore it.
aliddell Oct 9, 2023
199ccb0
Update doctest name
aliddell Oct 9, 2023
b6fbf45
update submodules
aliddell Nov 15, 2023
565c78e
Remove doctests from pre-commit. Add them to test_pr.yml. Check .pyi …
aliddell Nov 15, 2023
f74b2bc
Revert "update submodules"
aliddell Nov 15, 2023
e0ef3b3
Merge remote-tracking branch 'upstream/main' into 92-run-tests-on-doc…
aliddell Dec 12, 2023
e6fced1
Cargo format.
aliddell Dec 12, 2023
dfbfaab
Update ruff config to ignore __init__.py (from .acquire import *) is …
aliddell Dec 12, 2023
afcfa05
Fix pyi files to make ruff happy.
aliddell Dec 12, 2023
f3b6a43
Update pre-commit job name.
aliddell Dec 12, 2023
a5c0718
Remove test_docs.py. Update `add_opts` entry in pytest config. Trunca…
aliddell Dec 12, 2023
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
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/action@v3.0.0
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",
]
Comment on lines +67 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK to start with these excludes and ignores, though I'd prefer to have none of them in the long term.

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
Loading