From 70311024f560689547734bb15ab4df20549016f0 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:41:07 +0100 Subject: [PATCH 1/9] docs: fix typos in documentation and docstrings --- docs/source/developers.rst | 2 +- docs/source/features.rst | 8 ++++---- src/crappy/blocks/meta_block/block.py | 2 +- src/crappy/inout/phidgets_wheatstone_bridge.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/developers.rst b/docs/source/developers.rst index 43a21582..a7a967e6 100644 --- a/docs/source/developers.rst +++ b/docs/source/developers.rst @@ -380,7 +380,7 @@ This Barrier is shared by all the Blocks, and its value is set to the number of Blocks +1. Therefore, the Barrier only breaks when all the Blocks have reached it, as well as the ``__main__`` Process. In case one of the Processes doesn't make it to the Barrier, a :obj:`~threading.BrokenBarrierError` is raised to -indicate all the other Blocks not to wait forever on the Barrier. +indicate all the other Blocks not to wait forever at the Barrier. Once every Process has reached the Barrier, it breaks and releases them all. At that moment, the :obj:`~multiprocessing.Value` storing the initial timestamp diff --git a/docs/source/features.rst b/docs/source/features.rst index f6fc30a7..f8f89bea 100644 --- a/docs/source/features.rst +++ b/docs/source/features.rst @@ -324,7 +324,7 @@ Hardware control provided with Crappy. This Block can start or stop the script on the microcontroller, send commands, and receive data. - The examples folder on GitHub contains `on example of the UController Block + The examples folder on GitHub contains `one example of the UController Block `_. @@ -352,7 +352,7 @@ Others communicating with distant devices over a network, e.g. for remotely controlling a test. - The examples folder on GitHub contains `on example of the Client Server Block + The examples folder on GitHub contains `one example of the ClientServer Block `_. @@ -363,7 +363,7 @@ Others examples because it doesn't require any hardware, but may as well be used for debugging or prototyping. - The examples folder on GitHub contains `on example of the Fake Machine Block + The examples folder on GitHub contains `one example of the Fake Machine Block `_. @@ -371,7 +371,7 @@ Others Discards any received data. Used for prototyping and debugging only. - The examples folder on GitHub contains `on example of the Sink Block + The examples folder on GitHub contains `one example of the Sink Block `_. diff --git a/src/crappy/blocks/meta_block/block.py b/src/crappy/blocks/meta_block/block.py index ee0e08c3..260a9926 100644 --- a/src/crappy/blocks/meta_block/block.py +++ b/src/crappy/blocks/meta_block/block.py @@ -969,7 +969,7 @@ def prepare(self) -> None: Block before the test starts. For example, it can open a network connection, create a file, etc. It is - also fine for this method not to be overriden if there's no particular + also fine for this method not to be overridden if there's no particular action to perform. Note that this method is called once the :obj:`~multiprocessing.Process` diff --git a/src/crappy/inout/phidgets_wheatstone_bridge.py b/src/crappy/inout/phidgets_wheatstone_bridge.py index 8ae2202b..4c7765ab 100644 --- a/src/crappy/inout/phidgets_wheatstone_bridge.py +++ b/src/crappy/inout/phidgets_wheatstone_bridge.py @@ -101,7 +101,7 @@ def open(self) -> None: self.log(logging.DEBUG, "Trying to attach the load cell conditioner") self._load_cell.openWaitForAttachment(10000) except PhidgetException: - raise TimeoutError("Waited too long for the motor to attach !") + raise TimeoutError("Waited too long for the bridge to attach !") def get_data(self) -> Optional[list[float]]: """Returns the last known voltage ratio value, adjusted with the gain and From 518697e3dc2b6fd08db59cee3be413fbfcbeaa2c Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:41:29 +0100 Subject: [PATCH 2/9] refactor: remove unused import --- src/crappy/tool/camera_config/camera_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/crappy/tool/camera_config/camera_config.py b/src/crappy/tool/camera_config/camera_config.py index dd2676ca..69d51a10 100644 --- a/src/crappy/tool/camera_config/camera_config.py +++ b/src/crappy/tool/camera_config/camera_config.py @@ -2,7 +2,6 @@ import tkinter as tk from tkinter.messagebox import showerror -from _tkinter import TclError from platform import system import numpy as np from time import time, sleep From c43345bb3ce10529bf92bd0ff1ae7bc758067b4c Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:42:09 +0100 Subject: [PATCH 3/9] syntax: remove extra blank line --- src/crappy/blocks/stop_block.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/crappy/blocks/stop_block.py b/src/crappy/blocks/stop_block.py index e4455767..84947dfa 100644 --- a/src/crappy/blocks/stop_block.py +++ b/src/crappy/blocks/stop_block.py @@ -150,4 +150,3 @@ def cond(data: dict[str, list]) -> bool: else: raise ValueError("Wrong syntax for the criterion, please refer to the " "documentation") - From 3982674de710fc5ceb69d9bcea408b4a071f1a49 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:42:39 +0100 Subject: [PATCH 4/9] docs: move Stop Block and Stop Button to test management section --- docs/source/features.rst | 52 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/source/features.rst b/docs/source/features.rst index f8f89bea..42adeaff 100644 --- a/docs/source/features.rst +++ b/docs/source/features.rst @@ -342,6 +342,32 @@ Test management `_. +- :ref:`Stop Block` + + Stops the current Crappy script if the received data meets one of the given + criteria. One of the clean ways to stop a script in Crappy. + + The examples folder on GitHub contains `one example of the Stop Block + `_. + + Refer to the :ref:`dedicated tutorial section + <3. Properly stopping a script>` to learn more about how to properly stop a + script in Crappy. + +- :ref:`Stop Button` + + Stops the current Crappy script when the user clicks on a button in a GUI. + One of the clean ways to stop a script in Crappy. + + The examples folder on GitHub contains `one example of the Stop Button Block + `_. + + Refer to the :ref:`dedicated tutorial section + <3. Properly stopping a script>` to learn more about how to properly stop a + script in Crappy. + Others ++++++ @@ -375,32 +401,6 @@ Others `_. -- :ref:`Stop Block` - - Stops the current Crappy script if the received data meets one of the given - criteria. One of the clean ways to stop a script in Crappy. - - The examples folder on GitHub contains `on example of the Stop Block - `_. - - Refer to the :ref:`dedicated tutorial section - <3. Properly stopping a script>` to learn more about how to properly stop a - script in Crappy. - -- :ref:`Stop Button` - - Stops the current Crappy script when the user clicks on a button in a GUI. - One of the clean ways to stop a script in Crappy. - - The examples folder on GitHub contains `on example of the Stop Button Block - `_. - - Refer to the :ref:`dedicated tutorial section - <3. Properly stopping a script>` to learn more about how to properly stop a - script in Crappy. - Supported hardware (Cameras, InOuts, Actuators) ----------------------------------------------- From 08d1ed275c9321724e8f0e220aab3eba658cd02b Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:43:05 +0100 Subject: [PATCH 5/9] refactor: rearrange imports in alphabetical order --- src/crappy/blocks/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crappy/blocks/__init__.py b/src/crappy/blocks/__init__.py index c78a3e1e..0ddfbfe3 100644 --- a/src/crappy/blocks/__init__.py +++ b/src/crappy/blocks/__init__.py @@ -2,26 +2,26 @@ from .auto_drive_video_extenso import AutoDriveVideoExtenso from .meta_block import Block +from .button import Button from .camera import Camera +from .canvas import Canvas from .client_server import ClientServer from .dashboard import Dashboard -from .dis_correl import DISCorrel from .dic_ve import DICVE -from .canvas import Canvas +from .dis_correl import DISCorrel from .fake_machine import FakeMachine from .generator import Generator from .gpu_correl import GPUCorrel from .gpu_ve import GPUVE from .grapher import Grapher -from .button import Button from .hdf_recorder import HDFRecorder from .ioblock import IOBlock +from .link_reader import LinkReader from .machine import Machine from .mean import MeanBlock from .multiplexer import Multiplexer from .pause import Pause from .pid import PID -from .link_reader import LinkReader from .recorder import Recorder from .sink import Sink from .stop_block import StopBlock From 56cf633f7ea14d488202d7b6260703521b4fc78b Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:43:35 +0100 Subject: [PATCH 6/9] docs: replace references to typing by references to collections.abc --- src/crappy/blocks/stop_block.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/crappy/blocks/stop_block.py b/src/crappy/blocks/stop_block.py index 84947dfa..962f51fa 100644 --- a/src/crappy/blocks/stop_block.py +++ b/src/crappy/blocks/stop_block.py @@ -28,12 +28,13 @@ def __init__(self, """Sets the arguments and initialize the parent class. Args: - criteria: A :obj:`str`, a :obj:`~typing.Callable`, or an - :obj:`~typing.Iterable` (like a :obj:`tuple` or a :obj:`list`) - containing such objects. Each :obj:`str` or :obj:`~typing.Callable` - represents one stop criterion. There is no limit to the given number of - stop criteria. If a criterion is given as an :obj:`~typing.Callable`, - it should accept as its sole argument the output of the + criteria: A :obj:`str`, a :obj:`~collections.abc.Callable`, or an + :obj:`~collections.abc.Iterable` (like a :obj:`tuple` or a :obj:`list`) + containing such objects. Each :obj:`str` or + :obj:`~collections.abc.Callable` represents one stop criterion. There + is no limit to the given number of stop criteria. If a criterion is + given as an :obj:`~collections.abc.Callable`, it should accept as its + sole argument the output of the :meth:`crappy.blocks.Block.recv_all_data` method and return :obj:`True` if the criterion is met, and :obj:`False` otherwise. If the criterion is given as a :obj:`str`, it should follow the following syntax : From 2e2ba12c271f528ee6415ea8577286514687eef3 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:44:29 +0100 Subject: [PATCH 7/9] docs: fix broken badge on README page and PyPI home page --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab766fc8..bf177ca2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ Command and Real-time Acquisition in Parallelized PYthon (CRAPPY) ================================================================= -[![Downloads](https://pepy.tech/badge/crappy)](https://pepy.tech/project/crappy) -[![Documentation Status](https://readthedocs.org/projects/crappy/badge/?version=latest)](https://crappy.readthedocs.io/en/latest/?badge=latest) +[![Downloads](https://static.pepy.tech/badge/crappy)](https://www.pepy.tech/projects/crappy) +[![Documentation Status](https://readthedocs.org/projects/crappy/badge/?version=latest)](https://crappy.readthedocs.io/en/latest/) [![PyPi version](https://badgen.net/pypi/v/crappy/)](https://pypi.org/project/crappy/) [![Python version](https://img.shields.io/pypi/pyversions/crappy.svg)](https://pypi.org/project/crappy/) From 0075b537a9a37dcd5b53c0e6fa7224637b13b1f3 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:45:00 +0100 Subject: [PATCH 8/9] refactor: add type hints for instance attributes --- src/crappy/blocks/meta_block/block.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crappy/blocks/meta_block/block.py b/src/crappy/blocks/meta_block/block.py index 260a9926..03bf1ac7 100644 --- a/src/crappy/blocks/meta_block/block.py +++ b/src/crappy/blocks/meta_block/block.py @@ -77,9 +77,9 @@ def __init__(self) -> None: # Various objects that should be set by child classes self.niceness: int = 0 self.labels: Optional[Iterable[str]] = None - self.freq = None - self.display_freq = False - self.name = self.get_name(type(self).__name__) + self.freq: Optional[float] = None + self.display_freq: bool = False + self.name: str = self.get_name(type(self).__name__) self.pausable: bool = True # The synchronization objects will be set later From a6269006d61eaf9093223daecd17588816d0810e Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Thu, 14 Nov 2024 23:46:47 +0100 Subject: [PATCH 9/9] fix: regression added in 51f1e3f0 making wrong frequency handling --- src/crappy/blocks/meta_block/block.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crappy/blocks/meta_block/block.py b/src/crappy/blocks/meta_block/block.py index 03bf1ac7..f68e285a 100644 --- a/src/crappy/blocks/meta_block/block.py +++ b/src/crappy/blocks/meta_block/block.py @@ -1055,8 +1055,9 @@ def _handle_freq(self) -> None: # Correcting the error of the sleep function through a recursive approach # The last 2 milliseconds are in free loop - while (remaining := self._last_t + 1 / self.freq - t) > 0: + while self._last_t + 1 / self.freq - t > 0: t = time_ns() / 1e9 + remaining = self._last_t + 1 / self.freq - t sleep(max(0., remaining / 2 - 2e-3)) self._last_t = t