Skip to content

Commit

Permalink
more general rc-stripper in runcontrol, draft wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillinge committed Jan 4, 2025
1 parent a67cef2 commit 310065d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
23 changes: 23 additions & 0 deletions news/strip-prum_finisher.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* All inputs of `_id`s are now stripped before assigning to variables

**Security:**

* <news item>
26 changes: 26 additions & 0 deletions src/regolith/runcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@
FORBIDDEN_NAMES = frozenset(["del", "global"])


def strip_rc(rc):
"""strip whitespace from all string-like rc members
Parameters
----------
rc : runcontrol object
The rc with unstripped strings
Return
------
rc : runcontrol object
The rc with all strings sstripped of whitespace
"""
stripped_rc = rc.__class__()
for attr in dir(rc):
if not attr.startswith("__"):
value = getattr(rc, attr)
if isinstance(value, str):
print("str", attr, value)
setattr(stripped_rc, attr, value.strip())
else:
print("non-str", attr, value)
setattr(stripped_rc, attr, value)
return stripped_rc


def warn_forbidden_name(forname, inname=None, rename=None):
"""Warns the user that a forbidden name has been found."""
msg = "found forbidden name {0!r}".format(forname)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_runcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

from regolith.database import connect
from regolith.runcontrol import DEFAULT_RC, connect_db, filter_databases, load_rcfile
from regolith.runcontrol import DEFAULT_RC, connect_db, filter_databases, load_rcfile, strip_rc


def test_connect_db(make_db):
Expand All @@ -17,3 +17,10 @@ def test_connect_db(make_db):
chained_db, dbs = connect_db(rc)
assert chained_db == expected_chdb
assert dbs == expected_dbs


def test_strip_rc():
rc = copy.copy(DEFAULT_RC)
rc.new_thing = "new_thing "
rc = strip_rc(rc)
assert rc.new_thing == "new_thing"

0 comments on commit 310065d

Please sign in to comment.