Skip to content

Commit cc57954

Browse files
authored
REFACTOR-#2059: Consolidate environment variables (#2189)
Signed-off-by: Vasilij Litvinov <vasilij.n.litvinov@intel.com>
1 parent b0ef05c commit cc57954

39 files changed

+794
-288
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ jobs:
166166
conda list
167167
- name: Internals tests
168168
shell: bash -l {0}
169-
run: python -m pytest modin/test/test_publisher.py modin/data_management/factories/test/test_dispatcher.py modin/experimental/cloud/test/test_cloud.py
169+
run: python -m pytest modin/data_management/factories/test/test_dispatcher.py modin/experimental/cloud/test/test_cloud.py
170+
- shell: bash -l {0}
171+
run: python -m pytest modin/config/test
172+
- shell: bash -l {0}
173+
run: python -m pytest modin/test/test_envvar_catcher.py
170174

171175
test-defaults:
172176
needs: [lint-commit, lint-flake8, lint-black, test-api, test-headers]

modin/__init__.py

Lines changed: 6 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific language
1212
# governing permissions and limitations under the License.
1313

14-
import os
1514
import warnings
16-
from packaging import version
17-
import collections
1815

1916
from ._version import get_versions
2017

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

3734

38-
def get_execution_engine():
39-
# In the future, when there are multiple engines and different ways of
40-
# backing the DataFrame, there will have to be some changed logic here to
41-
# decide these things. In the meantime, we will use the currently supported
42-
# execution engine + backing (Pandas + Ray).
43-
if "MODIN_ENGINE" in os.environ:
44-
# .title allows variants like ray, RAY, Ray
45-
return os.environ["MODIN_ENGINE"].title()
46-
else:
47-
if "MODIN_DEBUG" in os.environ:
48-
return "Python"
49-
else:
50-
try:
51-
import ray
52-
53-
except ImportError:
54-
pass
55-
else:
56-
if version.parse(ray.__version__) < version.parse("1.0.0"):
57-
raise ImportError(
58-
"Please `pip install modin[ray]` to install compatible Ray version."
59-
)
60-
return "Ray"
61-
try:
62-
import dask
63-
import distributed
64-
65-
except ImportError:
66-
raise ImportError(
67-
"Please `pip install modin[ray]` or `modin[dask]` to install an engine"
68-
)
69-
else:
70-
if version.parse(dask.__version__) < version.parse(
71-
"2.1.0"
72-
) or version.parse(distributed.__version__) < version.parse("2.3.2"):
73-
raise ImportError(
74-
"Please `pip install modin[dask]` to install compatible Dask version."
75-
)
76-
return "Dask"
77-
78-
79-
def get_partition_format():
80-
# See note above about engine + backing.
81-
return os.environ.get("MODIN_BACKEND", "Pandas").title()
82-
83-
84-
class Publisher(object):
85-
def __init__(self, name, value):
86-
self.name = name
87-
self.__value = value.title()
88-
self.__subs = []
89-
self.__once = collections.defaultdict(list)
90-
91-
def subscribe(self, callback):
92-
self.__subs.append(callback)
93-
callback(self)
94-
95-
def once(self, onvalue, callback):
96-
onvalue = onvalue.title()
97-
if onvalue == self.__value:
98-
callback(self)
99-
else:
100-
self.__once[onvalue].append(callback)
101-
102-
def get(self):
103-
return self.__value
104-
105-
def _put_nocallback(self, value):
106-
value = value.title() # normalize the value
107-
oldvalue, self.__value = self.__value, value
108-
return oldvalue
109-
110-
def _check_callbacks(self, oldvalue):
111-
if oldvalue == self.__value:
112-
return
113-
for callback in self.__subs:
114-
callback(self)
115-
once = self.__once.pop(self.__value, ())
116-
for callback in once:
117-
callback(self)
118-
119-
def put(self, value):
120-
self._check_callbacks(self._put_nocallback(value))
121-
122-
123-
execution_engine = Publisher(name="execution_engine", value=get_execution_engine())
124-
partition_format = Publisher(name="partition_format", value=get_partition_format())
125-
126-
12735
def set_backends(engine=None, partition=None):
12836
"""
12937
Method to set the _pair_ of execution engine and partition format simultaneously.
@@ -132,24 +40,22 @@ def set_backends(engine=None, partition=None):
13240
13341
The method returns pair of old values, so it is easy to return back.
13442
"""
43+
from .config import Engine, Backend
44+
13545
old_engine, old_partition = None, None
13646
# defer callbacks until both entities are set
13747
if engine is not None:
138-
old_engine = execution_engine._put_nocallback(engine)
48+
old_engine = Engine._put_nocallback(engine)
13949
if partition is not None:
140-
old_partition = partition_format._put_nocallback(partition)
50+
old_partition = Backend._put_nocallback(partition)
14151
# execute callbacks if something was changed
14252
if old_engine is not None:
143-
execution_engine._check_callbacks(old_engine)
53+
Engine._check_callbacks(old_engine)
14454
if old_partition is not None:
145-
partition_format._check_callbacks(old_partition)
55+
Backend._check_callbacks(old_partition)
14656

14757
return old_engine, old_partition
14858

14959

150-
# We don't want these used outside of this file.
151-
del get_execution_engine
152-
del get_partition_format
153-
15460
__version__ = get_versions()["version"]
15561
del get_versions

modin/config/__init__.py

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

modin/config/__main__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to Modin Development Team under one or more contributor license agreements.
2+
# See the NOTICE file distributed with this work for additional information regarding
3+
# copyright ownership. The Modin Development Team licenses this file to you under the
4+
# Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
# compliance with the License. You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed under
10+
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific language
12+
# governing permissions and limitations under the License.
13+
14+
from . import * # noqa: F403, F401
15+
from .pubsub import Parameter
16+
17+
18+
def print_config_help():
19+
for objname in sorted(globals()):
20+
obj = globals()[objname]
21+
if isinstance(obj, type) and issubclass(obj, Parameter) and not obj.is_abstract:
22+
print(f"{obj.get_help()}\n\tCurrent value: {obj.get()}") # noqa: T001
23+
24+
25+
if __name__ == "__main__":
26+
print_config_help()

0 commit comments

Comments
 (0)