forked from snowflakedb/snowflake-connector-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.py
55 lines (40 loc) · 1.67 KB
/
options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import warnings
import pkg_resources
from .errors import MissingDependencyError
# Flags to see whether optional dependencies were installed
installed_pandas = False
installed_keyring = False
def warn_incompatible_dep(dep_name: str,
installed_ver: str,
expected_ver: 'pkg_resources.Requirement') -> None:
warnings.warn(
"You have an incompatible version of '{}' installed, please install a version that "
"adheres to: '{}'".format(dep_name,
_expected_version),
stacklevel=2)
class MissingPandas(object):
def __getattr__(self, item):
raise MissingDependencyError('pandas')
class MissingKeyring(object):
def __getattr__(self, item):
raise MissingDependencyError('keyring')
try:
import pandas
# since we enable relative imports without dots this import gives us an issues when ran from test directory
from pandas import DataFrame # NOQA
import pyarrow
installed_pandas = True
# Make sure we have the right pyarrow installed
_pandas_extras = pkg_resources.working_set.by_key['snowflake-connector-python']._dep_map['pandas']
_expected_version = [dep for dep in _pandas_extras if dep.name == 'pyarrow'][0]
_installed_pyarrow = pkg_resources.working_set.by_key['pyarrow']
if _installed_pyarrow and _installed_pyarrow.version not in _expected_version:
warn_incompatible_dep('pyarrow', _installed_pyarrow.version, _expected_version)
except ImportError:
pandas = MissingPandas()
pyarrow = MissingPandas()
try:
import keyring
installed_keyring = True
except ImportError:
keyring = MissingKeyring()