|
17 | 17 | # Boston, MA 02111-1307, USA.
|
18 | 18 |
|
19 | 19 | import os
|
| 20 | +import sysconfig |
| 21 | +import shutil |
20 | 22 |
|
21 | 23 | from cerbero.config import Config, Platform, DistroVersion
|
22 | 24 | from cerbero.bootstrap import BootstrapperBase
|
23 | 25 | from cerbero.build.oven import Oven
|
24 | 26 | from cerbero.build.cookbook import CookBook
|
25 | 27 | from cerbero.commands.fetch import Fetch
|
26 | 28 | from cerbero.utils import _, shell
|
| 29 | +from cerbero.utils import messages as m |
27 | 30 | from cerbero.errors import FatalError, ConfigurationError
|
28 | 31 |
|
| 32 | +from pathlib import PurePath |
29 | 33 |
|
30 | 34 | class BuildTools (BootstrapperBase, Fetch):
|
31 | 35 |
|
@@ -120,8 +124,36 @@ def _setup_env(self):
|
120 | 124 | self.recipes = self.BUILD_TOOLS
|
121 | 125 | self.recipes += self.PLAT_BUILD_TOOLS.get(self.config.platform, [])
|
122 | 126 |
|
123 |
| - def start(self): |
| 127 | + def insert_python_site(self): |
| 128 | + try: |
| 129 | + import setuptools.version as stv |
| 130 | + except ImportError: |
| 131 | + return |
| 132 | + |
| 133 | + version = [int(v) for v in stv.__version__.split('.')] |
| 134 | + if len(version) < 1 or version[:1] < [49]: |
| 135 | + return |
| 136 | + |
| 137 | + m.warning('detected setuptools >= 49.0.0, installing fallback site.py file. ' |
| 138 | + 'See https://github.com/pypa/setuptools/issues/2295') |
| 139 | + |
| 140 | + # Since python-setuptools 49.0.0, site.py is not installed by |
| 141 | + # easy_install/setup.py anymore which breaks python installs outside |
| 142 | + # the system prefix. |
| 143 | + # https://github.com/pypa/setuptools/issues/2295 |
| 144 | + # |
| 145 | + # Install the previously installed site.py ourselves as a workaround |
| 146 | + config = self.cookbook.get_config() |
| 147 | + |
| 148 | + py_prefix = sysconfig.get_path('purelib', vars={'base': ''}) |
| 149 | + # Must strip \/ to ensure that the path is relative |
| 150 | + py_prefix = PurePath(config.prefix) / PurePath(py_prefix.strip('\\/')) |
| 151 | + src_file = os.path.join(os.path.dirname(__file__), 'site-patch.py') |
| 152 | + shutil.copy(src_file, py_prefix / 'site.py') |
| 153 | + |
| 154 | + def start(self, jobs=0): |
124 | 155 | self._setup_env()
|
| 156 | + self.insert_python_site() |
125 | 157 | # Check build tools at the last minute because we may have installed them
|
126 | 158 | # in system bootstrap
|
127 | 159 | self.recipes += self.check_build_tools()
|
|
0 commit comments