From 9774ec4193610909c6727084cb784374c42abee8 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 15:53:09 -0400 Subject: [PATCH 01/27] add test_docs.py --- .pre-commit-config.yaml | 8 +++++++- tests/test_docs.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/test_docs.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 78b0c03..d94975b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,4 +20,10 @@ repos: rev: v1.2.7 hooks: - id: import-linter - stages: [manual] \ No newline at end of file + stages: [manual] +- repo: local + hooks: + - id: doctest + name: Document tests + entry: python tests/test_docs.py + language: system diff --git a/tests/test_docs.py b/tests/test_docs.py new file mode 100644 index 0000000..f05fb46 --- /dev/null +++ b/tests/test_docs.py @@ -0,0 +1,20 @@ +import doctest + +from pathlib import Path + + +def test_readme(): + readme_path = Path(__file__).parent.parent / "README.md" + assert ( + doctest.testfile(str(readme_path), module_relative=False).failed == 0 + ) + + +def test_modules(): + assert doctest.testmod().failed == 0 + + +if __name__ == "__main__": + test_readme() + test_modules() + print("Done.") From 0013842401dce4e5519c6ff89e3571a9d6923f48 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 16:12:09 -0400 Subject: [PATCH 02/27] doctest all python files --- README.md | 44 ++++++++++++++++++++++---------------------- pyproject.toml | 1 + tests/test_docs.py | 20 ++++++++++++++------ 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 626bb29..8cb9a7a 100644 --- a/README.md +++ b/README.md @@ -35,31 +35,30 @@ The provided [napari][] plugin is a good example of how to stream for visualizat ### List devices -```python -import acquire -print(acquire.Runtime().device_manager().devices()) +```python-repl +>>> import acquire +>>> print(acquire.Runtime().device_manager().devices()) # doctest: +SKIP ``` ### Finite triggered acquisition -```python -import acquire -runtime = acquire.Runtime() -dm = runtime.device_manager() - -props = runtime.get_configuration() -# select the first Hamamatsu camera -props.video[0].camera.identifier = dm.select(DeviceKind.Camera, "hamamatsu.*") -# stream to zarr -props.video[0].storage.identifier = dm.select(DeviceKind.Storage, "zarr") -props.video[0].storage.settings.filename = "out.zarr" -props.video[0].camera.settings.shape = (2304, 2304) -props.video[0].camera.settings.pixel_type = SampleType.U16 -props.video[0].max_frame_count = 100 -props = runtime.set_configuration(props) - -runtime.start() -runtime.stop() # wait for acquisition to complete +```python-repl +>>> import acquire +>>> runtime = acquire.Runtime() +>>> dm = runtime.device_manager() +>>> props = runtime.get_configuration() +>>> # select the first Hamamatsu camera +>>> props.video[0].camera.identifier = dm.select(acquire.DeviceKind.Camera, "hamamatsu.*") +>>> # stream to zarr +>>> props.video[0].storage.identifier = dm.select(acquire.DeviceKind.Storage, "zarr") +>>> props.video[0].storage.settings.filename = "out.zarr" +>>> props.video[0].camera.settings.shape = (2304, 2304) +>>> props.video[0].camera.settings.pixel_type = acquire.SampleType.U16 +>>> props.video[0].max_frame_count = 100 +>>> props = runtime.set_configuration(props) +>>> runtime.start() # doctest: +SKIP +>>> # wait for acquisition to complete +>>> runtime.stop() # doctest: +SKIP ``` # Development @@ -122,7 +121,8 @@ In order to configure which release of each driver to use, you can set the value "acquire-driver-common": "0.1.0", "acquire-driver-hdcam": "0.1.0", "acquire-driver-egrabber": "0.1.0", - "acquire-driver-zarr": "0.1.0" + "acquire-driver-zarr": "0.1.0", + "acquire-driver-spinnaker": "0.1.0" } ``` diff --git a/pyproject.toml b/pyproject.toml index 0225aa2..ca35171 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ testing = [ "zarr", "dask", "ome-zarr", + "doctest", ] [project.entry-points."napari.manifest"] diff --git a/tests/test_docs.py b/tests/test_docs.py index f05fb46..d3614bf 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -1,20 +1,28 @@ import doctest +import pytest from pathlib import Path -def test_readme(): - readme_path = Path(__file__).parent.parent / "README.md" +@pytest.fixture(autouse=True) +def base_dir(): + return Path(__file__).parent.parent + + +def test_readme(base_dir): + readme_path = base_dir / "README.md" assert ( doctest.testfile(str(readme_path), module_relative=False).failed == 0 ) -def test_modules(): - assert doctest.testmod().failed == 0 +def test_modules(base_dir): + for module in base_dir.glob("python/**/*.py"): + assert doctest.testfile(str(module), module_relative=False).failed == 0 if __name__ == "__main__": - test_readme() - test_modules() + base = Path(__file__).parent.parent + test_readme(base) + test_modules(base) print("Done.") From f8b98fa9952eb6e48e712e19e40d16fa88e243b7 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 16:24:47 -0400 Subject: [PATCH 03/27] add pre-commit.yml --- .github/workflows/pre-commit.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..656c65e --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [ main ] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 \ No newline at end of file From 9035cba1514228332ba251299d23098413a7c625 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 16:42:27 -0400 Subject: [PATCH 04/27] always_run: false, types are markdown, text, and python --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d94975b..619e210 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,5 @@ repos: name: Document tests entry: python tests/test_docs.py language: system + types: [markdown, text, python] + always_run: false From 82e293fcedf78890b5495b87175f5190b8dd1b50 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 16:47:31 -0400 Subject: [PATCH 05/27] .md/.py --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 619e210..9bc1e89 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,5 +27,5 @@ repos: name: Document tests entry: python tests/test_docs.py language: system - types: [markdown, text, python] - always_run: false + types: [file] + files: \.(md|py)$ From f13049a9e8b96f4cd7dde09f5e2367f185068864 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 17:12:21 -0400 Subject: [PATCH 06/27] =?UTF-8?q?remove=20doctest=20from=20pyproject.toml?= =?UTF-8?q?=20(part=20of=20the=20standard=20library=20=EF=BF=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ca35171..0225aa2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,6 @@ testing = [ "zarr", "dask", "ome-zarr", - "doctest", ] [project.entry-points."napari.manifest"] From 0d00968993cfc6982c5b83c7311dd0df66bd51b0 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 17:14:53 -0400 Subject: [PATCH 07/27] check rust files in doctests --- .pre-commit-config.yaml | 2 +- tests/test_docs.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9bc1e89..fbed12c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,4 +28,4 @@ repos: entry: python tests/test_docs.py language: system types: [file] - files: \.(md|py)$ + files: \.(md|py|rs)$ diff --git a/tests/test_docs.py b/tests/test_docs.py index d3614bf..ae6a071 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -21,6 +21,11 @@ def test_modules(base_dir): assert doctest.testfile(str(module), module_relative=False).failed == 0 +def test_rust_sources(base_dir): + for f in base_dir.glob("src/**/*.rs"): + assert doctest.testfile(str(f), module_relative=False).failed == 0 + + if __name__ == "__main__": base = Path(__file__).parent.parent test_readme(base) From 03245c8416cc1ad217f09f8e85462ee290be1fe9 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 17:42:45 -0400 Subject: [PATCH 08/27] Install dependencies for pre-commit workflow --- .github/workflows/pre-commit.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 656c65e..476c3bf 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -10,5 +10,18 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - - uses: pre-commit/action@v3.0.0 \ No newline at end of file + 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 \ No newline at end of file From cf6ee4d9cdcc8b26ba05527624eee3fcb28d53d9 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 17:49:49 -0400 Subject: [PATCH 09/27] don't forget test_rust_sources --- tests/test_docs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_docs.py b/tests/test_docs.py index ae6a071..0bb2db4 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -30,4 +30,5 @@ def test_rust_sources(base_dir): base = Path(__file__).parent.parent test_readme(base) test_modules(base) + test_rust_sources(base) print("Done.") From edd81abd803a694428062213f7a2f2c9690f2017 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 6 Oct 2023 17:53:04 -0400 Subject: [PATCH 10/27] reformat test_spinnaker.py --- tests/test_spinnaker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_spinnaker.py b/tests/test_spinnaker.py index 10d7800..7c08be7 100644 --- a/tests/test_spinnaker.py +++ b/tests/test_spinnaker.py @@ -22,4 +22,4 @@ def test_blackfly_camera_is_present(runtime: acquire.Runtime): def test_oryx_camera_is_present(runtime: acquire.Runtime): dm = runtime.device_manager() - assert dm.select(DeviceKind.Camera, ".*ORX-10GS-51S5M.*") \ No newline at end of file + assert dm.select(DeviceKind.Camera, ".*ORX-10GS-51S5M.*") From 0961751e84925dcb8c4bdb98d8ea38805d53b380 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 11:05:23 -0400 Subject: [PATCH 11/27] add ruff and cargo-fmt to pre-commit --- .pre-commit-config.yaml | 12 ++++++++++++ python/acquire/__init__.py | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fbed12c..1e64cee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,3 +29,15 @@ repos: language: system types: [file] files: \.(md|py|rs)$ + - id: ruff + name: Lint Python files + entry: python -m ruff check python/acquire/*.py tests/*.py + language: system + types: [file] + files: \.py$ + - id: cargo-fmt + name: Format Rust files + entry: cargo fmt --all -- --check + language: system + types: [file] + files: \.rs$ diff --git a/python/acquire/__init__.py b/python/acquire/__init__.py index e76f3e8..05e65db 100644 --- a/python/acquire/__init__.py +++ b/python/acquire/__init__.py @@ -13,7 +13,12 @@ import numpy.typing as npt from . import acquire -from .acquire import * +from .acquire import ( + Runtime, + Properties, + DeviceKind, + SampleType, +) __doc__ = acquire.__doc__ From 39d81fe3ef547e8dbb5459ab66d9cd6687a102c3 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 11:08:34 -0400 Subject: [PATCH 12/27] remove 'triggered' label from 'Finite triggered acquisition' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8cb9a7a..300659e 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ The provided [napari][] plugin is a good example of how to stream for visualizat >>> print(acquire.Runtime().device_manager().devices()) # doctest: +SKIP ``` -### Finite triggered acquisition +### Finite acquisition ```python-repl >>> import acquire From 5f1452ed787ba030954bf8a4a3dbbc8b1eb5d771 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 11:42:29 -0400 Subject: [PATCH 13/27] install ruff with testing dependencies --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 0225aa2..85ee6ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ testing = [ "zarr", "dask", "ome-zarr", + "ruff", ] [project.entry-points."napari.manifest"] From 8b4f48207d8667ccfe7caaef45c2ced04f7ff220 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 12:01:39 -0400 Subject: [PATCH 14/27] wip --- .github/workflows/pre-commit.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 476c3bf..2f5a620 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -23,5 +23,12 @@ jobs: pip install --upgrade pip pip install -e '.[testing]' + - name: Tree + run: | + tree + pwd + shell: bash + working-directory: ${{ github.workspace }} + - name: Run pre-commit uses: pre-commit/action@v3.0.0 \ No newline at end of file From a9c813515ca8555ee3d6c82339061320aba44b63 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 12:09:14 -0400 Subject: [PATCH 15/27] wip --- .github/workflows/pre-commit.yml | 26 +++++++++++++------------- .pre-commit-config.yaml | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 2f5a620..33db9b0 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,22 +13,22 @@ jobs: 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: 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: Tree run: | - tree - pwd + ls python/acquire/*.py + ls tests/*.py shell: bash working-directory: ${{ github.workspace }} - - name: Run pre-commit - uses: pre-commit/action@v3.0.0 \ No newline at end of file +# - name: Run pre-commit +# uses: pre-commit/action@v3.0.0 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e64cee..b595fda 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,7 +31,7 @@ repos: files: \.(md|py|rs)$ - id: ruff name: Lint Python files - entry: python -m ruff check python/acquire/*.py tests/*.py + entry: python -m ruff check ./python/acquire/*.py ./tests/*.py language: system types: [file] files: \.py$ From 5690cd7cae0bff1724da571b2e375806f1c89097 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 12:25:33 -0400 Subject: [PATCH 16/27] wip --- .github/workflows/pre-commit.yml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 33db9b0..476c3bf 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,22 +13,15 @@ jobs: 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: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" - - name: Tree + - name: Install run: | - ls python/acquire/*.py - ls tests/*.py - shell: bash - working-directory: ${{ github.workspace }} + pip install --upgrade pip + pip install -e '.[testing]' -# - name: Run pre-commit -# uses: pre-commit/action@v3.0.0 \ No newline at end of file + - name: Run pre-commit + uses: pre-commit/action@v3.0.0 \ No newline at end of file From 419b48ddf89f26665cb770b7c66e99252bc71d3e Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 12:56:30 -0400 Subject: [PATCH 17/27] skip .pyi files when ruff linting --- .pre-commit-config.yaml | 52 ++++++++++++++++++++--------------------- pyproject.toml | 5 ++++ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b595fda..fd8aef9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,43 +1,43 @@ 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] -- repo: local + - id: import-linter + stages: [ manual ] + - repo: local hooks: - - id: doctest + - id: doctest name: Document tests entry: python tests/test_docs.py language: system - types: [file] + types: [ file ] files: \.(md|py|rs)$ - - id: ruff + - id: ruff name: Lint Python files - entry: python -m ruff check ./python/acquire/*.py ./tests/*.py + entry: python -m ruff check . language: system - types: [file] + types: [ file ] files: \.py$ - - id: cargo-fmt - name: Format Rust files - entry: cargo fmt --all -- --check - language: system - types: [file] - files: \.rs$ + - id: cargo-fmt + name: Format Rust files + entry: cargo fmt --all -- --check + language: system + types: [ file ] + files: \.rs$ diff --git a/pyproject.toml b/pyproject.toml index 85ee6ed..b5dbf34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,3 +62,8 @@ addopts = "--tb=short -s" # 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 = [ + "*.pyi" +] \ No newline at end of file From 07a3fcb67eafce97e4beb5399d4f88e554559e54 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 13:12:01 -0400 Subject: [PATCH 18/27] permit from acquire import * in __init__.py, instruct ruff to ignore it. --- pyproject.toml | 5 +++++ python/acquire/__init__.py | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b5dbf34..3196e05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,4 +66,9 @@ log_cli = true # when true, messages are printed immediately [tool.ruff] exclude = [ "*.pyi" +] + +ignore = [ + "F403", + "F405", ] \ No newline at end of file diff --git a/python/acquire/__init__.py b/python/acquire/__init__.py index 05e65db..e76f3e8 100644 --- a/python/acquire/__init__.py +++ b/python/acquire/__init__.py @@ -13,12 +13,7 @@ import numpy.typing as npt from . import acquire -from .acquire import ( - Runtime, - Properties, - DeviceKind, - SampleType, -) +from .acquire import * __doc__ = acquire.__doc__ From 199ccb06982c5dd5803e7c91ba94abf3692cbbec Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Mon, 9 Oct 2023 13:24:39 -0400 Subject: [PATCH 19/27] Update doctest name --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd8aef9..a1219ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - repo: local hooks: - id: doctest - name: Document tests + name: Run doctests entry: python tests/test_docs.py language: system types: [ file ] From b6fbf454ac808a4eb23b951a110e449c0e314155 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Wed, 15 Nov 2023 12:43:04 -0500 Subject: [PATCH 20/27] update submodules --- acquire-libs/acquire-core-libs | 2 +- acquire-libs/acquire-video-runtime | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/acquire-libs/acquire-core-libs b/acquire-libs/acquire-core-libs index 40e71b2..8bea9c8 160000 --- a/acquire-libs/acquire-core-libs +++ b/acquire-libs/acquire-core-libs @@ -1 +1 @@ -Subproject commit 40e71b2af97f8827be5d88352414365193145ed3 +Subproject commit 8bea9c8ab8806d481ae943d3577c9adcede98672 diff --git a/acquire-libs/acquire-video-runtime b/acquire-libs/acquire-video-runtime index b183ecf..fdacf7d 160000 --- a/acquire-libs/acquire-video-runtime +++ b/acquire-libs/acquire-video-runtime @@ -1 +1 @@ -Subproject commit b183ecfe2c0cd8a8b70fe6dbd6fdedff651534fa +Subproject commit fdacf7da3410b961027cbdf8adea4fb405f3fb25 From 565c78e37c79a169128c97f797f361a426163fc5 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Wed, 15 Nov 2023 14:28:32 -0500 Subject: [PATCH 21/27] Remove doctests from pre-commit. Add them to test_pr.yml. Check .pyi files. --- .github/workflows/test_pr.yml | 6 +++--- .pre-commit-config.yaml | 6 ------ tests/test_docs.py | 9 +++------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index ce2e764..92bd451 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -53,6 +53,7 @@ jobs: - name: Test 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_docs --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0 dcam: name: Python ${{ matrix.python }} (DCAM) @@ -98,7 +99,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 --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0 --doctest-glob="*.pyi" --doctest-glob="*.md" egrabber: name: Python ${{ matrix.python }} (eGrabber) @@ -144,8 +145,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 --color=yes --cov-report=xml --cov=acquire --maxfail=5 --log-cli-level=0 --doctest-glob="*.pyi" --doctest-glob="*.md" spinnaker: name: Python ${{ matrix.python }} (Spinnaker) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a1219ed..f27be6a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,12 +23,6 @@ repos: stages: [ manual ] - repo: local hooks: - - id: doctest - name: Run doctests - entry: python tests/test_docs.py - language: system - types: [ file ] - files: \.(md|py|rs)$ - id: ruff name: Lint Python files entry: python -m ruff check . diff --git a/tests/test_docs.py b/tests/test_docs.py index 0bb2db4..771552f 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -26,9 +26,6 @@ def test_rust_sources(base_dir): assert doctest.testfile(str(f), module_relative=False).failed == 0 -if __name__ == "__main__": - base = Path(__file__).parent.parent - test_readme(base) - test_modules(base) - test_rust_sources(base) - print("Done.") +def test_pyi_files(base_dir): + for f in base_dir.glob("python/**/*.pyi"): + assert doctest.testfile(str(f), module_relative=False).failed == 0 From f74b2bc6ffe6445c11e3223d2b19ea56421debef Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Wed, 15 Nov 2023 14:37:37 -0500 Subject: [PATCH 22/27] Revert "update submodules" This reverts commit b6fbf454ac808a4eb23b951a110e449c0e314155. --- acquire-libs/acquire-core-libs | 2 +- acquire-libs/acquire-video-runtime | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/acquire-libs/acquire-core-libs b/acquire-libs/acquire-core-libs index 8bea9c8..40e71b2 160000 --- a/acquire-libs/acquire-core-libs +++ b/acquire-libs/acquire-core-libs @@ -1 +1 @@ -Subproject commit 8bea9c8ab8806d481ae943d3577c9adcede98672 +Subproject commit 40e71b2af97f8827be5d88352414365193145ed3 diff --git a/acquire-libs/acquire-video-runtime b/acquire-libs/acquire-video-runtime index fdacf7d..b183ecf 160000 --- a/acquire-libs/acquire-video-runtime +++ b/acquire-libs/acquire-video-runtime @@ -1 +1 @@ -Subproject commit fdacf7da3410b961027cbdf8adea4fb405f3fb25 +Subproject commit b183ecfe2c0cd8a8b70fe6dbd6fdedff651534fa From e6fced1fcb3e94720476eda9cd5d817a75bf9a2f Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 12 Dec 2023 10:31:05 -0500 Subject: [PATCH 23/27] Cargo format. --- src/camera.rs | 62 +++++++++++++++++++------------------- src/capabilities.rs | 16 +++------- src/components/mod.rs | 4 +-- src/components/property.rs | 2 +- src/lib.rs | 2 +- src/runtime.rs | 5 +-- src/storage.rs | 56 +++++++++++++++++++++------------- 7 files changed, 78 insertions(+), 69 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 46e3769..638f851 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,10 +1,10 @@ use crate::{ capi, - components::{macros::impl_plain_old_dict, Property, Direction, SampleType, Trigger}, + components::{macros::impl_plain_old_dict, Direction, Property, SampleType, Trigger}, }; use pyo3::prelude::*; use serde::{Deserialize, Serialize}; -use std::ffi::{CStr, c_char, c_void}; +use std::ffi::{c_char, c_void, CStr}; #[pyclass] #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -289,7 +289,9 @@ impl Default for OffsetShapeCapabilities { } } -impl TryFrom for OffsetShapeCapabilities { +impl TryFrom + for OffsetShapeCapabilities +{ type Error = anyhow::Error; fn try_from( @@ -304,7 +306,9 @@ impl TryFrom f } } -impl TryFrom for OffsetShapeCapabilities { +impl TryFrom + for OffsetShapeCapabilities +{ type Error = anyhow::Error; fn try_from( @@ -341,7 +345,9 @@ impl Default for DigitalLineCapabilities { } } -impl TryFrom for DigitalLineCapabilities { +impl TryFrom + for DigitalLineCapabilities +{ type Error = anyhow::Error; fn try_from( @@ -350,7 +356,9 @@ impl TryFrom PyResult<_> { let mut names: [String; 8] = Default::default(); for (i, name) in value.names.iter().enumerate() { - let name = unsafe { CStr::from_ptr(name.as_ptr()) }.to_str()?.to_owned(); + let name = unsafe { CStr::from_ptr(name.as_ptr()) } + .to_str()? + .to_owned(); names[i] = name; } Ok(Self { @@ -565,7 +573,9 @@ impl Default for capi::CameraPropertyMetadata_camera_properties_metadata_offset_ } } -impl TryFrom<&OffsetShapeCapabilities> for capi::CameraPropertyMetadata_camera_properties_metadata_offset_s { +impl TryFrom<&OffsetShapeCapabilities> + for capi::CameraPropertyMetadata_camera_properties_metadata_offset_s +{ type Error = anyhow::Error; fn try_from(value: &OffsetShapeCapabilities) -> Result { @@ -587,7 +597,9 @@ impl Default for capi::CameraPropertyMetadata_camera_properties_metadata_shape_s } } -impl TryFrom<&OffsetShapeCapabilities> for capi::CameraPropertyMetadata_camera_properties_metadata_shape_s { +impl TryFrom<&OffsetShapeCapabilities> + for capi::CameraPropertyMetadata_camera_properties_metadata_shape_s +{ type Error = anyhow::Error; fn try_from(value: &OffsetShapeCapabilities) -> Result { @@ -605,33 +617,21 @@ impl Default for capi::CameraPropertyMetadata_CameraPropertyMetadataDigitalLineM Self { line_count: Default::default(), names: [ - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], + [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], ], } } } -impl TryFrom<&DigitalLineCapabilities> for capi::CameraPropertyMetadata_CameraPropertyMetadataDigitalLineMetadata { +impl TryFrom<&DigitalLineCapabilities> + for capi::CameraPropertyMetadata_CameraPropertyMetadataDigitalLineMetadata +{ type Error = anyhow::Error; fn try_from(value: &DigitalLineCapabilities) -> Result { Ok(Python::with_gil(|_| -> PyResult<_> { let mut names: [[c_char; 64]; 8] = [ - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], - [0; 64], + [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], [0; 64], ]; for (i, name) in value.names.iter().enumerate() { let name = std::ffi::CString::new(name.as_str())?; @@ -685,7 +685,9 @@ impl Default for capi::CameraPropertyMetadata_CameraPropertiesTriggerMetadata { } } -impl TryFrom<&TriggerCapabilities> for capi::CameraPropertyMetadata_CameraPropertiesTriggerMetadata { +impl TryFrom<&TriggerCapabilities> + for capi::CameraPropertyMetadata_CameraPropertiesTriggerMetadata +{ type Error = anyhow::Error; fn try_from(value: &TriggerCapabilities) -> Result { @@ -696,14 +698,12 @@ impl TryFrom<&TriggerCapabilities> for capi::CameraPropertyMetadata_CameraProper })?; let exposure = Python::with_gil(|py| -> PyResult<_> { - let exposure: TriggerInputOutputCapabilities = - value.exposure.extract(py)?; + let exposure: TriggerInputOutputCapabilities = value.exposure.extract(py)?; Ok(exposure) })?; let frame_start = Python::with_gil(|py| -> PyResult<_> { - let frame_start: TriggerInputOutputCapabilities = - value.frame_start.extract(py)?; + let frame_start: TriggerInputOutputCapabilities = value.frame_start.extract(py)?; Ok(frame_start) })?; @@ -772,4 +772,4 @@ impl TryFrom<&CameraCapabilities> for capi::CameraPropertyMetadata { triggers: (&triggers).try_into()?, }) } -} \ No newline at end of file +} diff --git a/src/capabilities.rs b/src/capabilities.rs index cbe5476..7d3c0e6 100644 --- a/src/capabilities.rs +++ b/src/capabilities.rs @@ -2,10 +2,10 @@ use pyo3::prelude::*; use serde::{Deserialize, Serialize}; use crate::{ - capi, - storage::StorageCapabilities, camera::CameraCapabilities, + capi, components::{macros::impl_plain_old_dict, Property}, + storage::StorageCapabilities, }; #[pyclass] @@ -88,10 +88,7 @@ impl TryFrom<&capi::AcquirePropertyMetadata> for Capabilities { (value.video[0].try_into()?, value.video[1].try_into()?); Ok(Self { - video: ( - Py::new(py, video.0)?, - Py::new(py, video.1)?, - ), + video: (Py::new(py, video.0)?, Py::new(py, video.1)?), }) })?) } @@ -152,11 +149,8 @@ impl TryFrom<&Capabilities> for capi::AcquirePropertyMetadata { (value.video.0.extract(py)?, value.video.1.extract(py)?); Ok(Self { - video: [ - (&video.0).try_into()?, - (&video.1).try_into()?, - ], + video: [(&video.0).try_into()?, (&video.1).try_into()?], }) })?) } -} \ No newline at end of file +} diff --git a/src/components/mod.rs b/src/components/mod.rs index 736ee0d..7d653fa 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,10 +1,10 @@ mod direction; pub(crate) mod macros; +mod property; mod sample_type; mod signal_io_kind; mod signal_type; mod trigger_edge; -mod property; use anyhow::Result; use pyo3::prelude::*; @@ -13,11 +13,11 @@ use serde::{Deserialize, Serialize}; // Exports pub use direction::Direction; +pub use property::{Property, PropertyType}; pub use sample_type::SampleType; pub use signal_io_kind::SignalIOKind; pub use signal_type::SignalType; pub use trigger_edge::TriggerEdge; -pub use property::{Property, PropertyType}; use crate::{capi, components::macros::impl_plain_old_dict}; diff --git a/src/components/property.rs b/src/components/property.rs index 15bd268..a9f2257 100644 --- a/src/components/property.rs +++ b/src/components/property.rs @@ -1,9 +1,9 @@ use pyo3::prelude::*; +use crate::components::macros::impl_plain_old_dict; use crate::{capi, components::macros::cvt}; use anyhow::anyhow; use serde::{Deserialize, Serialize}; -use crate::components::macros::impl_plain_old_dict; /// PropertyType #[pyclass] diff --git a/src/lib.rs b/src/lib.rs index fe49c94..ee08844 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub(crate) mod camera; +pub(crate) mod capabilities; pub(crate) mod capi; pub(crate) mod components; pub(crate) mod core_properties; @@ -6,7 +7,6 @@ pub(crate) mod device; pub(crate) mod device_manager; pub(crate) mod runtime; pub(crate) mod storage; -pub(crate) mod capabilities; use anyhow::{anyhow, Result}; use device_manager::DeviceManager; diff --git a/src/runtime.rs b/src/runtime.rs index 564af84..3bf812e 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -13,11 +13,11 @@ use std::{ sync::Arc, }; +use crate::capabilities::Capabilities; use crate::{ capi, components::macros::impl_plain_old_dict, core_properties::Properties, device::DeviceState, device_manager, Status, }; -use crate::capabilities::Capabilities; unsafe extern "C" fn reporter( is_error: ::std::os::raw::c_int, @@ -159,7 +159,8 @@ impl Runtime { fn get_capabilities(&self, py: Python<'_>) -> PyResult { let mut meta: capi::AcquirePropertyMetadata = Default::default(); Python::allow_threads(py, || { - unsafe { capi::acquire_get_configuration_metadata(self.as_ref().as_ptr(), &mut meta) }.ok() + unsafe { capi::acquire_get_configuration_metadata(self.as_ref().as_ptr(), &mut meta) } + .ok() })?; Ok((&meta).try_into()?) } diff --git a/src/storage.rs b/src/storage.rs index c1d02f9..3de14f9 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1,9 +1,6 @@ use crate::{ capi, - components::{ - macros::impl_plain_old_dict, - Property, - }, + components::{macros::impl_plain_old_dict, Property}, }; use pyo3::prelude::*; use serde::{Deserialize, Serialize}; @@ -127,7 +124,8 @@ impl TryFrom for StorageProperties { height: value.chunk_dims_px.height, planes: value.chunk_dims_px.planes, }, - ).unwrap() + ) + .unwrap() }); let shard_dims_chunks = Python::with_gil(|py| { @@ -138,7 +136,8 @@ impl TryFrom for StorageProperties { height: value.shard_dims_chunks.height, planes: value.shard_dims_chunks.planes, }, - ).unwrap() + ) + .unwrap() }); Ok(Self { @@ -293,7 +292,9 @@ impl Default for capi::StorageProperties_storage_properties_sharding_s { impl TryFrom for ChunkDims { type Error = anyhow::Error; - fn try_from(value: capi::StorageProperties_storage_properties_chunking_s) -> Result { + fn try_from( + value: capi::StorageProperties_storage_properties_chunking_s, + ) -> Result { Ok(ChunkDims { width: value.width, height: value.height, @@ -317,7 +318,9 @@ impl TryFrom<&ChunkDims> for capi::StorageProperties_storage_properties_chunking impl TryFrom for ShardDims { type Error = anyhow::Error; - fn try_from(value: capi::StorageProperties_storage_properties_sharding_s) -> Result { + fn try_from( + value: capi::StorageProperties_storage_properties_sharding_s, + ) -> Result { Ok(ShardDims { width: value.width, height: value.height, @@ -479,9 +482,12 @@ impl_plain_old_dict!(StorageCapabilities); impl Default for StorageCapabilities { fn default() -> Self { - let chunk_dims_px = Python::with_gil(|py| Py::new(py, ChunkingCapabilities::default()).unwrap()); - let shard_dims_chunks = Python::with_gil(|py| Py::new(py, ShardingCapabilities::default()).unwrap()); - let multiscale = Python::with_gil(|py| Py::new(py, MultiscaleCapabilities::default()).unwrap()); + let chunk_dims_px = + Python::with_gil(|py| Py::new(py, ChunkingCapabilities::default()).unwrap()); + let shard_dims_chunks = + Python::with_gil(|py| Py::new(py, ShardingCapabilities::default()).unwrap()); + let multiscale = + Python::with_gil(|py| Py::new(py, MultiscaleCapabilities::default()).unwrap()); Self { chunk_dims_px, shard_dims_chunks, @@ -547,7 +553,9 @@ impl Default for capi::StoragePropertyMetadata_storage_property_metadata_chunkin } } -impl TryFrom<&ChunkingCapabilities> for capi::StoragePropertyMetadata_storage_property_metadata_chunking_s { +impl TryFrom<&ChunkingCapabilities> + for capi::StoragePropertyMetadata_storage_property_metadata_chunking_s +{ type Error = anyhow::Error; fn try_from(value: &ChunkingCapabilities) -> Result { @@ -578,7 +586,9 @@ impl Default for capi::StoragePropertyMetadata_storage_property_metadata_shardin } } -impl TryFrom<&ShardingCapabilities> for capi::StoragePropertyMetadata_storage_property_metadata_sharding_s { +impl TryFrom<&ShardingCapabilities> + for capi::StoragePropertyMetadata_storage_property_metadata_sharding_s +{ type Error = anyhow::Error; fn try_from(value: &ShardingCapabilities) -> Result { @@ -606,7 +616,9 @@ impl Default for capi::StoragePropertyMetadata_storage_property_metadata_multisc } } -impl TryFrom<&MultiscaleCapabilities> for capi::StoragePropertyMetadata_storage_property_metadata_multiscale_s { +impl TryFrom<&MultiscaleCapabilities> + for capi::StoragePropertyMetadata_storage_property_metadata_multiscale_s +{ type Error = anyhow::Error; fn try_from(value: &MultiscaleCapabilities) -> Result { @@ -630,12 +642,14 @@ impl TryFrom<&StorageCapabilities> for capi::StoragePropertyMetadata { type Error = anyhow::Error; fn try_from(value: &StorageCapabilities) -> Result { - let (chunk_dims_px, shard_dims_chunks, multiscale) = Python::with_gil(|py| -> PyResult<_> { - let chunk_dims_px: ChunkingCapabilities = value.chunk_dims_px.extract(py)?; - let shard_dims_chunks: ShardingCapabilities = value.shard_dims_chunks.extract(py)?; - let multiscale: MultiscaleCapabilities = value.multiscale.extract(py)?; - Ok((chunk_dims_px, shard_dims_chunks, multiscale)) - })?; + let (chunk_dims_px, shard_dims_chunks, multiscale) = + Python::with_gil(|py| -> PyResult<_> { + let chunk_dims_px: ChunkingCapabilities = value.chunk_dims_px.extract(py)?; + let shard_dims_chunks: ShardingCapabilities = + value.shard_dims_chunks.extract(py)?; + let multiscale: MultiscaleCapabilities = value.multiscale.extract(py)?; + Ok((chunk_dims_px, shard_dims_chunks, multiscale)) + })?; Ok(Self { chunk_dims_px: (&chunk_dims_px).try_into()?, @@ -643,4 +657,4 @@ impl TryFrom<&StorageCapabilities> for capi::StoragePropertyMetadata { multiscale: (&multiscale).try_into()?, }) } -} \ No newline at end of file +} From dfbfaabdd5a27c27ab7271a5246e0649ab8d9837 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 12 Dec 2023 10:33:38 -0500 Subject: [PATCH 24/27] Update ruff config to ignore __init__.py (from .acquire import *) is necessary. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3196e05..8e57fe7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ log_cli = true # when true, messages are printed immediately [tool.ruff] exclude = [ - "*.pyi" + "__init__.py" ] ignore = [ From afcfa05c0f2f8302a044bea4a81a93a4fbb39f6f Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 12 Dec 2023 10:34:01 -0500 Subject: [PATCH 25/27] Fix pyi files to make ruff happy. --- python/acquire/__init__.pyi | 2 +- python/acquire/acquire.pyi | 68 ++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/python/acquire/__init__.pyi b/python/acquire/__init__.pyi index ae5aeb4..3c40e76 100644 --- a/python/acquire/__init__.pyi +++ b/python/acquire/__init__.pyi @@ -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, diff --git a/python/acquire/acquire.pyi b/python/acquire/acquire.pyi index 8d48643..e8e8ac6 100644 --- a/python/acquire/acquire.pyi +++ b/python/acquire/acquire.pyi @@ -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: ... @@ -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: ... @@ -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: ... @@ -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: ... @@ -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: ... @@ -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: ... @@ -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: ... @@ -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: ... From f3b6a436706cf74c4b9854e55c38f408e6496045 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 12 Dec 2023 10:34:54 -0500 Subject: [PATCH 26/27] Update pre-commit job name. --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 476c3bf..9ecbe53 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,4 +1,4 @@ -name: pre-commit +name: Run pre-commit on: pull_request: From a5c0718f811f767dd239f0d0e396fe684d49f88d Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 12 Dec 2023 11:38:26 -0500 Subject: [PATCH 27/27] Remove test_docs.py. Update `add_opts` entry in pytest config. Truncate pytest args in workflow files. --- .github/workflows/release.yml | 4 ++-- .github/workflows/test_pr.yml | 11 +++++------ pyproject.toml | 2 +- tests/test_docs.py | 31 ------------------------------- 4 files changed, 8 insertions(+), 40 deletions(-) delete mode 100644 tests/test_docs.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f7826f..c20d0ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index 0f04200..7d14f0a 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -55,9 +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_docs --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) @@ -103,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) @@ -149,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: @@ -197,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: diff --git a/pyproject.toml b/pyproject.toml index 8e57fe7..22a5c57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ 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 diff --git a/tests/test_docs.py b/tests/test_docs.py deleted file mode 100644 index 771552f..0000000 --- a/tests/test_docs.py +++ /dev/null @@ -1,31 +0,0 @@ -import doctest -import pytest - -from pathlib import Path - - -@pytest.fixture(autouse=True) -def base_dir(): - return Path(__file__).parent.parent - - -def test_readme(base_dir): - readme_path = base_dir / "README.md" - assert ( - doctest.testfile(str(readme_path), module_relative=False).failed == 0 - ) - - -def test_modules(base_dir): - for module in base_dir.glob("python/**/*.py"): - assert doctest.testfile(str(module), module_relative=False).failed == 0 - - -def test_rust_sources(base_dir): - for f in base_dir.glob("src/**/*.rs"): - assert doctest.testfile(str(f), module_relative=False).failed == 0 - - -def test_pyi_files(base_dir): - for f in base_dir.glob("python/**/*.pyi"): - assert doctest.testfile(str(f), module_relative=False).failed == 0