Skip to content

Commit c8c6977

Browse files
committed
Fix environment variable names in ExecEnv class
1 parent a428b70 commit c8c6977

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

guidata/env.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class ExecEnv:
3333
"""Object representing execution environment"""
3434

3535
UNATTENDED_ARG = "unattended"
36-
ACCEPTDIALOGS_ARG = "accept_dialogs"
36+
ACCEPT_DIALOGS_ARG = "accept_dialogs"
3737
VERBOSE_ARG = "verbose"
3838
SCREENSHOT_ARG = "screenshot"
3939
DELAY_ARG = "delay"
4040
UNATTENDED_ENV = "GUIDATA_UNATTENDED"
41-
ACCEPTDIALOGS_ENV = "GUIDATA_ACCEPT_DIALOGS"
41+
ACCEPT_DIALOGS_ENV = "GUIDATA_ACCEPT_DIALOGS"
4242
VERBOSE_ENV = "GUIDATA_VERBOSE"
4343
SCREENSHOT_ENV = "GUIDATA_SCREENSHOT"
4444
DELAY_ENV = "GUIDATA_DELAY"
@@ -50,15 +50,23 @@ def __init__(self):
5050
# Check that calling `to_dict` do not raise any exception
5151
self.to_dict()
5252

53+
def iterate_over_attrs_envvars(self) -> Generator[tuple[str, str], None, None]:
54+
"""Iterate over CDL environment variables
55+
56+
Yields:
57+
A tuple (attribute name, environment variable name)
58+
"""
59+
for name in dir(self):
60+
if name.endswith("_ENV"):
61+
envvar: str = getattr(self, name)
62+
attrname = "_".join(name.split("_")[:-1]).lower()
63+
yield attrname, envvar
64+
5365
def to_dict(self):
5466
"""Return a dictionary representation of the object"""
55-
# The list of properties match the list of environment variable names, modulo
56-
# the "GUIDATA_" prefix for environment variables:
57-
props = [
58-
"_".join(getattr(self, attrname).split("_")[1:]).lower()
59-
for attrname in dir(self)
60-
if attrname.endswith("_ENV")
61-
]
67+
# The list of properties match the list of environment variable attribute names,
68+
# modulo the "_ENV" suffix:
69+
props = [attrname for attrname, _envvar in self.iterate_over_attrs_envvars()]
6270

6371
# Check that all properties are defined in the class and that they are
6472
# really properties:
@@ -106,12 +114,12 @@ def unattended(self, value):
106114
@property
107115
def accept_dialogs(self):
108116
"""Whether to accept dialogs in unattended mode"""
109-
return self.__get_mode(self.ACCEPTDIALOGS_ENV)
117+
return self.__get_mode(self.ACCEPT_DIALOGS_ENV)
110118

111119
@accept_dialogs.setter
112120
def accept_dialogs(self, value):
113121
"""Set whether to accept dialogs in unattended mode"""
114-
self.__set_mode(self.ACCEPTDIALOGS_ENV, value)
122+
self.__set_mode(self.ACCEPT_DIALOGS_ENV, value)
115123

116124
@property
117125
def screenshot(self):
@@ -159,7 +167,7 @@ def parse_args(self):
159167
default=None,
160168
)
161169
parser.add_argument(
162-
"--" + self.ACCEPTDIALOGS_ARG,
170+
"--" + self.ACCEPT_DIALOGS_ARG,
163171
action="store_true",
164172
help="accept dialogs in unattended mode",
165173
default=None,
@@ -190,7 +198,7 @@ def set_env_from_args(self, args):
190198
"""Set appropriate environment variables"""
191199
for argname in (
192200
self.UNATTENDED_ARG,
193-
self.ACCEPTDIALOGS_ARG,
201+
self.ACCEPT_DIALOGS_ARG,
194202
self.SCREENSHOT_ARG,
195203
self.VERBOSE_ARG,
196204
self.DELAY_ARG,

0 commit comments

Comments
 (0)