-
Notifications
You must be signed in to change notification settings - Fork 0
Add waterlog app interface #246
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ac5d665
Implement detached executor
bruno-f-cruz b3e3afc
Add unittest for LocalDetachedExecutor
bruno-f-cruz 1a86d4a
Add waterlog app interface
bruno-f-cruz f7b76e4
Use default location and exe as fallback
bruno-f-cruz 15ea112
Default to `Program Files`
bruno-f-cruz 68abd80
Use `StdCommand` syntatic sugar
bruno-f-cruz e9c415b
Waterlog is a detached app
bruno-f-cruz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .waterlog import WaterlogApp, WaterlogSettings | ||
|
|
||
| __all__ = ["WaterlogApp", "WaterlogSettings"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import os | ||
| import shutil | ||
| from pathlib import Path | ||
| from typing import Any, ClassVar, Optional, Self | ||
|
|
||
| from pydantic import Field | ||
| from pydantic_settings import CliApp, SettingsConfigDict | ||
|
|
||
| from clabe.apps import StdCommand | ||
| from clabe.apps._base import CommandResult | ||
|
|
||
| from ..apps import ExecutableApp, LocalDetachedExecutor | ||
| from ..services import ServiceSettings | ||
|
|
||
|
|
||
| class WaterlogSettings(ServiceSettings): | ||
| """Settings for the waterlog service.""" | ||
|
|
||
| model_config = SettingsConfigDict(cli_kebab_case=True) | ||
| # This should be ok since the subclass initializes first the and toml sources get appended to the settings dict | ||
| __yml_section__: ClassVar[Optional[str]] = "waterlog" | ||
|
|
||
| username: Optional[str] = Field(default=None, description="Username for the waterlog service") | ||
| mouse_id: Optional[str] = Field(default=None, description="Mouse ID for the waterlog service") | ||
| mouse_weight: Optional[float] = Field(default=None, description="Mouse weight for the waterlog service") | ||
| comment: Optional[str] = Field(default=None, description="Comment for the waterlog service") | ||
| earned_water: Optional[float] = Field(default=None, description="Water earned during behavior task (mL)") | ||
| water_supplement_ml: Optional[float] = Field(default=None, description="Water supplement amount (mL)") | ||
| water_supplement_delivered: Optional[bool] = Field( | ||
| default=None, description="Flag indicating if the water supplement has been delivered" | ||
| ) | ||
|
|
||
|
|
||
| class WaterlogApp(ExecutableApp): | ||
| """App for logging water consumption and related information.""" | ||
|
|
||
| _EXECUTABLE: Optional[Path] = ( | ||
| Path(os.getenv("PROGRAMFILES", r"C:\Program Files")) / r"AIBS_MPE\waterlog\waterlog.exe" | ||
| ) | ||
|
|
||
| def __init__(self, settings: WaterlogSettings): | ||
| """Initialize the WaterlogApp with the given settings.""" | ||
| self._executable = str(self._EXECUTABLE) | ||
| self._settings = settings | ||
| self.validate() | ||
| _cmd = [self._executable] + CliApp.serialize(settings) | ||
| self._command = StdCommand(cmd=_cmd) | ||
|
|
||
| def validate(self) -> None: | ||
| """Validates the settings and checks for the presence of the waterlog executable.""" | ||
| if not Path(self._executable).exists(): | ||
| if (loc := shutil.which("waterlog.exe")) is None: | ||
| raise FileNotFoundError( | ||
| f"'{self._EXECUTABLE}' command not found. Please ensure it is installed and available." | ||
| ) | ||
| self._executable = loc | ||
|
|
||
| @property | ||
| def command(self) -> StdCommand: | ||
| """Get the command to execute.""" | ||
| return self._command | ||
|
|
||
| def run(self: Self, executor_kwargs: Optional[dict[str, Any]] = None) -> CommandResult: | ||
| """Execute the command using a local executor and return the result.""" | ||
| executor = LocalDetachedExecutor(**(executor_kwargs or {})) | ||
| return self.command.execute(executor) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.