Use UMBaseConanfile for reusable functions

Added a recipe in the conan-ultimaker-index repo,
which contains a conanrecipe that can be loaded
as a python_requires.

This allows us to reuse python code over multiple
recipes, see: https://docs.conan.io/en/latest/extending/python_requires.html

Contributes to CURA-9365
This commit is contained in:
j.spijker@ultimaker.com 2022-06-18 11:35:20 +02:00 committed by jspijker
parent 4c1262d9d3
commit dfc0f9b31f

View file

@ -4,7 +4,6 @@ from pathlib import Path
from platform import python_version from platform import python_version
from jinja2 import Template from jinja2 import Template
from semver import *
from conan import ConanFile from conan import ConanFile
from conan.tools import files from conan.tools import files
@ -24,15 +23,21 @@ class CuraConan(ConanFile):
build_policy = "missing" build_policy = "missing"
exports = "LICENSE*" exports = "LICENSE*"
settings = "os", "compiler", "build_type", "arch" settings = "os", "compiler", "build_type", "arch"
no_copy_source = True no_copy_source = True # We won't build so no need to copy sources to the build folder
# FIXME: Remove specific branch once merged to main
# Extending the conanfile with the UMBaseConanfile https://github.com/Ultimaker/conan-ultimaker-index/tree/CURA-9177_Fix_CI_CD/recipes/umbase
python_requires = "umbase/0.1@ultimaker/testing"
python_requires_extend = "umbase.UMBaseConanfile"
options = { options = {
"python_version": "ANY", "python_version": "ANY",
"enterprise": ["True", "False", "true", "false"], "enterprise": ["True", "False", "true", "false"], # Workaround for GH Action passing boolean as lowercase string
"staging": ["True", "False", "true", "false"], "staging": ["True", "False", "true", "false"], # Workaround for GH Action passing boolean as lowercase string
"devtools": [True, False], "devtools": [True, False], # FIXME: Split this up in testing and (development / build (pyinstaller) / system installer) tools
"cloud_api_version": "ANY", "cloud_api_version": "ANY",
"display_name": "ANY", "display_name": "ANY", # TODO: should this be an option??
"cura_debug_mode": [True, False] "cura_debug_mode": [True, False] # FIXME: Use profiles
} }
default_options = { default_options = {
"python_version": "system", "python_version": "system",
@ -50,20 +55,6 @@ class CuraConan(ConanFile):
"revision": "auto" "revision": "auto"
} }
@property
def _conan_data(self):
data = {}
if self.version:
for k, vers in self.conan_data.items():
for v in vers:
if v != "None":
if satisfies(self.version, v, loose = True, include_prerelease = False):
data[k] = vers[v]
else:
for k, ver in self.conan_data.items():
data[k] = ver["None"]
return data
@property @property
def _staging(self): def _staging(self):
return self.options.staging in ["True", 'true'] return self.options.staging in ["True", 'true']
@ -107,7 +98,7 @@ class CuraConan(ConanFile):
raise ConanInvalidConfiguration("Only versions 5+ are support") raise ConanInvalidConfiguration("Only versions 5+ are support")
def requirements(self): def requirements(self):
for req in self._conan_data["requirements"]: for req in self._um_data(self.version)["requirements"]:
self.requires(req) self.requires(req)
def layout(self): def layout(self):
@ -143,7 +134,7 @@ class CuraConan(ConanFile):
with open(Path(self.source_folder, "Ultimaker-Cura.spec.jinja"), "r") as f: with open(Path(self.source_folder, "Ultimaker-Cura.spec.jinja"), "r") as f:
pyinstaller = Template(f.read()) pyinstaller = Template(f.read())
pyinstaller_metadata = self._conan_data["pyinstaller"] pyinstaller_metadata = self._um_data(self.version)["pyinstaller"]
datas = [] datas = []
for data in pyinstaller_metadata["datas"].values(): for data in pyinstaller_metadata["datas"].values():
if "package" in data: # get the paths from conan package if "package" in data: # get the paths from conan package
@ -176,7 +167,7 @@ class CuraConan(ConanFile):
with open(Path(self.generators_folder, "Ultimaker-Cura.spec"), "w") as f: with open(Path(self.generators_folder, "Ultimaker-Cura.spec"), "w") as f:
f.write(pyinstaller.render( f.write(pyinstaller.render(
name = str(self.options.display_name).replace(" ", "-"), name = str(self.options.display_name).replace(" ", "-"),
entrypoint = self._conan_data["runinfo"]["entrypoint"], entrypoint = self._um_data(self.version)["runinfo"]["entrypoint"],
datas = datas, datas = datas,
binaries = binaries, binaries = binaries,
hiddenimports = pyinstaller_metadata["hiddenimports"], hiddenimports = pyinstaller_metadata["hiddenimports"],