Returns a callable for a given setuptools style import string :param str import_name: A console_scripts style import string
(import_name)
| 49 | |
| 50 | |
| 51 | def import_string(import_name): |
| 52 | """Returns a callable for a given setuptools style import string |
| 53 | |
| 54 | :param str import_name: A console_scripts style import string |
| 55 | """ |
| 56 | import_name = str(import_name).replace(":", ".") |
| 57 | |
| 58 | try: |
| 59 | import_module(import_name) |
| 60 | |
| 61 | except ImportError: |
| 62 | if "." not in import_name: |
| 63 | # this is a case like "import name", where continuing to the |
| 64 | # next style of import would not improve the situation, so |
| 65 | # we raise here. |
| 66 | raise |
| 67 | |
| 68 | else: |
| 69 | return sys.modules[import_name] |
| 70 | |
| 71 | # this is a case where the previous attempt may have failed due to |
| 72 | # not being importable. ("not a package", etc) |
| 73 | module_name, obj_name = import_name.rsplit(".", 1) |
| 74 | |
| 75 | try: |
| 76 | module = __import__(module_name, None, None, [obj_name]) |
| 77 | |
| 78 | except ImportError: |
| 79 | # Recurse to support importing modules not yet set up by the parent module |
| 80 | # (or package for that matter) |
| 81 | module = import_string(module_name) |
| 82 | |
| 83 | try: |
| 84 | return getattr(module, obj_name) |
| 85 | |
| 86 | except AttributeError as e: |
| 87 | raise ImportError(e) |
| 88 | |
| 89 | |
| 90 | def cache_path(archive, root_dir, build_id): |
no outgoing calls