|
19 | 19 | import ConfigParser as configparser |
20 | 20 |
|
21 | 21 | import mock |
22 | | -import setuptools |
23 | 22 | from commoncode.command import pushd |
24 | 23 | from packvers.requirements import Requirement |
25 | 24 |
|
@@ -54,11 +53,18 @@ def iter_requirements(level, extras, setup_file): |
54 | 53 | setup_requires = {} |
55 | 54 | # change directory to setup.py path |
56 | 55 | with pushd(os.path.dirname(setup_file)): |
57 | | - with mock.patch.object(setuptools, "setup") as mock_setup: |
58 | | - sys.path.append(os.path.dirname(setup_file)) |
59 | | - g = {"__file__": setup_file, "__name__": "__main__"} |
60 | | - with open(setup_file) as sf: |
61 | | - exec(sf.read(), g) |
| 56 | + with open(setup_file) as sf: |
| 57 | + file_contents = sf.read() |
| 58 | + setup_provider = re.findall(r'from ([a-z._]+) import setup', file_contents)[0] |
| 59 | + if not (setup_provider == 'distutils.core' or setup_provider == 'setuptools'): |
| 60 | + print(f"Warning: unable to recognize 'import {setup_provider}' in {setup_file}: " |
| 61 | + "defaulting to 'distutils.core'.") |
| 62 | + setup_provider = 'distutils.core' |
| 63 | + exec(f"import {setup_provider}") |
| 64 | + with mock.patch.object(eval(setup_provider), "setup") as mock_setup: |
| 65 | + sys.path.append(os.path.dirname(setup_file)) |
| 66 | + g = {"__file__": setup_file, "__name__": "__main__"} |
| 67 | + exec(file_contents, g) |
62 | 68 | sys.path.pop() |
63 | 69 | # removing the assertion `assert g["setup"]`` since this is not true for all cases |
64 | 70 | # for example when setuptools.setup() is called instead of setup() |
|
0 commit comments