|
35 | 35 | )
|
36 | 36 |
|
37 | 37 |
|
38 |
| -class DisallowExecutionAndBackendInEnvironmentMixin: |
39 |
| - """Mixin to disallow setting both execution and backend in environment.""" |
40 |
| - |
41 |
| - @classmethod |
42 |
| - @doc(Parameter._get_value_from_config.__doc__) |
43 |
| - def _get_value_from_config(cls) -> str: |
44 |
| - if Backend.varname in os.environ and ( |
45 |
| - Engine.varname in os.environ or StorageFormat.varname in os.environ |
46 |
| - ): |
47 |
| - # Handling this case is tricky, in part because the combination of |
48 |
| - # Backend and Engine/StorageFormat may be invalid. For now just |
49 |
| - # disallow it. |
50 |
| - raise Exception("Can't specify both execution and backend in environment") |
51 |
| - return Parameter._get_value_from_config() |
52 |
| - |
53 |
| - |
54 | 38 | class EnvironmentVariable(Parameter, type=str, abstract=True):
|
55 | 39 | """Base class for environment variables-based configuration."""
|
56 | 40 |
|
@@ -182,14 +166,35 @@ def put(cls, value: Any) -> None:
|
182 | 166 | cls._update_sibling = True
|
183 | 167 |
|
184 | 168 |
|
| 169 | +class EnvironmentVariableDisallowingExecutionAndBackendBothSet( |
| 170 | + EnvironmentVariable, |
| 171 | + type=EnvironmentVariable.type, |
| 172 | + abstract=True, |
| 173 | +): |
| 174 | + """Subclass to disallow getting this variable from the environment when both execution and backend are set in the environment.""" |
| 175 | + |
| 176 | + @classmethod |
| 177 | + @doc(EnvironmentVariable._get_value_from_config.__doc__) |
| 178 | + def _get_value_from_config(cls) -> str: |
| 179 | + if Backend.varname in os.environ and ( |
| 180 | + Engine.varname in os.environ or StorageFormat.varname in os.environ |
| 181 | + ): |
| 182 | + # Handling this case is tricky, in part because the combination of |
| 183 | + # Backend and Engine/StorageFormat may be invalid. For now just |
| 184 | + # disallow it. |
| 185 | + raise Exception("Can't specify both execution and backend in environment") |
| 186 | + return super()._get_value_from_config() |
| 187 | + |
| 188 | + |
185 | 189 | class IsDebug(EnvironmentVariable, type=bool):
|
186 | 190 | """Force Modin engine to be "Python" unless specified by $MODIN_ENGINE."""
|
187 | 191 |
|
188 | 192 | varname = "MODIN_DEBUG"
|
189 | 193 |
|
190 | 194 |
|
191 | 195 | class Engine(
|
192 |
| - DisallowExecutionAndBackendInEnvironmentMixin, EnvironmentVariable, type=str |
| 196 | + EnvironmentVariableDisallowingExecutionAndBackendBothSet, |
| 197 | + type=str, |
193 | 198 | ):
|
194 | 199 | """Distribution engine to run queries by."""
|
195 | 200 |
|
@@ -327,9 +332,7 @@ def get(cls) -> str:
|
327 | 332 | return cls._value
|
328 | 333 |
|
329 | 334 |
|
330 |
| -class StorageFormat( |
331 |
| - DisallowExecutionAndBackendInEnvironmentMixin, EnvironmentVariable, type=str |
332 |
| -): |
| 335 | +class StorageFormat(EnvironmentVariableDisallowingExecutionAndBackendBothSet, type=str): |
333 | 336 | """Engine to run on a single node of distribution."""
|
334 | 337 |
|
335 | 338 | @classmethod
|
@@ -395,9 +398,7 @@ def get(cls) -> str:
|
395 | 398 | Execution = namedtuple("Execution", ["storage_format", "engine"])
|
396 | 399 |
|
397 | 400 |
|
398 |
| -class Backend( |
399 |
| - DisallowExecutionAndBackendInEnvironmentMixin, EnvironmentVariable, type=str |
400 |
| -): |
| 401 | +class Backend(EnvironmentVariableDisallowingExecutionAndBackendBothSet, type=str): |
401 | 402 | """
|
402 | 403 | An alias for execution, i.e. the combination of StorageFormat and Engine.
|
403 | 404 |
|
|
0 commit comments