Commit 7eff80b6 authored by Christophe Benz's avatar Christophe Benz
Browse files

Don't leak "spec" in outer scope, use importlib_resources

parent be94ecdf
......@@ -20,15 +20,19 @@ log = logging.getLogger(__name__)
VALIDATA_MAX_ROWS = 100000
# Import all custom checks classes
cs_dir = Path(__file__).parent / 'custom_checks'
for check_file in cs_dir.glob('*.py'):
spec = importlib.util.spec_from_file_location(check_file.stem, str(check_file))
if spec is None:
log.error('spec is None for %r', str(check_file))
else:
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
def import_custom_checks():
"""Import all custom checks classes"""
with importlib_resources.path('validata_core', 'custom_checks') as cs_dir:
for check_file in cs_dir.glob('*.py'):
spec = importlib.util.spec_from_file_location(check_file.stem, str(check_file))
if spec is None:
log.error('spec is None for %r', str(check_file))
else:
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
import_custom_checks()
def get_schemas_config():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment