Last active
May 10, 2024 01:39
-
-
Save zachlewis/7e93d28993a00db3b723e6194b9b9f56 to your computer and use it in GitHub Desktop.
python rez package.py that uses `rye` to download and deploy indygreg builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = "python" | |
version = "3.10.14" | |
authors = ["Guido van Rossum"] | |
description = "The Python programming language" | |
@early() | |
def variants(): | |
import rez.package_py_utils as rezutils, platform | |
p = 'platform-%s' % {'darwin':'osx','windows':'windows','linux':'linux'}[platform.system().lower()] | |
return [rezutils.expand_requires(p, "arch-**")] | |
@early() | |
def tools(): | |
# conditionally enumerate python 2 / 3 tools | |
maj, mnr = this.version.split('.')[0:2] | |
pyver = '.'.join([maj, mnr]) | |
all_vers = ['python{0}', 'python{0}-config', 'pydoc{0}', 'pip{0}'] | |
py2_only = ['smtpd.py'] | |
py3_only = ['pyenv', 'idle3'] | |
tools = py2_only if int(maj) < 3 else py3_only | |
variants = ['', maj, pyver] | |
for tool in all_vers: | |
for variant in variants: | |
tools.append(tool.format(variant)) | |
return tools + ['2to3', 'idle'] | |
@early() | |
def uuid(): | |
import uuid | |
return str(uuid.uuid5(uuid.NAMESPACE_DNS, name)) | |
def pre_build_commands(): | |
import platform | |
is_windows = platform.system() == 'Windows' | |
p = {'darwin':'macos','windows':'windows','linux':'linux'}[platform.system().lower()] | |
arch = 'aarch64' if 'arm' in platform.machine() else 'x86_64' | |
ext = 'exe' if is_windows else 'gz' | |
archive = "rye-x86-windows.exe" if is_windows else f"rye-{arch}-{p}.{ext}" | |
filename = f"rye" if not is_windows else "rye-x86-windows.exe" | |
url = "https://github.com/astral-sh/rye/releases/latest/download/{archive}" | |
download_cmd = "curl -SL --progress-bar %s --output %s" % (url, ("{build.build_path}/%s" % (filename if is_windows else "rye.gz"))) | |
pyver = '{this.version.major}.{this.version.minor}.{this.version.patch}' | |
rye_cmd = "%s fetch cpython@%s --target-path=%s" % (filename, pyver, build.install_path) | |
env.RYE_NO_AUTO_INSTALL = 1 | |
env.REZ_BUILD_DOWNLOAD_CMD = download_cmd | |
env.REZ_BUILD_RYE_CMD = rye_cmd | |
build_command = """ | |
rm -rf {install_path} | |
$REZ_BUILD_DOWNLOAD_CMD | |
if [ ! -f rye-x86-windows.exe ]; then | |
gunzip rye.gz | |
chmod +x rye | |
fi | |
$REZ_BUILD_RYE_CMD | |
if [ ! -f {install_path}/bin/python ]; then | |
#cd {install_path}/bin | |
ln -s {install_path}/bin/python{version.major}.{version.minor} {install_path}/bin/python | |
fi | |
""" | |
def pre_commands(): | |
from tempfile import gettempdir | |
import os | |
env.PYTHONHOME.unset() | |
env.PYTHONPYCACHEPREFIX = os.path.join(gettempdir(), 'rez-pycache') | |
def commands(): | |
env.PATH.prepend("{root}/bin") | |
if building: | |
def abi_ext(): | |
import os | |
libpythons = os.listdir(expandvars(os.path.join('$REZ_PYTHON_ROOT','lib'))) | |
abi_ext = sorted(list(filter(lambda x: 'libpython' in x, libpythons)), key=len)[-1].split('python')[-1][3:] | |
abi = abi_ext.split('.')[0] | |
ext = abi_ext.strip(abi).strip('.') | |
return (abi if not abi.isdigit() else '', ext) | |
abi, ext = abi_ext() | |
maj_min = '{this.version.major}.{this.version.minor}' | |
env.PYTHON_VERSION_ABI = maj_min + abi | |
env.PYTHON_VERSION = env.PYTHON_VERSION_MAJOR_MINOR = maj_min | |
env.Python_ROOT = '{root}' | |
env.Python_LIBRARY = '{root}/lib/libpython{maj_min}{abi}.{ext}' | |
env.Python_EXECUTABLE = '{root}/bin/python{maj_min}{abi}' | |
env.Python_INCLUDE_DIR = '{root}/include/python{maj_min}{abi}' | |
env.PKG_CONFIG_PATH.prepend('{root}/include/pkgconfig') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment