Skip to content

Commit

Permalink
Convert string config settings to bool (#1117)
Browse files Browse the repository at this point in the history
* convert string config settings to bool

* update changelog

* move str_to_bool and use in settings

* fix lint

* fix lint

---------

Co-authored-by: Eric Denovellis <[email protected]>
  • Loading branch information
samuelbray32 and edeno authored Sep 26, 2024
1 parent 32dc077 commit 05444bb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dj.FreeTable(dj.conn(), "common_session.session_group").drop()
- Update DataJoint to 0.14.2 #1081
- Allow restriction based on parent keys in `Merge.fetch_nwb()` #1086, #1126
- Import `datajoint.dependencies.unite_master_parts` -> `topo_sort` #1116
- Fix bool settings imported from dj config file #1117
- Allow definition of tasks and new probe entries from config #1074, #1120
- Enforce match between ingested nwb probe geometry and existing table entry
#1074
Expand Down
10 changes: 1 addition & 9 deletions src/spyglass/position/v1/position_dlc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ruamel.yaml as yaml

from spyglass.utils import SpyglassMixin, logger
from spyglass.utils.dj_helper_fn import str_to_bool

from . import dlc_reader
from .position_dlc_project import BodyPart, DLCProject # noqa: F401
Expand Down Expand Up @@ -347,12 +348,3 @@ def make(self, key):
test_error_p=results["Test error with p-cutoff"],
)
)


def str_to_bool(value) -> bool:
"""Return whether the provided string represents true. Otherwise false."""
# Due to distutils equivalent depreciation in 3.10
# Adopted from github.com/PostHog/posthog/blob/master/posthog/utils.py
if not value:
return False
return str(value).lower() in ("y", "yes", "t", "true", "on", "1")
3 changes: 3 additions & 0 deletions src/spyglass/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import yaml
from pymysql.err import OperationalError

from spyglass.utils.dj_helper_fn import str_to_bool
from spyglass.utils.logging import logger


Expand Down Expand Up @@ -143,6 +144,8 @@ def load_config(
self._test_mode = kwargs.get("test_mode") or dj_custom.get(
"test_mode", False
)
self._test_mode = str_to_bool(self._test_mode)
self._debug_mode = str_to_bool(self._debug_mode)

resolved_base = (
base_dir
Expand Down
9 changes: 9 additions & 0 deletions src/spyglass/utils/dj_helper_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,12 @@ def daemon(self, val):

proc.__class__ = NonDaemonProcess
return proc


def str_to_bool(value) -> bool:
"""Return whether the provided string represents true. Otherwise false."""
# Due to distutils equivalent depreciation in 3.10
# Adopted from github.com/PostHog/posthog/blob/master/posthog/utils.py
if not value:
return False
return str(value).lower() in ("y", "yes", "t", "true", "on", "1")

0 comments on commit 05444bb

Please sign in to comment.