Skip to content

Commit

Permalink
FIX-#2473: Some configuration values should not be transformed (#2476)
Browse files Browse the repository at this point in the history
* FIX-#2473: Some configuration values should not be transformed

Signed-off-by: Vasilij Litvinov <[email protected]>

* FIX-#2473: Add tests for ExactStr

Signed-off-by: Vasilij Litvinov <[email protected]>
  • Loading branch information
vnlitvinov authored Nov 25, 2020
1 parent f7f1f7a commit 0c40d61
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 4 additions & 4 deletions modin/config/envvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import warnings
from packaging import version

from .pubsub import Parameter, _TYPE_PARAMS
from .pubsub import Parameter, _TYPE_PARAMS, ExactStr


class EnvironmentVariable(Parameter, type=str, abstract=True):
Expand Down Expand Up @@ -112,7 +112,7 @@ class IsRayCluster(EnvironmentVariable, type=bool):
varname = "MODIN_RAY_CLUSTER"


class RayRedisAddress(EnvironmentVariable, type=str):
class RayRedisAddress(EnvironmentVariable, type=ExactStr):
"""
What Redis address to connect to when running in Ray cluster
"""
Expand Down Expand Up @@ -142,7 +142,7 @@ class Memory(EnvironmentVariable, type=int):
varname = "MODIN_MEMORY"


class RayPlasmaDir(EnvironmentVariable, type=str):
class RayPlasmaDir(EnvironmentVariable, type=ExactStr):
"""
Path to Plasma storage for Ray
"""
Expand All @@ -158,7 +158,7 @@ class IsOutOfCore(EnvironmentVariable, type=bool):
varname = "MODIN_OUT_OF_CORE"


class SocksProxy(EnvironmentVariable, type=str):
class SocksProxy(EnvironmentVariable, type=ExactStr):
"""
SOCKS proxy address if it is needed for SSH to work
"""
Expand Down
12 changes: 12 additions & 0 deletions modin/config/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ class TypeDescriptor(typing.NamedTuple):
help: str


class ExactStr(str):
"""
To be used in type params where no transformations are needed
"""


_TYPE_PARAMS = {
str: TypeDescriptor(
decode=lambda value: value.strip().title(),
normalize=lambda value: value.strip().title(),
verify=lambda value: True,
help="a case-insensitive string",
),
ExactStr: TypeDescriptor(
decode=lambda value: value,
normalize=lambda value: value,
verify=lambda value: True,
help="a string",
),
bool: TypeDescriptor(
Expand Down
10 changes: 5 additions & 5 deletions modin/config/test/test_envvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
import pytest

from modin.config.envvars import EnvironmentVariable, _check_vars
from modin.config.envvars import EnvironmentVariable, _check_vars, ExactStr


@pytest.fixture
Expand All @@ -25,9 +25,9 @@ def make_unknown_env():
del os.environ[varname]


@pytest.fixture
def make_custom_envvar():
class CustomVar(EnvironmentVariable, type=str):
@pytest.fixture(params=[str, ExactStr])
def make_custom_envvar(request):
class CustomVar(EnvironmentVariable, type=request.param):
""" custom var """

default = 10
Expand All @@ -40,7 +40,7 @@ class CustomVar(EnvironmentVariable, type=str):
@pytest.fixture
def set_custom_envvar(make_custom_envvar):
os.environ[make_custom_envvar.varname] = " custom "
yield "Custom"
yield "Custom" if make_custom_envvar.type is str else " custom "
del os.environ[make_custom_envvar.varname]


Expand Down

0 comments on commit 0c40d61

Please sign in to comment.