Skip to content

Commit

Permalink
REFACTOR-modin-project#2059: Introduce abstract parameter concept
Browse files Browse the repository at this point in the history
Signed-off-by: Vasilij Litvinov <[email protected]>
  • Loading branch information
vnlitvinov committed Oct 12, 2020
1 parent 86127de commit c530318
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions modin/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

from .pubsub import Parameter
from .envvars import *
from .pubsub import Parameter # noqa: F401
from .envvars import * # noqa: F403, F401
10 changes: 3 additions & 7 deletions modin/config/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from . import *
from . import * # noqa: F403, F401
from .pubsub import Parameter


def print_config_help():
for objname in sorted(globals()):
obj = globals()[objname]
if (
isinstance(obj, type)
and issubclass(obj, Parameter)
and obj is not EnvironmentVariable
and obj is not Parameter
):
if isinstance(obj, type) and issubclass(obj, Parameter) and not obj.is_abstract:
print(f"{obj.get_help()}\n\tCurrent value: {obj.get()}")


Expand Down
6 changes: 3 additions & 3 deletions modin/config/envvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .pubsub import Parameter, _TYPE_PARAMS


class EnvironmentVariable(Parameter, type=str):
class EnvironmentVariable(Parameter, type=str, abstract=True):
"""
Base class for environment variables-based configuration
"""
Expand Down Expand Up @@ -201,9 +201,9 @@ def _check_vars():
valid_names = {
obj.varname
for obj in globals().values()
if obj is not EnvironmentVariable
and isinstance(obj, type)
if isinstance(obj, type)
and issubclass(obj, EnvironmentVariable)
and not obj.is_abstract
}
found_names = {name for name in os.environ.keys() if name.startswith("MODIN_")}
unknown = found_names - valid_names
Expand Down
4 changes: 3 additions & 1 deletion modin/config/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Parameter(object):
choices: typing.Sequence[str] = None
type = str
default = None
is_abstract = True

@classmethod
def _get_raw_from_config(cls) -> str:
Expand All @@ -79,9 +80,10 @@ def get_help(cls) -> str:
"""
raise NotImplementedError()

def __init_subclass__(cls, type, **kw):
def __init_subclass__(cls, type, abstract=False, **kw):
assert type in _TYPE_PARAMS, f"Unsupported variable type: {type}"
cls.type = type
cls.is_abstract = abstract
cls._value = _UNSET
cls._subs = []
cls._once = collections.defaultdict(list)
Expand Down

0 comments on commit c530318

Please sign in to comment.