Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 18, 2024
1 parent 100474c commit 1cb01b7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
17 changes: 8 additions & 9 deletions pioreactor/actions/leader/experiment_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
bool_expression = str | bool
Env = dict[str, Any]

STRICT_EXPRESSION_PATTERN = r"^\${{(.*?)}}$"
FLEXIBLE_EXPRESSION_PATTERN = r"\${{(.*?)}}"


def wrap_in_try_except(func, logger: CustomLogger) -> Callable:
def inner_function(*args, **kwargs) -> None:
Expand All @@ -46,15 +49,13 @@ def inner_function(*args, **kwargs) -> None:
def is_bracketed_expression(value: str) -> bool:
import re

pattern = r"\${{(.*?)}}"
return bool(re.search(pattern, str(value)))
return bool(re.search(STRICT_EXPRESSION_PATTERN, str(value)))


def strip_expression_brackets(value: str) -> str:
import re

pattern = r"\${{(.*?)}}"
match = re.search(pattern, value)
match = re.search(STRICT_EXPRESSION_PATTERN, value)
assert match is not None
return match.group(1)

Expand All @@ -80,14 +81,12 @@ def evaluate_log_message(message: str, env: dict) -> str:
import re
from pioreactor.experiment_profiles.parser import parse_profile_expression

pattern = r"\${{(.*?)}}"

matches = re.findall(pattern, message)
matches = re.findall(FLEXIBLE_EXPRESSION_PATTERN, message)

modified_matches = [parse_profile_expression(match, env) for match in matches]

# Replace each ${{...}} in the original string with the modified match
result_string = re.sub(pattern, lambda m: str(modified_matches.pop(0)), message)
result_string = re.sub(FLEXIBLE_EXPRESSION_PATTERN, lambda m: str(modified_matches.pop(0)), message)
return result_string


Expand Down Expand Up @@ -924,7 +923,7 @@ def execute_experiment_profile(profile_filename: str, experiment: str, dry_run:
if state.exit_event.is_set():
# ended early

logger.notice(f"Stopping profile {profile.experiment_profile_name} early: {len(sched.queue)} actions not started, and stopping all started actions.") # type: ignore
logger.notice(f"Stopping profile {profile.experiment_profile_name} early: {len(sched.queue)} action(s) not started, and stopping all started action(s).") # type: ignore
# stop all jobs started
# we can use active workers in experiment, since if a worker leaves an experiment or goes inactive, it's jobs are stopped
workers = get_active_workers_in_experiment(experiment)
Expand Down
8 changes: 6 additions & 2 deletions pioreactor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ def get_config() -> ConfigParserMod:
config["od_config.photodiode_channel_reverse"] = config.invert_section("od_config.photodiode_channel")

# add this for hostname resolution using config.ini, see pioreactor.utils.networking.resolve_to_address
leader_hostname = config["cluster.topology"]["leader_hostname"]
config["cluster.addresses"][f"{leader_hostname}_address"] = config["cluster.topology"]["leader_address"]
if "cluster.addresses" not in config:
config.add_section("cluster.addresses")

leader_hostname = config.get("cluster.topology", "leader_hostname")
leader_address = config.get("cluster.topology", "leader_address")
config.set("cluster.addresses", f"{leader_hostname}_address", leader_address)

return config

Expand Down
5 changes: 3 additions & 2 deletions pioreactor/plugin_management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
from typing import Any

import click
from msgspec import Struct

from .install_plugin import click_install_plugin
Expand Down Expand Up @@ -82,7 +83,7 @@ def get_plugins() -> dict[str, Plugin]:
"entry_points",
)
except Exception as e:
print(f"{plugin.name} plugin load error: {e}")
click.secho(f"{plugin.name} plugin load error: {e}", color="red")

# get file-based plugins.
# Users can put .py files into the MODULE_DIR folder below.
Expand Down Expand Up @@ -110,7 +111,7 @@ def get_plugins() -> dict[str, Plugin]:
f"plugins/{py_file.name}",
)
except Exception as e:
print(f"{py_file} encountered plugin load error: {e}")
click.secho(f"{py_file} plugin load error: {e}", color="red")

return plugins

Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
"diskcache==5.6.3",
"crudini==0.9.5",
"iniparse==0.5",
"six==1.16.0",
"blinker==1.8.2",
"flask==3.0.2",
"flup6==1.1.1",
"huey==2.5.0",
"huey==2.5.2",
"ifaddr==0.2.0",
"itsdangerous==2.2.0",
"Jinja2==3.1.4",
Expand Down Expand Up @@ -47,7 +46,6 @@
"pyserial==3.5",
"pyusb==1.2.1",
"rpi_hardware_pwm==0.2.1",
"typing_extensions==4.12.2",
]


Expand Down
2 changes: 1 addition & 1 deletion update_scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Possible update scripts and their sequence, always run as `root`:

It's very important that update scripts are idempotent. Some tips:

- Use ChatGPT to assist psuedo-check if a script is idempotent, or making suggestions.
- Use ChatGPT to inspect if a script is idempotent, or make suggestions.


### `bash` specific tips
Expand Down

0 comments on commit 1cb01b7

Please sign in to comment.