Skip to content

Commit

Permalink
Lazily import implementations
Browse files Browse the repository at this point in the history
This fixes setup.py throwing ImportError.
  • Loading branch information
dahlia committed Jan 16, 2021
1 parent e1ec45b commit da4c476
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions hanja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import warnings

from hanja.impl import is_hanja, is_valid_mode, split_hanja, translate


__all__ = ["is_hanja", "is_valid_mode", "split_hanja", "translate"]
__author__ = "Sumin Byeon"
Expand All @@ -31,3 +29,23 @@ def new_func(*args, **kwargs):
new_func.__doc__ = func.__doc__
new_func.__dict__.update(func.__dict__)
return new_func


def lazily_import(import_string):
import_path, func_name = import_string.split(':')

def load_and_call(*args, **kwargs):
mod = __import__(import_path)
for mod_name in import_path.split('.')[1:]:
mod = getattr(mod, mod_name)
func = getattr(mod, func_name)
globals()[func_name] = func
return func(*args, **kwargs)

globals()[func_name] = load_and_call


lazily_import('hanja.impl:is_hanja')
lazily_import('hanja.impl:is_valid_mode')
lazily_import('hanja.impl:split_hanja')
lazily_import('hanja.impl:translate')

0 comments on commit da4c476

Please sign in to comment.