From ddde1c7581457f795daa7be4b659afab133734da Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 5 Nov 2020 01:32:28 +0100 Subject: Avoid 'import *' in parent package to allow importing separate converters if using dealconvert as a library --- dealconvert/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dealconvert/__init__.py b/dealconvert/__init__.py index 7bb1325..60dbed5 100644 --- a/dealconvert/__init__.py +++ b/dealconvert/__init__.py @@ -1,4 +1,5 @@ -from .formats import * +from importlib import import_module + class DealConverter(object): def __init__(self, input_file=None, **kwargs): @@ -14,10 +15,11 @@ class DealConverter(object): self.detect_format(output).output(output, deal_set, True) def detect_format(self, filename, interactive=True): - for deal_format in globals()['formats'].__all__: + for deal_format in import_module('.formats', 'dealconvert').__all__: if deal_format not in self.formats: + mod = import_module('.formats.' + deal_format, 'dealconvert') self.formats[deal_format] = getattr( - globals()[deal_format], + mod, deal_format.upper() + 'Format')(interactive, **self.format_options) if self.formats[deal_format].match_file(filename): return self.formats[deal_format] -- cgit v1.2.3