-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make release-tag: Merge branch 'master' into stable
- Loading branch information
Showing
9 changed files
with
206 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
__author__ = 'DataCebo, Inc.' | ||
__email__ = '[email protected]' | ||
__version__ = '0.8.0' | ||
__version__ = '0.9.0.dev1' | ||
|
||
import contextlib | ||
import importlib | ||
|
@@ -13,6 +13,10 @@ | |
import numpy as np | ||
import pandas as pd | ||
|
||
from copulas._addons import _find_addons | ||
|
||
_find_addons(group='copulas_modules', parent_globals=globals()) | ||
|
||
EPSILON = np.finfo(np.float32).eps | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Copulas add-ons functionality.""" | ||
import warnings | ||
|
||
from pkg_resources import iter_entry_points | ||
|
||
|
||
def _find_addons(group, parent_globals): | ||
"""Find and load add-ons based on the given group. | ||
Args: | ||
group (str): | ||
The name of the entry points group to load. | ||
parent_globals (dict): | ||
The caller's global scope. Modules will be added | ||
to the parent's global scope through their name. | ||
""" | ||
for entry_point in iter_entry_points(group=group): | ||
try: | ||
module = entry_point.load() | ||
except Exception: | ||
msg = f'Failed to load "{entry_point.name}" from "{entry_point.module}".' | ||
warnings.warn(msg) | ||
continue | ||
|
||
if entry_point.name not in parent_globals: | ||
parent_globals[entry_point.name] = module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
from copulas._addons import _find_addons | ||
|
||
|
||
@patch('copulas._addons.iter_entry_points') | ||
def test__find_versions(entry_points_mock): | ||
"""Test loading an add-on.""" | ||
# Setup | ||
entry_point = Mock() | ||
entry_point.name = 'entry_name' | ||
entry_point.load.return_value = 'entry_point' | ||
entry_points_mock.return_value = [entry_point] | ||
test_dict = {} | ||
|
||
# Run | ||
_find_addons(group='group', parent_globals=test_dict) | ||
|
||
# Assert | ||
entry_points_mock.assert_called_once_with(group='group') | ||
assert test_dict['entry_name'] == 'entry_point' | ||
|
||
|
||
@patch('copulas._addons.warnings.warn') | ||
@patch('copulas._addons.iter_entry_points') | ||
def test__find_versions_bad_addon(entry_points_mock, warning_mock): | ||
"""Test failing to load an add-on generates a warning.""" | ||
# Setup | ||
def entry_point_error(): | ||
raise ValueError() | ||
|
||
bad_entry_point = Mock() | ||
bad_entry_point.name = 'bad_entry_point' | ||
bad_entry_point.module = 'bad_module' | ||
bad_entry_point.load.side_effect = entry_point_error | ||
entry_points_mock.return_value = [bad_entry_point] | ||
test_dict = {} | ||
msg = 'Failed to load "bad_entry_point" from "bad_module".' | ||
|
||
# Run | ||
_find_addons(group='group', parent_globals=test_dict) | ||
|
||
# Assert | ||
entry_points_mock.assert_called_once_with(group='group') | ||
warning_mock.assert_called_once_with(msg) |
Oops, something went wrong.