Skip to content

Commit

Permalink
try this fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Sep 19, 2023
1 parent 652d30a commit 9da5154
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 44 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### 23.9.20
The previous change:

> - Base automations now subclass from `pioreactor.automations.BaseAutomationJob`. You may need to change custom automation imports from, for example, `from pioreactor.automations import DosingAutomationJobContrib` to `from pioreactor.automations.dosing.base import DosingAutomationJobContrib`
had an import error that I didn't see in my testing. We changed this further to:

- Base automations now subclass from `pioreactor.automations.base.AutomationJob`.


### 23.9.19
- When installing plugins, any leader-only commands would not be run. This is fixed.
- Base automations now subclass from `pioreactor.automations.BaseAutomationJob`. You may need to change custom automation imports from, for example, `from pioreactor.automations import DosingAutomationJobContrib` to `from pioreactor.automations.dosing.base import DosingAutomationJobContrib`
Expand Down
40 changes: 4 additions & 36 deletions pioreactor/automations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

from typing import Optional

from pioreactor.automations import events
from pioreactor.background_jobs.subjobs import BackgroundSubJob


DISALLOWED_AUTOMATION_NAMES = {
"config",
}


class BaseAutomationJob(BackgroundSubJob):
automation_name = "base_automation_job"

def __init__(self, unit: str, experiment: str) -> None:
super(BaseAutomationJob, self).__init__(unit, experiment)

if self.automation_name in DISALLOWED_AUTOMATION_NAMES:
raise NameError(f"{self.automation_name} is not allowed.")

self.add_to_published_settings(
"latest_event",
{
"datatype": "AutomationEvent",
"settable": False,
},
)

def on_init_to_ready(self) -> None:
self.start_passive_listeners()

def execute(self) -> Optional[events.AutomationEvent]:
"""
Overwrite in subclass
"""
return events.NoEvent()
from . import dosing
from . import events
from . import led
from . import temperature
39 changes: 39 additions & 0 deletions pioreactor/automations/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

from typing import Optional

from pioreactor.automations import events
from pioreactor.background_jobs.subjobs import BackgroundSubJob


DISALLOWED_AUTOMATION_NAMES = {
"config",
}


class AutomationJob(BackgroundSubJob):
automation_name = "automation_job"

def __init__(self, unit: str, experiment: str) -> None:
super(AutomationJob, self).__init__(unit, experiment)

if self.automation_name in DISALLOWED_AUTOMATION_NAMES:
raise NameError(f"{self.automation_name} is not allowed.")

self.add_to_published_settings(
"latest_event",
{
"datatype": "AutomationEvent",
"settable": False,
},
)

def on_init_to_ready(self) -> None:
self.start_passive_listeners()

def execute(self) -> Optional[events.AutomationEvent]:
"""
Overwrite in subclass
"""
return events.NoEvent()
4 changes: 2 additions & 2 deletions pioreactor/automations/dosing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from pioreactor.actions.pump import add_alt_media
from pioreactor.actions.pump import add_media
from pioreactor.actions.pump import remove_waste
from pioreactor.automations import BaseAutomationJob
from pioreactor.automations import events
from pioreactor.automations.base import AutomationJob
from pioreactor.background_jobs.dosing_control import DosingController
from pioreactor.config import config
from pioreactor.pubsub import QOS
Expand Down Expand Up @@ -157,7 +157,7 @@ def _update_alt_media_fraction(
)


class DosingAutomationJob(BaseAutomationJob):
class DosingAutomationJob(AutomationJob):
"""
This is the super class that automations inherit from. The `run` function will
execute every `duration` minutes (selected at the start of the program). If `duration` is left
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/automations/led/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from pioreactor import structs
from pioreactor import types as pt
from pioreactor.actions.led_intensity import led_intensity
from pioreactor.automations import BaseAutomationJob
from pioreactor.automations import events
from pioreactor.automations.base import AutomationJob
from pioreactor.background_jobs.led_control import LEDController
from pioreactor.pubsub import QOS
from pioreactor.utils import is_pio_job_running
Expand All @@ -30,7 +30,7 @@ def brief_pause() -> float:
return d


class LEDAutomationJob(BaseAutomationJob):
class LEDAutomationJob(AutomationJob):
"""
This is the super class that LED automations inherit from. The `run` function will
execute every `duration` minutes (selected at the start of the program), and call the `execute` function
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/automations/temperature/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
from pioreactor import exc
from pioreactor import structs
from pioreactor import types as pt
from pioreactor.automations import BaseAutomationJob
from pioreactor.automations.base import AutomationJob
from pioreactor.background_jobs.temperature_control import TemperatureController
from pioreactor.pubsub import QOS
from pioreactor.utils import is_pio_job_running
from pioreactor.utils.timing import current_utc_datetime


class TemperatureAutomationJob(BaseAutomationJob):
class TemperatureAutomationJob(AutomationJob):
"""
This is the super class that Temperature automations inherit from.
The `execute` function, which is what subclasses will define, is updated every time a new temperature is recorded to MQTT.
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Append "dev" if a dev version
# Append "rc0" if a rc version
__version__ = "23.9.19"
__version__ = "23.9.19dev"


def _get_hardware_version() -> tuple[int, int] | tuple[int, int, str]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"sh==1.14.3",
"JSON-log-formatter==0.5.1",
"colorlog==6.7.0",
"msgspec==0.18.1",
"msgspec==0.18.2",
"diskcache==5.6.1",
"wheel==0.38.4",
"crudini==0.9.4",
Expand Down

0 comments on commit 9da5154

Please sign in to comment.