From 0f8b92ddc63441a54269be9acf7b9cf65b6ce20c Mon Sep 17 00:00:00 2001 From: Frances Hartwell Date: Tue, 9 May 2023 10:00:35 -0400 Subject: [PATCH] Add add-on detection for constraints (#1412) * add ability to find constraint addons * fix error message * fix test --- sdv/_addons.py | 2 +- sdv/constraints/__init__.py | 4 +++- tests/unit/test__addons.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sdv/_addons.py b/sdv/_addons.py index 07f3fae09..37ef2dc9e 100644 --- a/sdv/_addons.py +++ b/sdv/_addons.py @@ -21,7 +21,7 @@ def _find_addons(group, parent_globals, add_all=False): try: module = entry_point.load() except Exception: - msg = f'Failed to load "{entry_point.name}" from "{entry_point.module}".' + msg = f'Failed to load "{entry_point.name}" from "{entry_point.module_name}".' warnings.warn(msg) continue diff --git a/sdv/constraints/__init__.py b/sdv/constraints/__init__.py index ac065dabc..6a1779e15 100644 --- a/sdv/constraints/__init__.py +++ b/sdv/constraints/__init__.py @@ -1,5 +1,5 @@ """SDV Constraints module.""" - +from sdv._addons import _find_addons from sdv.constraints.base import Constraint from sdv.constraints.tabular import ( FixedCombinations, FixedIncrements, Inequality, Negative, OneHotEncoding, Positive, Range, @@ -19,3 +19,5 @@ 'OneHotEncoding', 'Unique' ] + +_find_addons('sdv.constraints_modules', globals(), add_all=True) diff --git a/tests/unit/test__addons.py b/tests/unit/test__addons.py index 205d806b3..2d7eda586 100644 --- a/tests/unit/test__addons.py +++ b/tests/unit/test__addons.py @@ -80,7 +80,7 @@ def entry_point_error(): bad_entry_point = Mock() bad_entry_point.name = 'bad_entry_point' - bad_entry_point.module = 'bad_module' + bad_entry_point.module_name = 'bad_module' bad_entry_point.load.side_effect = entry_point_error entry_points_mock.return_value = [bad_entry_point] test_dict = {}