Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR-#2059: Consolidate environment variables #2189

Merged
merged 27 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
91fc628
REFACTOR-#2059: Implement vars in single package
vnlitvinov Sep 30, 2020
30b75ec
REFACTOR-#2059: Simplify passing varname
vnlitvinov Oct 1, 2020
c238647
REFACTOR-#2059: Simplify getter for parameter
vnlitvinov Oct 1, 2020
0ae78da
REFACTOR-#2059: Rename Publisher -> Parameter for clarity
vnlitvinov Oct 1, 2020
cd3610e
REFACTOR-#2059: Improve single vs plural in warning
vnlitvinov Oct 1, 2020
0247ad3
REFACTOR-#2059: Fix defaults for MODIN_ENGINE and MODIN_BACKEND
vnlitvinov Oct 1, 2020
efb007e
REFACTOR-#2059: Make computed default be on demand
vnlitvinov Oct 1, 2020
425ea3f
REFACTOR-#2059: Adapt moved test
vnlitvinov Oct 1, 2020
f5092c0
REFACTOR-#2059: Add parameter value validation
vnlitvinov Oct 1, 2020
227bc26
REFACTOR-#2059: Add tests for envvars
vnlitvinov Oct 1, 2020
f757eec
REFACTOR-#2059: Reduce "import *" effect
vnlitvinov Oct 1, 2020
86127de
REFACTOR-#2059: Beautify help a bit
vnlitvinov Oct 1, 2020
c530318
REFACTOR-#2059: Introduce abstract parameter concept
vnlitvinov Oct 1, 2020
195c0f3
REFACTOR-#2059: Fix flake8 issues
vnlitvinov Oct 1, 2020
d13ffcd
REFACTOR-#2059: Migrate MODIN_EXPERIMENTAL
vnlitvinov Oct 1, 2020
a09fca3
REFACTOR-#2059: Migrate MODIN_RAY_CLUSTER and MODIN_REDIS_ADDRESS
vnlitvinov Oct 1, 2020
c7481cf
REFACTOR-#2059: Migrate MODIN_CPUS
vnlitvinov Oct 1, 2020
902502a
REFACTOR-#2059: Migrate remaining Ray params
vnlitvinov Oct 1, 2020
6707746
REFACTOR-#2059: Migrate SOCKS proxy and RPyC tracing and logging
vnlitvinov Oct 1, 2020
3590b58
REFACTOR-#2059: Migrate remaining vars
vnlitvinov Oct 1, 2020
e85ab96
REFACTOR-#2059: Adapt CI to tests change
vnlitvinov Oct 1, 2020
04a42f7
REFACTOR-#2059: Fix linting and API testing issues
vnlitvinov Oct 1, 2020
b7d522e
REFACTOR-#2059: Fix test_dispatcher
vnlitvinov Oct 1, 2020
2650c7e
REFACTOR-#2059: Mark test_from_sql_distributed as xfail, see #2194
vnlitvinov Oct 2, 2020
d941efa
REFACTOR-#2059: Add missing docstrings
vnlitvinov Oct 2, 2020
433b797
REFACTOR-#2059: Skip coverage for modin/config/tests
vnlitvinov Oct 5, 2020
7c0dc90
REFACTOR-#2059: Add catching env access bypassing config
vnlitvinov Oct 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ jobs:
conda list
- name: Internals tests
shell: bash -l {0}
run: python -m pytest modin/test/test_publisher.py modin/data_management/factories/test/test_dispatcher.py modin/experimental/cloud/test/test_cloud.py
run: python -m pytest modin/data_management/factories/test/test_dispatcher.py modin/experimental/cloud/test/test_cloud.py
- shell: bash -l {0}
run: python -m pytest modin/config/test
- shell: bash -l {0}
run: python -m pytest modin/test/test_envvar_catcher.py

test-defaults:
needs: [lint-commit, lint-flake8, lint-black, test-api, test-headers]
Expand Down
106 changes: 6 additions & 100 deletions modin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

import os
import warnings
from packaging import version
import collections

from ._version import get_versions

Expand All @@ -35,95 +32,6 @@ def custom_formatwarning(msg, category, *args, **kwargs):
)


def get_execution_engine():
# In the future, when there are multiple engines and different ways of
# backing the DataFrame, there will have to be some changed logic here to
# decide these things. In the meantime, we will use the currently supported
# execution engine + backing (Pandas + Ray).
if "MODIN_ENGINE" in os.environ:
# .title allows variants like ray, RAY, Ray
return os.environ["MODIN_ENGINE"].title()
else:
if "MODIN_DEBUG" in os.environ:
return "Python"
else:
try:
import ray

except ImportError:
pass
else:
if version.parse(ray.__version__) < version.parse("1.0.0"):
raise ImportError(
"Please `pip install modin[ray]` to install compatible Ray version."
)
return "Ray"
try:
import dask
import distributed

except ImportError:
raise ImportError(
"Please `pip install modin[ray]` or `modin[dask]` to install an engine"
)
else:
if version.parse(dask.__version__) < version.parse(
"2.1.0"
) or version.parse(distributed.__version__) < version.parse("2.3.2"):
raise ImportError(
"Please `pip install modin[dask]` to install compatible Dask version."
)
return "Dask"


def get_partition_format():
# See note above about engine + backing.
return os.environ.get("MODIN_BACKEND", "Pandas").title()


class Publisher(object):
def __init__(self, name, value):
self.name = name
self.__value = value.title()
self.__subs = []
self.__once = collections.defaultdict(list)

def subscribe(self, callback):
self.__subs.append(callback)
callback(self)

def once(self, onvalue, callback):
onvalue = onvalue.title()
if onvalue == self.__value:
callback(self)
else:
self.__once[onvalue].append(callback)

def get(self):
return self.__value

def _put_nocallback(self, value):
value = value.title() # normalize the value
oldvalue, self.__value = self.__value, value
return oldvalue

def _check_callbacks(self, oldvalue):
if oldvalue == self.__value:
return
for callback in self.__subs:
callback(self)
once = self.__once.pop(self.__value, ())
for callback in once:
callback(self)

def put(self, value):
self._check_callbacks(self._put_nocallback(value))


execution_engine = Publisher(name="execution_engine", value=get_execution_engine())
partition_format = Publisher(name="partition_format", value=get_partition_format())


def set_backends(engine=None, partition=None):
"""
Method to set the _pair_ of execution engine and partition format simultaneously.
Expand All @@ -132,24 +40,22 @@ def set_backends(engine=None, partition=None):

The method returns pair of old values, so it is easy to return back.
"""
from .config import Engine, Backend

old_engine, old_partition = None, None
# defer callbacks until both entities are set
if engine is not None:
old_engine = execution_engine._put_nocallback(engine)
old_engine = Engine._put_nocallback(engine)
if partition is not None:
old_partition = partition_format._put_nocallback(partition)
old_partition = Backend._put_nocallback(partition)
# execute callbacks if something was changed
if old_engine is not None:
execution_engine._check_callbacks(old_engine)
Engine._check_callbacks(old_engine)
if old_partition is not None:
partition_format._check_callbacks(old_partition)
Backend._check_callbacks(old_partition)

return old_engine, old_partition


# We don't want these used outside of this file.
del get_execution_engine
del get_partition_format

__version__ = get_versions()["version"]
del get_versions
15 changes: 15 additions & 0 deletions modin/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Licensed to Modin Development Team under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The Modin Development Team licenses this file to you under the
# Apache License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

from .pubsub import Parameter # noqa: F401
from .envvars import * # noqa: F403, F401
26 changes: 26 additions & 0 deletions modin/config/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to Modin Development Team under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The Modin Development Team licenses this file to you under the
# Apache License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

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 not obj.is_abstract:
print(f"{obj.get_help()}\n\tCurrent value: {obj.get()}") # noqa: T001


if __name__ == "__main__":
print_config_help()
Loading