Cleanup: make format on new install_linux_packages py script.
Also some minor fixes to generator for version numbers of packages.
This commit is contained in:
parent
f692010ae1
commit
e05010b2f2
|
@ -75,6 +75,7 @@ class Package:
|
|||
# (typically, because it is included in a parent package already).
|
||||
"distro_package_names",
|
||||
)
|
||||
|
||||
def __init__(self, name, is_group=False, is_mandatory=False,
|
||||
version=None, version_short=None, version_min=None, version_mex=None,
|
||||
sub_packages=(), distro_package_names={}):
|
||||
|
@ -91,7 +92,7 @@ class Package:
|
|||
|
||||
|
||||
# Absolute minimal required tools to build Blender.
|
||||
BASICS_BUILD_MANDATORY_SUBPACKAGES = (
|
||||
BUILD_MANDATORY_SUBPACKAGES = (
|
||||
Package(name="Build Essentials", is_group=True,
|
||||
sub_packages=(
|
||||
Package(name="GCC",
|
||||
|
@ -154,7 +155,7 @@ BASICS_BUILD_MANDATORY_SUBPACKAGES = (
|
|||
|
||||
|
||||
# Fairly common additional tools useful to build Blender.
|
||||
BASICS_BUILD_OPTIONAL_SUBPACKAGES = (
|
||||
BUILD_OPTIONAL_SUBPACKAGES = (
|
||||
Package(name="Ninja Builder",
|
||||
distro_package_names={DISTRO_ID_DEBIAN: "ninja-build",
|
||||
DISTRO_ID_FEDORA: "ninja-build",
|
||||
|
@ -187,7 +188,7 @@ BASICS_BUILD_OPTIONAL_SUBPACKAGES = (
|
|||
|
||||
|
||||
# Library dependencies that are not provided by precompiled libraries.
|
||||
BASIC_DEPS_CRITICAL_SUBPACKAGES = (
|
||||
DEPS_CRITICAL_SUBPACKAGES = (
|
||||
Package(name="X11 library",
|
||||
distro_package_names={DISTRO_ID_DEBIAN: "libx11-dev",
|
||||
DISTRO_ID_FEDORA: "libX11-devel",
|
||||
|
@ -269,7 +270,7 @@ BASIC_DEPS_CRITICAL_SUBPACKAGES = (
|
|||
|
||||
|
||||
# Basic mandatory set of common libraries to build Blender, which are also available as pre-conmpiled libraries.
|
||||
BASIC_DEPS_MANDATORY_SUBPACKAGES = (
|
||||
DEPS_MANDATORY_SUBPACKAGES = (
|
||||
Package(name="JPEG Library",
|
||||
distro_package_names={DISTRO_ID_DEBIAN: "libjpeg-dev",
|
||||
DISTRO_ID_FEDORA: "libjpeg-turbo-devel",
|
||||
|
@ -365,7 +366,7 @@ BASIC_DEPS_MANDATORY_SUBPACKAGES = (
|
|||
|
||||
|
||||
# Basic optional set of common libraries to build Blender, which are also available as pre-conmpiled libraries.
|
||||
BASIC_DEPS_OPTIONAL_SUBPACKAGES = (
|
||||
DEPS_OPTIONAL_SUBPACKAGES = (
|
||||
Package(name="OpenJPG Library",
|
||||
distro_package_names={DISTRO_ID_DEBIAN: "libopenjp2-7-dev",
|
||||
DISTRO_ID_FEDORA: "openjpeg2-devel",
|
||||
|
@ -499,6 +500,8 @@ def suse_pypackages_name_gen(name):
|
|||
v = "".join(str(i) for i in PackageInstaller.version_tokenize(pp.version_installed)[0][:2])
|
||||
return "python" + v + "-" + name
|
||||
return _gen
|
||||
|
||||
|
||||
PYTHON_SUBPACKAGES = (
|
||||
Package(name="Cython", version="0.29", version_short="0.29", version_min="0.20", version_mex="1.0",
|
||||
distro_package_names={DISTRO_ID_DEBIAN: "cython3",
|
||||
|
@ -664,26 +667,26 @@ BOOST_SUBPACKAGES = (
|
|||
|
||||
# Packages required to build Blender, which are not included in the precompiled libraries.
|
||||
PACKAGES_BASICS_BUILD = (
|
||||
Package(name="Basics Mandatory Build", is_group=True, is_mandatory=True, sub_packages=BASICS_BUILD_MANDATORY_SUBPACKAGES),
|
||||
Package(name="Basics Optional Build", is_group=True, is_mandatory=False, sub_packages=BASICS_BUILD_OPTIONAL_SUBPACKAGES),
|
||||
Package(name="Basic Critical Dependencies", is_group=True, is_mandatory=True, sub_packages=BASIC_DEPS_CRITICAL_SUBPACKAGES),
|
||||
Package(name="Basics Mandatory Build", is_group=True, is_mandatory=True, sub_packages=BUILD_MANDATORY_SUBPACKAGES),
|
||||
Package(name="Basics Optional Build", is_group=True, is_mandatory=False, sub_packages=BUILD_OPTIONAL_SUBPACKAGES),
|
||||
Package(name="Basic Critical Deps", is_group=True, is_mandatory=True, sub_packages=DEPS_CRITICAL_SUBPACKAGES),
|
||||
)
|
||||
|
||||
|
||||
# All packages, required or 'nice to have', to build Blender.
|
||||
# Also covers (as best as possible) the dependencies provided by the precompiled libraries.
|
||||
PACKAGES_ALL = (
|
||||
Package(name="Basics Mandatory Build", is_group=True, is_mandatory=True, sub_packages=BASICS_BUILD_MANDATORY_SUBPACKAGES),
|
||||
Package(name="Basics Optional Build", is_group=True, is_mandatory=False, sub_packages=BASICS_BUILD_OPTIONAL_SUBPACKAGES),
|
||||
Package(name="Basic Critical Dependencies", is_group=True, is_mandatory=True, sub_packages=BASIC_DEPS_CRITICAL_SUBPACKAGES),
|
||||
Package(name="Basic Mandatory Dependencies", is_group=True, is_mandatory=True, sub_packages=BASIC_DEPS_MANDATORY_SUBPACKAGES),
|
||||
Package(name="Basic Optional Dependencies", is_group=True, is_mandatory=False, sub_packages=BASIC_DEPS_OPTIONAL_SUBPACKAGES),
|
||||
Package(name="Basics Mandatory Build", is_group=True, is_mandatory=True, sub_packages=BUILD_MANDATORY_SUBPACKAGES),
|
||||
Package(name="Basics Optional Build", is_group=True, is_mandatory=False, sub_packages=BUILD_OPTIONAL_SUBPACKAGES),
|
||||
Package(name="Basic Critical Deps", is_group=True, is_mandatory=True, sub_packages=DEPS_CRITICAL_SUBPACKAGES),
|
||||
Package(name="Basic Mandatory Deps", is_group=True, is_mandatory=True, sub_packages=DEPS_MANDATORY_SUBPACKAGES),
|
||||
Package(name="Basic Optional Deps", is_group=True, is_mandatory=False, sub_packages=DEPS_OPTIONAL_SUBPACKAGES),
|
||||
|
||||
Package(name="Clang Format", version="10.0", version_short="10.0", version_min="6.0", version_mex="15.0",
|
||||
distro_package_names={DISTRO_ID_DEBIAN: "clang-format",
|
||||
DISTRO_ID_FEDORA: "clang", # On Fedora clang-format is part of the main clang package.
|
||||
DISTRO_ID_SUSE: "clang", # On Suse clang-format is part of the main clang package.
|
||||
DISTRO_ID_ARCH: "clang", # On Arch clang-format is part of the main clang package.
|
||||
DISTRO_ID_FEDORA: "clang", # clang-format is part of the main clang package.
|
||||
DISTRO_ID_SUSE: "clang", # clang-format is part of the main clang package.
|
||||
DISTRO_ID_ARCH: "clang", # clang-format is part of the main clang package.
|
||||
},
|
||||
),
|
||||
Package(name="Python", is_mandatory=True, version="3.10.9", version_short="3.10", version_min="3.10", version_mex="3.12",
|
||||
|
@ -909,6 +912,7 @@ PACKAGES_ALL = (
|
|||
|
||||
class ProgressBar:
|
||||
"""Very basic progress bar printing in the console."""
|
||||
|
||||
def __init__(self, min_value=0, max_value=100, print_len=80, is_known_limit=True):
|
||||
self.value = 0
|
||||
self.min_value = min_value
|
||||
|
@ -965,7 +969,11 @@ class PackageInstaller:
|
|||
pbar.update(steps=2)
|
||||
time.sleep(0.05)
|
||||
pbar.finish()
|
||||
return subprocess.CompletedProcess(args=command, returncode=p.returncode, stdout=p.stdout.read(), stderr=p.stderr.read())
|
||||
return subprocess.CompletedProcess(
|
||||
args=command,
|
||||
returncode=p.returncode,
|
||||
stdout=p.stdout.read(),
|
||||
stderr=p.stderr.read())
|
||||
|
||||
@property
|
||||
def can_install(self):
|
||||
|
@ -1019,6 +1027,9 @@ class PackageInstaller:
|
|||
versions_set.add(version)
|
||||
yield version
|
||||
MEX_RANGE_DIFF = 5
|
||||
VERSION_FACTOR_MAX = 100
|
||||
VERSION_FACTOR_MINRANGE_MULTIPLIER = 2
|
||||
VERSION_FACTOR_STEP_DIVIDER = 10
|
||||
|
||||
version = cls.version_tokenize(package.version)[0][:2]
|
||||
version_min = cls.version_tokenize(package.version_min)[0][:2]
|
||||
|
@ -1040,18 +1051,20 @@ class PackageInstaller:
|
|||
yield from do_yield(str(version_major), versions_set)
|
||||
return
|
||||
|
||||
version_minor_fac = 1
|
||||
version_minor = version[1]
|
||||
version_minor_min = 0 if len(version_min) < 2 else version_min[1]
|
||||
version_minor_mex = 0 if len(version_mex) < 2 else version_mex[0]
|
||||
if ((version_minor >= 100 or version_minor_min >= 100 or version_minor_mex >= 100) and
|
||||
(version_major_min != version_major_mex or version_minor_mex - version_minor_min >= 200)
|
||||
and version_minor // 100 == 0):
|
||||
version_minor_fac = 100
|
||||
elif ((version_minor >= 10 or version_minor_min >= 10 or version_minor_mex >= 10) and
|
||||
(version_major_min != version_major_mex or version_minor_mex - version_minor_min >= 20)
|
||||
and version_minor // 10 == 0):
|
||||
version_minor_fac = 10
|
||||
version_minor_mex = 0 if len(version_mex) < 2 else version_mex[1]
|
||||
version_minor_fac = 1
|
||||
vfac = VERSION_FACTOR_MAX
|
||||
while vfac > 1:
|
||||
version_minor_minrange = vfac * VERSION_FACTOR_MINRANGE_MULTIPLIER
|
||||
is_vfac_in_range = (version_minor >= vfac or version_minor_min >= vfac or version_minor_mex >= vfac)
|
||||
is_version_range_big_enough = (version_major_min != version_major_mex or
|
||||
version_minor_mex - version_minor_min >= version_minor_minrange)
|
||||
if (is_vfac_in_range and is_version_range_big_enough and version_minor % vfac == 0):
|
||||
version_minor_fac = vfac
|
||||
break
|
||||
vfac = vfac // VERSION_FACTOR_STEP_DIVIDER
|
||||
yield from do_yield(str(version_major) + "." + str(version_minor), versions_set)
|
||||
yield from do_yield(str(version_major) + str(version_minor), versions_set)
|
||||
for i in range(1, MEX_RANGE_DIFF):
|
||||
|
@ -1211,7 +1224,8 @@ class PackageInstaller:
|
|||
package_distro_name = self.package_distro_name(package, parent_packages)[0]
|
||||
if package_distro_name is None:
|
||||
if package.is_mandatory:
|
||||
self.settings.logger.warning(f"Mandatory package {info_name} is not defined for {distro_id} distribution, "
|
||||
self.settings.logger.warning(
|
||||
f"Mandatory package {info_name} is not defined for {distro_id} distribution, "
|
||||
"Blender will likely not build at all without it.\n")
|
||||
else:
|
||||
self.settings.logger.info(f"Package {info_name} is not defined for {distro_id} distribution.\n")
|
||||
|
@ -1223,7 +1237,8 @@ class PackageInstaller:
|
|||
# Inherit parent version info if needed and possible.
|
||||
if package.version is None:
|
||||
if not parent_packages:
|
||||
self.settings.logger.critical(f"Package {info_name} ({package_distro_name}) has no version information.")
|
||||
self.settings.logger.critical(
|
||||
f"Package {info_name} ({package_distro_name}) has no version information.")
|
||||
exit(1)
|
||||
package.version = parent_packages[-1].version
|
||||
package.version_short = parent_packages[-1].version_short
|
||||
|
@ -1249,7 +1264,8 @@ class PackageInstaller:
|
|||
package_name = self.package_find(package, package_distro_name)
|
||||
if package_name is None:
|
||||
if package.is_mandatory:
|
||||
self.settings.logger.critical(f"\tFailed to find a matching mandatory {package_distro_name} "
|
||||
self.settings.logger.critical(
|
||||
f"\tFailed to find a matching mandatory {package_distro_name} "
|
||||
f"(withing versions range [{package.version_min}, {package.version_mex}[).")
|
||||
exit(1)
|
||||
self.settings.logger.warning(f"\tFailed to find a matching {package_distro_name} "
|
||||
|
@ -1290,11 +1306,13 @@ class PackageInstaller:
|
|||
# Only from PackageInstaller base class.
|
||||
assert self.__class__ is PackageInstaller
|
||||
packages_info_names = ',\n\t\t\t'.join(packages_distro_names)
|
||||
self.settings.logger.info(f"\tWould install group of packages {package.name}:\n\t\t\t{packages_info_names}.")
|
||||
self.settings.logger.info(
|
||||
f"\tWould install group of packages {package.name}:\n\t\t\t{packages_info_names}.")
|
||||
return True
|
||||
|
||||
if self.settings.no_sudo:
|
||||
self.settings.logger.warning(f"\t--no-sudo enabled, impossible to run apt-get install for {packages_distro_names}.")
|
||||
self.settings.logger.warning(
|
||||
f"\t--no-sudo enabled, impossible to run apt-get install for {packages_distro_names}.")
|
||||
return True
|
||||
|
||||
if not packages_distro_names:
|
||||
|
@ -1308,7 +1326,8 @@ class PackageInstaller:
|
|||
self.settings.logger.critical(f"\tFailed to install packages:\n\t{repr(result)}")
|
||||
exit(1)
|
||||
else:
|
||||
self.settings.logger.warning(f"\tFailed to find install all of {packages_distro_names}:\n\t{repr(result)}")
|
||||
self.settings.logger.warning(
|
||||
f"\tFailed to find install all of {packages_distro_names}:\n\t{repr(result)}")
|
||||
self.settings.logger.debug(repr(result))
|
||||
return result.returncode == 0
|
||||
|
||||
|
@ -1363,19 +1382,35 @@ class PackageInstallerDebian(PackageInstaller):
|
|||
version = self._re_version_candidate.search(str(result.stdout))
|
||||
return version["version"] if version is not None else None
|
||||
|
||||
def package_name_version_gen(self, package, package_distro_name, version=..., suffix="", do_range_version_names=False):
|
||||
def package_name_version_gen(
|
||||
self,
|
||||
package,
|
||||
package_distro_name,
|
||||
version=...,
|
||||
suffix="",
|
||||
do_range_version_names=False):
|
||||
if version is ...:
|
||||
version = package.version_short
|
||||
# Generate versions variants with version between main name and '-dev' suffix, if any.
|
||||
tmp_package_name = package_distro_name.removesuffix("-dev")
|
||||
if tmp_package_name != package_distro_name:
|
||||
for pn in self.package_name_version_gen(package, tmp_package_name, version, suffix="-dev" + suffix, do_range_version_names=do_range_version_names):
|
||||
for pn in self.package_name_version_gen(
|
||||
package,
|
||||
tmp_package_name,
|
||||
version,
|
||||
suffix="-dev" + suffix,
|
||||
do_range_version_names=do_range_version_names):
|
||||
yield pn
|
||||
# Strip any 'version-like' numbers at the end of the package name (already stripped of '-dev' suffix)
|
||||
# and generate versions variants out of it.
|
||||
tmp_package_name = tmp_package_name.rstrip("0123456789.-")
|
||||
if tmp_package_name != package_distro_name:
|
||||
for pn in self.package_name_version_gen(package, tmp_package_name, version, suffix=suffix, do_range_version_names=do_range_version_names):
|
||||
for pn in self.package_name_version_gen(
|
||||
package,
|
||||
tmp_package_name,
|
||||
version,
|
||||
suffix=suffix,
|
||||
do_range_version_names=do_range_version_names):
|
||||
yield pn
|
||||
# Generate version variants from given package name.
|
||||
versions = [version]
|
||||
|
@ -1413,19 +1448,35 @@ class PackageInstallerFedora(PackageInstaller):
|
|||
def package_query_version_get_impl(self, package_distro_name):
|
||||
return self.package_version_get(["sudo", "dnf", "info", "--all", package_distro_name])
|
||||
|
||||
def package_name_version_gen(self, package, package_distro_name, version=..., suffix="", do_range_version_names=False):
|
||||
def package_name_version_gen(
|
||||
self,
|
||||
package,
|
||||
package_distro_name,
|
||||
version=...,
|
||||
suffix="",
|
||||
do_range_version_names=False):
|
||||
if version is ...:
|
||||
version = package.version_short
|
||||
# Generate versions variants with version between main name and '-devel' suffix, if any.
|
||||
tmp_package_name = package_distro_name.removesuffix("-devel")
|
||||
if tmp_package_name != package_distro_name:
|
||||
for pn in self.package_name_version_gen(package, tmp_package_name, version, suffix="-devel" + suffix, do_range_version_names=do_range_version_names):
|
||||
for pn in self.package_name_version_gen(
|
||||
package,
|
||||
tmp_package_name,
|
||||
version,
|
||||
suffix="-devel" + suffix,
|
||||
do_range_version_names=do_range_version_names):
|
||||
yield pn
|
||||
# Strip any 'version-like' numbers at the end of the package name (already stripped of '-devel' suffix)
|
||||
# and generate versions variants out of it.
|
||||
tmp_package_name = tmp_package_name.rstrip("0123456789.-")
|
||||
if tmp_package_name != package_distro_name:
|
||||
for pn in self.package_name_version_gen(package, tmp_package_name, version, suffix=suffix, do_range_version_names=do_range_version_names):
|
||||
for pn in self.package_name_version_gen(
|
||||
package,
|
||||
tmp_package_name,
|
||||
version,
|
||||
suffix=suffix,
|
||||
do_range_version_names=do_range_version_names):
|
||||
yield pn
|
||||
# Generate version variants from given package name.
|
||||
versions = [version]
|
||||
|
@ -1466,19 +1517,35 @@ class PackageInstallerSuse(PackageInstaller):
|
|||
result = self.run_command(["sudo", "zypper", "info", package_distro_name])
|
||||
return self.package_version_get(result)
|
||||
|
||||
def package_name_version_gen(self, package, package_distro_name, version=..., suffix="", do_range_version_names=False):
|
||||
def package_name_version_gen(
|
||||
self,
|
||||
package,
|
||||
package_distro_name,
|
||||
version=...,
|
||||
suffix="",
|
||||
do_range_version_names=False):
|
||||
if version is ...:
|
||||
version = package.version_short
|
||||
# Generate versions variants with version between main name and '-devel' suffix, if any.
|
||||
tmp_package_name = package_distro_name.removesuffix("-devel")
|
||||
if tmp_package_name != package_distro_name:
|
||||
for pn in self.package_name_version_gen(package, tmp_package_name, version, suffix="-devel" + suffix, do_range_version_names=do_range_version_names):
|
||||
for pn in self.package_name_version_gen(
|
||||
package,
|
||||
tmp_package_name,
|
||||
version,
|
||||
suffix="-devel" + suffix,
|
||||
do_range_version_names=do_range_version_names):
|
||||
yield pn
|
||||
# Strip any 'version-like' numbers at the end of the package name (already stripped of '-devel' suffix)
|
||||
# and generate versions variants out of it.
|
||||
tmp_package_name = tmp_package_name.rstrip("0123456789.-")
|
||||
if tmp_package_name != package_distro_name:
|
||||
for pn in self.package_name_version_gen(package, tmp_package_name, version, suffix=suffix, do_range_version_names=do_range_version_names):
|
||||
for pn in self.package_name_version_gen(
|
||||
package,
|
||||
tmp_package_name,
|
||||
version,
|
||||
suffix=suffix,
|
||||
do_range_version_names=do_range_version_names):
|
||||
yield pn
|
||||
# Generate version variants from given package name.
|
||||
versions = [version]
|
||||
|
@ -1516,7 +1583,13 @@ class PackageInstallerArch(PackageInstaller):
|
|||
def package_query_version_get_impl(self, package_distro_name):
|
||||
return self.package_version_get(["pacman", "-Si", package_distro_name])
|
||||
|
||||
def package_name_version_gen(self, package, package_distro_name, version=..., suffix="", do_range_version_names=False):
|
||||
def package_name_version_gen(
|
||||
self,
|
||||
package,
|
||||
package_distro_name,
|
||||
version=...,
|
||||
suffix="",
|
||||
do_range_version_names=False):
|
||||
if version is ...:
|
||||
version = package.version_short
|
||||
# Generate versions variants with version after the main name.
|
||||
|
@ -1525,7 +1598,12 @@ class PackageInstallerArch(PackageInstaller):
|
|||
# and generate versions variants out of it.
|
||||
tmp_package_name = tmp_package_name.rstrip("0123456789.-")
|
||||
if tmp_package_name != package_distro_name:
|
||||
for pn in self.package_name_version_gen(package, tmp_package_name, version, suffix=suffix, do_range_version_names=do_range_version_names):
|
||||
for pn in self.package_name_version_gen(
|
||||
package,
|
||||
tmp_package_name,
|
||||
version,
|
||||
suffix=suffix,
|
||||
do_range_version_names=do_range_version_names):
|
||||
yield pn
|
||||
# Generate version variants from given package name.
|
||||
versions = [version]
|
||||
|
@ -1643,7 +1721,8 @@ def main():
|
|||
logger.addHandler(stdout_handler)
|
||||
settings.logger = logger
|
||||
|
||||
distro_package_installer = PackageInstaller(settings) if settings.show_deps else get_distro_package_installer(settings)
|
||||
distro_package_installer = (PackageInstaller(settings) if settings.show_deps
|
||||
else get_distro_package_installer(settings))
|
||||
distro_package_installer.packages_database_update()
|
||||
|
||||
if settings.all:
|
||||
|
|
Loading…
Reference in New Issue