|
12 | 12 | import tempfile
|
13 | 13 |
|
14 | 14 | from functools import partial, update_wrapper
|
| 15 | +from pathlib import Path |
15 | 16 |
|
16 | 17 | import pytest
|
17 | 18 |
|
18 | 19 | import build.env
|
19 | 20 |
|
| 21 | +from build._compat import tomllib |
| 22 | + |
20 | 23 |
|
21 | 24 | def pytest_addoption(parser):
|
22 | 25 | os.environ['PYTHONWARNINGS'] = 'ignore:DEPRECATION::pip._internal.cli.base_command' # for when not run within tox
|
@@ -101,10 +104,28 @@ def packages_path():
|
101 | 104 | return os.path.realpath(os.path.join(__file__, '..', 'packages'))
|
102 | 105 |
|
103 | 106 |
|
| 107 | +def is_setuptools(package_path): |
| 108 | + if package_path.joinpath('setup.py').is_file(): |
| 109 | + return True |
| 110 | + pyproject = package_path / 'pyproject.toml' |
| 111 | + try: |
| 112 | + with pyproject.open('rb') as f: |
| 113 | + pp = tomllib.load(f) |
| 114 | + except (FileNotFoundError, ValueError): |
| 115 | + return True |
| 116 | + return 'setuptools' in pp.get('build-system', {}).get('build-backend', 'setuptools') |
| 117 | + |
| 118 | + |
104 | 119 | def generate_package_path_fixture(package_name):
|
105 | 120 | @pytest.fixture
|
106 |
| - def fixture(packages_path): |
107 |
| - return os.path.join(packages_path, package_name) |
| 121 | + def fixture(packages_path, tmp_path): |
| 122 | + package_path = Path(packages_path) / package_name |
| 123 | + if not is_setuptools(package_path): |
| 124 | + return str(package_path) |
| 125 | + |
| 126 | + new_path = tmp_path / package_name |
| 127 | + shutil.copytree(package_path, new_path) |
| 128 | + return str(new_path) |
108 | 129 |
|
109 | 130 | return fixture
|
110 | 131 |
|
|
0 commit comments