|
1 | 1 | from os.path import basename, dirname, exists, isdir, isfile, join, realpath, split
|
2 |
| -import importlib |
3 | 2 | import glob
|
4 | 3 | from shutil import rmtree
|
5 | 4 | from six import PY2, with_metaclass
|
|
21 | 20 | from pythonforandroid.util import (urlretrieve, current_directory, ensure_dir,
|
22 | 21 | BuildInterruptingException)
|
23 | 22 |
|
24 |
| -# this import is necessary to keep imp.load_source from complaining :) |
25 |
| -if PY2: |
26 |
| - import imp |
27 |
| - import_recipe = imp.load_source |
28 |
| -else: |
29 |
| - import importlib.util |
30 |
| - if hasattr(importlib.util, 'module_from_spec'): |
31 |
| - def import_recipe(module, filename): |
| 23 | + |
| 24 | +def import_recipe(module, filename): |
| 25 | + if PY2: |
| 26 | + import imp |
| 27 | + import warnings |
| 28 | + with warnings.catch_warnings(): |
| 29 | + # ignores warnings raised by hierarchical module names |
| 30 | + # (names containing dots) on Python 2 |
| 31 | + warnings.simplefilter("ignore", RuntimeWarning) |
| 32 | + return imp.load_source(module, filename) |
| 33 | + else: |
| 34 | + # Python 3.5+ |
| 35 | + import importlib.util |
| 36 | + if hasattr(importlib.util, 'module_from_spec'): |
32 | 37 | spec = importlib.util.spec_from_file_location(module, filename)
|
33 | 38 | mod = importlib.util.module_from_spec(spec)
|
34 | 39 | spec.loader.exec_module(mod)
|
35 | 40 | return mod
|
36 |
| - else: |
37 |
| - from importlib.machinery import SourceFileLoader |
38 |
| - |
39 |
| - def import_recipe(module, filename): |
| 41 | + else: |
| 42 | + # Python 3.3 and 3.4: |
| 43 | + from importlib.machinery import SourceFileLoader |
40 | 44 | return SourceFileLoader(module, filename).load_module()
|
41 | 45 |
|
42 | 46 |
|
|
0 commit comments