Skip to content

Commit

Permalink
REFACTOR-#4629: Add type annotations to modin/config (#4685)
Browse files Browse the repository at this point in the history
Signed-off-by: Karthik Velayutham <vkarthik@ponder.io>
  • Loading branch information
Karthik Velayutham committed Jul 26, 2022
1 parent f5f4c16 commit 0236358
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 49 deletions.
1 change: 1 addition & 0 deletions docs/release_notes/release_notes-0.16.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Key Features and Updates
* REFACTOR-#4530: Standardize access to physical data in partitions (#4563)
* REFACTOR-#4534: Replace logging meta class with class decorator (#4535)
* REFACTOR-#4708: Delete combine dtypes (#4709)
* REFACTOR-#4629: Add type annotations to modin/config (#4685)
* Pandas API implementations and improvements
* FEAT-#4670: Implement convert_dtypes by mapping across partitions (#4671)
* OmniSci enhancements
Expand Down
8 changes: 5 additions & 3 deletions modin/config/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
import argparse


def print_config_help():
def print_config_help() -> None:
"""Print configs help messages."""
for objname in sorted(globals()):
obj = globals()[objname]
if isinstance(obj, type) and issubclass(obj, Parameter) and not obj.is_abstract:
print(f"{obj.get_help()}\n\tCurrent value: {obj.get()}") # noqa: T201


def export_config_help(filename: str):
def export_config_help(filename: str) -> None:
"""
Export all configs help messages to the CSV file.
Expand All @@ -57,7 +57,9 @@ def export_config_help(filename: str):
if obj.__name__ != "RayRedisPassword"
else "random string",
# `Notes` `-` underlining can't be correctly parsed inside csv table by sphinx
"Description": dedent(obj.__doc__).replace("Notes\n-----", "Notes:\n"),
"Description": dedent(obj.__doc__ or "").replace(
"Notes\n-----", "Notes:\n"
),
"Options": obj.choices,
}
configs_data.append(data)
Expand Down
41 changes: 23 additions & 18 deletions modin/config/envvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import secrets

from .pubsub import Parameter, _TYPE_PARAMS, ExactStr, ValueSource
from typing import Optional


class EnvironmentVariable(Parameter, type=str, abstract=True):
"""Base class for environment variables-based configuration."""

varname: str = None
varname: Optional[str] = None

@classmethod
def _get_raw_from_config(cls) -> str:
Expand All @@ -40,9 +41,13 @@ def _get_raw_from_config(cls) -> str:
Raises
------
TypeError
If `varname` is None.
KeyError
If value is absent.
"""
if cls.varname is None:
raise TypeError("varname should not be None")
return os.environ[cls.varname]

@classmethod
Expand Down Expand Up @@ -73,7 +78,7 @@ class Engine(EnvironmentVariable, type=str):
choices = ("Ray", "Dask", "Python", "Native")

@classmethod
def _get_default(cls):
def _get_default(cls) -> str:
"""
Get default value of the config.
Expand Down Expand Up @@ -170,7 +175,7 @@ class CpuCount(EnvironmentVariable, type=int):
varname = "MODIN_CPUS"

@classmethod
def _get_default(cls):
def _get_default(cls) -> int:
"""
Get default value of the config.
Expand Down Expand Up @@ -208,7 +213,7 @@ class NPartitions(EnvironmentVariable, type=int):
varname = "MODIN_NPARTITIONS"

@classmethod
def _put(cls, value):
def _put(cls, value: int) -> None:
"""
Put specific value if NPartitions wasn't set by a user yet.
Expand All @@ -226,7 +231,7 @@ def _put(cls, value):
cls.put(value)

@classmethod
def _get_default(cls):
def _get_default(cls) -> int:
"""
Get default value of the config.
Expand Down Expand Up @@ -318,17 +323,17 @@ class ProgressBar(EnvironmentVariable, type=bool):
default = False

@classmethod
def enable(cls):
def enable(cls) -> None:
"""Enable ``ProgressBar`` feature."""
cls.put(True)

@classmethod
def disable(cls):
def disable(cls) -> None:
"""Disable ``ProgressBar`` feature."""
cls.put(False)

@classmethod
def put(cls, value):
def put(cls, value: bool) -> None:
"""
Set ``ProgressBar`` value only if synchronous benchmarking is disabled.
Expand All @@ -349,7 +354,7 @@ class BenchmarkMode(EnvironmentVariable, type=bool):
default = False

@classmethod
def put(cls, value):
def put(cls, value: bool) -> None:
"""
Set ``BenchmarkMode`` value only if progress bar feature is disabled.
Expand All @@ -371,17 +376,17 @@ class LogMode(EnvironmentVariable, type=ExactStr):
default = "disable"

@classmethod
def enable(cls):
def enable(cls) -> None:
"""Enable all logging levels."""
cls.put("enable")

@classmethod
def disable(cls):
def disable(cls) -> None:
"""Disable logging feature."""
cls.put("disable")

@classmethod
def enable_api_only(cls):
def enable_api_only(cls) -> None:
"""Enable API level logging."""
cls.put("enable_api_only")

Expand All @@ -393,7 +398,7 @@ class LogMemoryInterval(EnvironmentVariable, type=int):
default = 5

@classmethod
def put(cls, value):
def put(cls, value: int) -> None:
"""
Set ``LogMemoryInterval`` with extra checks.
Expand Down Expand Up @@ -427,7 +432,7 @@ class LogFileSize(EnvironmentVariable, type=int):
default = 10

@classmethod
def put(cls, value):
def put(cls, value: int) -> None:
"""
Set ``LogFileSize`` with extra checks.
Expand Down Expand Up @@ -484,7 +489,7 @@ class OmnisciLaunchParameters(EnvironmentVariable, type=dict):
}

@classmethod
def get(self):
def get(self) -> dict:
"""
Get the resulted command-line options.
Expand Down Expand Up @@ -515,7 +520,7 @@ class MinPartitionSize(EnvironmentVariable, type=int):
default = 32

@classmethod
def put(cls, value):
def put(cls, value: int) -> None:
"""
Set ``MinPartitionSize`` with extra checks.
Expand All @@ -529,7 +534,7 @@ def put(cls, value):
super().put(value)

@classmethod
def get(cls):
def get(cls) -> int:
"""
Get ``MinPartitionSize`` with extra checks.
Expand Down Expand Up @@ -564,7 +569,7 @@ class ReadSqlEngine(EnvironmentVariable, type=str):
choices = ("Pandas", "Connectorx")


def _check_vars():
def _check_vars() -> None:
"""
Check validity of environment variables.
Expand Down
Loading

0 comments on commit 0236358

Please sign in to comment.