summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2020-11-05 01:32:28 +0100
committeremkael <emkael@tlen.pl>2020-11-05 01:32:28 +0100
commitddde1c7581457f795daa7be4b659afab133734da (patch)
treeeb12e0471c2aaca7d234e15f0943f7a444309964
parent45dffab74b9423d8495648491681280a51a149ac (diff)
Avoid 'import *' in parent package to allow importing separate converters if using dealconvert as a library
-rw-r--r--dealconvert/__init__.py8
1 files 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]