# HG changeset patch # User Ronny Pfannschmidt # Date 1338418574 -7200 # Node ID 1629b6c5048114ec100d05552765934be939a963 # Parent 747eec42e7ae9cfe821f534760846b361578d27c clean up distutils2.util.resolve_name diff --git a/distutils2/util.py b/distutils2/util.py --- a/distutils2/util.py +++ b/distutils2/util.py @@ -648,26 +648,24 @@ def resolve_name(name): __import__(name) return sys.modules[name] - # FIXME clean up this code! parts = name.split('.') - cursor = len(parts) - module_name = parts[:cursor] - ret = '' + attributes = [] + ret = None - while cursor > 0: + while parts: try: - ret = __import__('.'.join(module_name)) + ret = __import__('.'.join(parts), fromlist=['__doc__']) break except ImportError: - cursor -= 1 - module_name = parts[:cursor] + attributes.append(parts.pop()) - if ret == '': - raise ImportError(parts[0]) + attributes.reverse() + if ret is None: + raise ImportError(attributes[0]) - for part in parts[1:]: + for attr in attributes: try: - ret = getattr(ret, part) + ret = getattr(ret, attr) except AttributeError, exc: raise ImportError(exc) # HG changeset patch # User Ronny Pfannschmidt # Date 1338419197 -7200 # Node ID b3002d439465860fe05e5731f004272f19b07668 # Parent 747eec42e7ae9cfe821f534760846b361578d27c clean up distutils2.util.resolve_name diff --git a/distutils2/util.py b/distutils2/util.py --- a/distutils2/util.py +++ b/distutils2/util.py @@ -648,26 +648,25 @@ def resolve_name(name): __import__(name) return sys.modules[name] - # FIXME clean up this code! parts = name.split('.') - cursor = len(parts) - module_name = parts[:cursor] - ret = '' + attributes = [] + ret = None - while cursor > 0: + while parts: try: - ret = __import__('.'.join(module_name)) + ret = __import__('.'.join(parts), + fromlist=['dummy_value_to_get_the_module']) break except ImportError: - cursor -= 1 - module_name = parts[:cursor] + attributes.append(parts.pop()) - if ret == '': - raise ImportError(parts[0]) + attributes.reverse() + if ret is None: + raise ImportError(attributes[0]) - for part in parts[1:]: + for attr in attributes: try: - ret = getattr(ret, part) + ret = getattr(ret, attr) except AttributeError, exc: raise ImportError(exc)