Commit 1beeb406 authored by Matthew Waters's avatar Matthew Waters 🐨
Browse files

build-tools: copy the removed from setuptools

Fixes python programs (like meson) from using libraries from incorrect

Upstream reference:

Fixes: #307
Part-of: <!655>
parent e75c9681
Pipeline #220176 passed with stages
in 66 minutes and 30 seconds
......@@ -17,6 +17,8 @@
# Boston, MA 02111-1307, USA.
import os
import sysconfig
import shutil
from cerbero.config import Config
from cerbero.bootstrap import BootstrapperBase
......@@ -24,9 +26,11 @@ from import Oven
from import CookBook
from cerbero.commands.fetch import Fetch
from cerbero.utils import _, shell
from cerbero.utils import messages as m
from cerbero.errors import FatalError, ConfigurationError
from cerbero.enums import Platform, Architecture, DistroVersion
from pathlib import PurePath
class BuildTools (BootstrapperBase, Fetch):
......@@ -122,7 +126,36 @@ class BuildTools (BootstrapperBase, Fetch): = self.BUILD_TOOLS += self.PLAT_BUILD_TOOLS.get(self.config.platform, [])
def insert_python_site(self):
import setuptools.version as stv
except ImportError:
version = [int(v) for v in stv.__version__.split('.')]
if len(version) < 1 or version[:1] < [49]:
m.warning('detected setuptools >= 49.0.0, installing fallback file. '
# Since python-setuptools 49.0.0, is not installed by
# easy_install/ anymore which breaks python installs outside
# the system prefix.
# Install the previously installed ourselves as a workaround
config = self.cookbook.get_config()
py_prefix = sysconfig.get_path('purelib', vars={'base': ''})
# Must strip \/ to ensure that the path is relative
py_prefix = PurePath(config.prefix) / PurePath(py_prefix.strip('\\/'))
src_file = os.path.join(os.path.dirname(__file__), '')
shutil.copy(src_file, py_prefix / '')
def start(self, jobs=0):
# Check and these at the last minute because we may have installed them
# in system bootstrap += self.check_build_tools()
# Originally kept from
def __boot():
import sys
import os
PYTHONPATH = os.environ.get('PYTHONPATH')
if PYTHONPATH is None or (sys.platform == 'win32' and not PYTHONPATH):
PYTHONPATH = PYTHONPATH.split(os.pathsep)
pic = getattr(sys, 'path_importer_cache', {})
stdpath = sys.path[len(PYTHONPATH):]
mydir = os.path.dirname(__file__)
for item in stdpath:
if item == mydir or not item:
continue # skip if current dir. on Windows, or my own directory
importer = pic.get(item)
if importer is not None:
loader = importer.find_module('site')
if loader is not None:
# This should actually reload the current module
import imp # Avoid import loop in Python 3
stream, path, descr = imp.find_module('site', [item])
except ImportError:
if stream is None:
# This should actually reload the current module
imp.load_module('site', stream, path, descr)
raise ImportError("Couldn't find the real 'site' module")
# 2.2 comp
known_paths = dict([(
makepath(item)[1], 1) for item in sys.path]) # noqa
oldpos = getattr(sys, '__egginsert', 0) # save old insertion position
sys.__egginsert = 0 # and reset the current one
for item in PYTHONPATH:
addsitedir(item) # noqa
sys.__egginsert += oldpos # restore effective old position
d, nd = makepath(stdpath[0]) # noqa
insert_at = None
new_path = []
for item in sys.path:
p, np = makepath(item) # noqa
if np == nd and insert_at is None:
# We've hit the first 'system' path entry, so added entries go here
insert_at = len(new_path)
if np in known_paths or insert_at is None:
# new path after the insert point, back-insert it
new_path.insert(insert_at, item)
insert_at += 1
sys.path[:] = new_path
if __name__ == 'site':
del __boot
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment