diff options
author | emkael <emkael@tlen.pl> | 2020-11-05 01:32:28 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-11-05 01:32:28 +0100 |
commit | ddde1c7581457f795daa7be4b659afab133734da (patch) | |
tree | eb12e0471c2aaca7d234e15f0943f7a444309964 | |
parent | 45dffab74b9423d8495648491681280a51a149ac (diff) |
Avoid 'import *' in parent package to allow importing separate converters if using dealconvert as a library
-rw-r--r-- | dealconvert/__init__.py | 8 |
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] |