conanfile.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. import os
  2. from pathlib import Path
  3. from jinja2 import Template
  4. from conan import ConanFile
  5. from conan.tools.files import copy, rmdir, save, mkdir
  6. from conan.tools.microsoft import unix_path
  7. from conan.tools.env import VirtualRunEnv, Environment, VirtualBuildEnv
  8. from conan.tools.scm import Version
  9. from conan.errors import ConanInvalidConfiguration, ConanException
  10. required_conan_version = "<=1.56.0"
  11. class CuraConan(ConanFile):
  12. name = "cura"
  13. license = "LGPL-3.0"
  14. author = "UltiMaker"
  15. url = "https://github.com/Ultimaker/cura"
  16. description = "3D printer / slicing GUI built on top of the Uranium framework"
  17. topics = ("conan", "python", "pyqt6", "qt", "qml", "3d-printing", "slicer")
  18. build_policy = "missing"
  19. exports = "LICENSE*", "UltiMaker-Cura.spec.jinja", "CuraVersion.py.jinja"
  20. settings = "os", "compiler", "build_type", "arch"
  21. no_copy_source = True # We won't build so no need to copy sources to the build folder
  22. # FIXME: Remove specific branch once merged to main
  23. # Extending the conanfile with the UMBaseConanfile https://github.com/Ultimaker/conan-ultimaker-index/tree/CURA-9177_Fix_CI_CD/recipes/umbase
  24. python_requires = "umbase/[>=0.1.7]@ultimaker/stable", "translationextractor/[>=1.0.0]@ultimaker/stable"
  25. python_requires_extend = "umbase.UMBaseConanfile"
  26. options = {
  27. "enterprise": ["True", "False", "true", "false"], # Workaround for GH Action passing boolean as lowercase string
  28. "staging": ["True", "False", "true", "false"], # Workaround for GH Action passing boolean as lowercase string
  29. "devtools": [True, False], # FIXME: Split this up in testing and (development / build (pyinstaller) / system installer) tools
  30. "cloud_api_version": "ANY",
  31. "display_name": "ANY", # TODO: should this be an option??
  32. "cura_debug_mode": [True, False], # FIXME: Use profiles
  33. "internal": [True, False]
  34. }
  35. default_options = {
  36. "enterprise": "False",
  37. "staging": "False",
  38. "devtools": False,
  39. "cloud_api_version": "1",
  40. "display_name": "UltiMaker Cura",
  41. "cura_debug_mode": False, # Not yet implemented
  42. "internal": False,
  43. }
  44. @property
  45. def _pycharm_targets(self):
  46. return self.conan_data["pycharm_targets"]
  47. # FIXME: These env vars should be defined in the runenv.
  48. _cura_env = None
  49. @property
  50. def _cura_run_env(self):
  51. if self._cura_env:
  52. return self._cura_env
  53. self._cura_env = Environment()
  54. self._cura_env.define("QML2_IMPORT_PATH", str(self._site_packages.joinpath("PyQt6", "Qt6", "qml")))
  55. self._cura_env.define("QT_PLUGIN_PATH", str(self._site_packages.joinpath("PyQt6", "Qt6", "plugins")))
  56. if self.settings.os == "Linux":
  57. self._cura_env.define("QT_QPA_FONTDIR", "/usr/share/fonts")
  58. self._cura_env.define("QT_QPA_PLATFORMTHEME", "xdgdesktopportal")
  59. self._cura_env.define("QT_XKB_CONFIG_ROOT", "/usr/share/X11/xkb")
  60. return self._cura_env
  61. @property
  62. def _staging(self):
  63. return self.options.staging in ["True", 'true']
  64. @property
  65. def _enterprise(self):
  66. return self.options.enterprise in ["True", 'true']
  67. @property
  68. def _app_name(self):
  69. if self._enterprise:
  70. return str(self.options.display_name) + " Enterprise"
  71. return str(self.options.display_name)
  72. @property
  73. def _cloud_api_root(self):
  74. return "https://api-staging.ultimaker.com" if self._staging else "https://api.ultimaker.com"
  75. @property
  76. def _cloud_account_api_root(self):
  77. return "https://account-staging.ultimaker.com" if self._staging else "https://account.ultimaker.com"
  78. @property
  79. def _marketplace_root(self):
  80. return "https://marketplace-staging.ultimaker.com" if self._staging else "https://marketplace.ultimaker.com"
  81. @property
  82. def _digital_factory_url(self):
  83. return "https://digitalfactory-staging.ultimaker.com" if self._staging else "https://digitalfactory.ultimaker.com"
  84. @property
  85. def _cura_latest_url(self):
  86. return "https://software.ultimaker.com/latest.json"
  87. @property
  88. def requirements_txts(self):
  89. if self.options.devtools:
  90. return ["requirements.txt", "requirements-ultimaker.txt", "requirements-dev.txt"]
  91. return ["requirements.txt", "requirements-ultimaker.txt"]
  92. @property
  93. def _base_dir(self):
  94. if self.install_folder is None:
  95. if self.build_folder is not None:
  96. return Path(self.build_folder)
  97. return Path(os.getcwd(), "venv")
  98. if self.in_local_cache:
  99. return Path(self.install_folder)
  100. else:
  101. return Path(self.source_folder, "venv")
  102. @property
  103. def _share_dir(self):
  104. return self._base_dir.joinpath("share")
  105. @property
  106. def _script_dir(self):
  107. if self.settings.os == "Windows":
  108. return self._base_dir.joinpath("Scripts")
  109. return self._base_dir.joinpath("bin")
  110. @property
  111. def _site_packages(self):
  112. if self.settings.os == "Windows":
  113. return self._base_dir.joinpath("Lib", "site-packages")
  114. py_version = Version(self.deps_cpp_info["cpython"].version)
  115. return self._base_dir.joinpath("lib", f"python{py_version.major}.{py_version.minor}", "site-packages")
  116. @property
  117. def _py_interp(self):
  118. py_interp = self._script_dir.joinpath(Path(self.deps_user_info["cpython"].python).name)
  119. if self.settings.os == "Windows":
  120. py_interp = Path(*[f'"{p}"' if " " in p else p for p in py_interp.parts])
  121. return py_interp
  122. @property
  123. def _pyinstaller_spec_arch(self):
  124. if self.settings.os == "Macos":
  125. if self.settings.arch == "armv8":
  126. return "'arm64'"
  127. return "'x86_64'"
  128. return "None"
  129. def _generate_about_dialog(self, location):
  130. # TODO: @jellespijker also auto generate for Python requirements, but we might want to do that after a revision of the VirtualPythonEnv
  131. # TODO: @jellespijker also add the entries for Windows/MacOS specific conan managed dependencies
  132. with open(os.path.join(self.recipe_folder, "AboutDialog.qml.jinja"), "r") as f:
  133. about_dialog_qml = Template(f.read())
  134. dependencies = [{}]
  135. for require, dep in self.dependencies.host.items():
  136. name = str(dep.ref.name).replace('_', ' ')
  137. # Currently not possible to get this information from the dependencies conanfiles themself, should be doable in the future with the 2.0 API
  138. description = self.conan_data["about_dialog"].get(str(dep.ref.name), {"description": ""})["description"]
  139. url = self.conan_data["about_dialog"].get(str(dep.ref.name), {"url": ""})["url"]
  140. license = self.conan_data["about_dialog"].get(str(dep.ref.name), {"license": ""})["license"]
  141. dependencies.append({"name": name,
  142. "version": str(dep.ref.version),
  143. "license": license,
  144. })
  145. for dep, values in self.conan_data["about_dialog_unmanaged"].items():
  146. dependencies.append({"name": dep.replace("_", " "),
  147. "version": "",
  148. "license": values["license"],
  149. })
  150. with open(os.path.join(location, "AboutDialog.qml"), "w") as f:
  151. f.write(about_dialog_qml.render(
  152. dependencies = dependencies
  153. # dependencies = sorted(dependencies, key=lambda dep: dep["name"])
  154. ))
  155. def _generate_cura_version(self, location):
  156. with open(os.path.join(self.recipe_folder, "CuraVersion.py.jinja"), "r") as f:
  157. cura_version_py = Template(f.read())
  158. # If you want a specific Cura version to show up on the splash screen add the user configuration `user.cura:version=VERSION`
  159. # the global.conf, profile, package_info (of dependency) or via the cmd line `-c user.cura:version=VERSION`
  160. cura_version = Version(self.conf.get("user.cura:version", default = self.version, check_type = str))
  161. pre_tag = f"-{cura_version.pre}" if cura_version.pre else ""
  162. build_tag = f"+{cura_version.build}" if cura_version.build else ""
  163. internal_tag = f"+internal" if self.options.internal else ""
  164. cura_version = f"{cura_version.major}.{cura_version.minor}.{cura_version.patch}{pre_tag}{build_tag}{internal_tag}"
  165. with open(os.path.join(location, "CuraVersion.py"), "w") as f:
  166. f.write(cura_version_py.render(
  167. cura_app_name = self.name,
  168. cura_app_display_name = self._app_name,
  169. cura_version = cura_version,
  170. cura_build_type = "Enterprise" if self._enterprise else "",
  171. cura_debug_mode = self.options.cura_debug_mode,
  172. cura_cloud_api_root = self._cloud_api_root,
  173. cura_cloud_api_version = self.options.cloud_api_version,
  174. cura_cloud_account_api_root = self._cloud_account_api_root,
  175. cura_marketplace_root = self._marketplace_root,
  176. cura_digital_factory_url = self._digital_factory_url,
  177. cura_latest_url = self._cura_latest_url))
  178. def _generate_pyinstaller_spec(self, location, entrypoint_location, icon_path, entitlements_file):
  179. pyinstaller_metadata = self.conan_data["pyinstaller"]
  180. datas = [(str(self._base_dir.joinpath("conan_install_info.json")), ".")]
  181. for data in pyinstaller_metadata["datas"].values():
  182. if not self.options.internal and data.get("internal", False):
  183. continue
  184. if "package" in data: # get the paths from conan package
  185. if data["package"] == self.name:
  186. if self.in_local_cache:
  187. src_path = os.path.join(self.package_folder, data["src"])
  188. else:
  189. src_path = os.path.join(self.source_folder, data["src"])
  190. else:
  191. src_path = os.path.join(self.deps_cpp_info[data["package"]].rootpath, data["src"])
  192. elif "root" in data: # get the paths relative from the sourcefolder
  193. src_path = os.path.join(self.source_folder, data["root"], data["src"])
  194. else:
  195. continue
  196. if Path(src_path).exists():
  197. datas.append((str(src_path), data["dst"]))
  198. binaries = []
  199. for binary in pyinstaller_metadata["binaries"].values():
  200. if "package" in binary: # get the paths from conan package
  201. src_path = os.path.join(self.deps_cpp_info[binary["package"]].rootpath, binary["src"])
  202. elif "root" in binary: # get the paths relative from the sourcefolder
  203. src_path = os.path.join(self.source_folder, binary["root"], binary["src"])
  204. else:
  205. continue
  206. if not Path(src_path).exists():
  207. self.output.warning(f"Source path for binary {binary['binary']} does not exist")
  208. continue
  209. for bin in Path(src_path).glob(binary["binary"] + "*[.exe|.dll|.so|.dylib|.so.]*"):
  210. binaries.append((str(bin), binary["dst"]))
  211. for bin in Path(src_path).glob(binary["binary"]):
  212. binaries.append((str(bin), binary["dst"]))
  213. # Make sure all Conan dependencies which are shared are added to the binary list for pyinstaller
  214. for _, dependency in self.dependencies.host.items():
  215. for bin_paths in dependency.cpp_info.bindirs:
  216. binaries.extend([(f"{p}", ".") for p in Path(bin_paths).glob("**/*.dll")])
  217. for lib_paths in dependency.cpp_info.libdirs:
  218. binaries.extend([(f"{p}", ".") for p in Path(lib_paths).glob("**/*.so*")])
  219. binaries.extend([(f"{p}", ".") for p in Path(lib_paths).glob("**/*.dylib*")])
  220. # Copy dynamic libs from lib path
  221. binaries.extend([(f"{p}", ".") for p in Path(self._base_dir.joinpath("lib")).glob("**/*.dylib*")])
  222. binaries.extend([(f"{p}", ".") for p in Path(self._base_dir.joinpath("lib")).glob("**/*.so*")])
  223. # Collect all dll's from PyQt6 and place them in the root
  224. binaries.extend([(f"{p}", ".") for p in Path(self._site_packages, "PyQt6", "Qt6").glob("**/*.dll")])
  225. with open(os.path.join(self.recipe_folder, "UltiMaker-Cura.spec.jinja"), "r") as f:
  226. pyinstaller = Template(f.read())
  227. version = self.conf_info.get("user.cura:version", default = self.version, check_type = str)
  228. cura_version = Version(version)
  229. with open(os.path.join(location, "UltiMaker-Cura.spec"), "w") as f:
  230. f.write(pyinstaller.render(
  231. name = str(self.options.display_name).replace(" ", "-"),
  232. display_name = self._app_name,
  233. entrypoint = entrypoint_location,
  234. datas = datas,
  235. binaries = binaries,
  236. venv_script_path = str(self._script_dir),
  237. hiddenimports = pyinstaller_metadata["hiddenimports"],
  238. collect_all = pyinstaller_metadata["collect_all"],
  239. icon = icon_path,
  240. entitlements_file = entitlements_file,
  241. osx_bundle_identifier = "'nl.ultimaker.cura'" if self.settings.os == "Macos" else "None",
  242. upx = str(self.settings.os == "Windows"),
  243. strip = False, # This should be possible on Linux and MacOS but, it can also cause issues on some distributions. Safest is to disable it for now
  244. target_arch = self._pyinstaller_spec_arch,
  245. macos = self.settings.os == "Macos",
  246. version = f"'{version}'",
  247. short_version = f"'{cura_version.major}.{cura_version.minor}.{cura_version.patch}'",
  248. ))
  249. def export_sources(self):
  250. copy(self, "*", os.path.join(self.recipe_folder, "plugins"), os.path.join(self.export_sources_folder, "plugins"))
  251. copy(self, "*", os.path.join(self.recipe_folder, "resources"), os.path.join(self.export_sources_folder, "resources"), excludes = "*.mo")
  252. copy(self, "*", os.path.join(self.recipe_folder, "tests"), os.path.join(self.export_sources_folder, "tests"))
  253. copy(self, "*", os.path.join(self.recipe_folder, "cura"), os.path.join(self.export_sources_folder, "cura"), excludes="CuraVersion.py")
  254. copy(self, "*", os.path.join(self.recipe_folder, "packaging"), os.path.join(self.export_sources_folder, "packaging"))
  255. copy(self, "*", os.path.join(self.recipe_folder, ".run_templates"), os.path.join(self.export_sources_folder, ".run_templates"))
  256. copy(self, "requirements.txt", self.recipe_folder, self.export_sources_folder)
  257. copy(self, "requirements-dev.txt", self.recipe_folder, self.export_sources_folder)
  258. copy(self, "requirements-ultimaker.txt", self.recipe_folder, self.export_sources_folder)
  259. copy(self, "UltiMaker-Cura.spec.jinja", self.recipe_folder, self.export_sources_folder)
  260. copy(self, "CuraVersion.py.jinja", self.recipe_folder, self.export_sources_folder)
  261. copy(self, "cura_app.py", self.recipe_folder, self.export_sources_folder)
  262. def set_version(self):
  263. if self.version is None:
  264. self.version = self._umdefault_version()
  265. def configure(self):
  266. self.options["pyarcus"].shared = True
  267. self.options["pysavitar"].shared = True
  268. self.options["pynest2d"].shared = True
  269. self.options["cpython"].shared = True
  270. def validate(self):
  271. version = self.conf_info.get("user.cura:version", default = self.version, check_type = str)
  272. if version and Version(version) <= Version("4"):
  273. raise ConanInvalidConfiguration("Only versions 5+ are support")
  274. def requirements(self):
  275. self.requires("pyarcus/5.2.2")
  276. self.requires("curaengine/(latest)@ultimaker/testing")
  277. self.requires("pysavitar/5.2.2")
  278. self.requires("pynest2d/5.2.2")
  279. self.requires("uranium/(latest)@ultimaker/testing")
  280. self.requires("fdm_materials/(latest)@{}/testing".format("internal" if self.options.internal else "ultimaker"))
  281. self.requires("cura_binary_data/(latest)@ultimaker/testing")
  282. self.requires("cpython/3.10.4")
  283. if self.options.internal:
  284. self.requires("cura_private_data/(latest)@ultimaker/testing")
  285. def build_requirements(self):
  286. if self.options.devtools:
  287. if self.settings.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str):
  288. # FIXME: once m4, autoconf, automake are Conan V2 ready use self.win_bash and add gettext as base tool_requirement
  289. self.tool_requires("gettext/0.21", force_host_context=True)
  290. def layout(self):
  291. self.folders.source = "."
  292. self.folders.build = "venv"
  293. self.folders.generators = os.path.join(self.folders.build, "conan")
  294. self.cpp.package.libdirs = [os.path.join("site-packages", "cura")]
  295. self.cpp.package.bindirs = ["bin"]
  296. self.cpp.package.resdirs = ["resources", "plugins", "packaging", "pip_requirements"] # pip_requirements should be the last item in the list
  297. def generate(self):
  298. copy(self, "cura_app.py", self.source_folder, str(self._script_dir))
  299. cura_run_envvars = self._cura_run_env.vars(self, scope = "run")
  300. ext = ".ps1" if self.settings.os == "Windows" else ".sh"
  301. cura_run_envvars.save_script(os.path.join(self.folders.generators, f"cura_run_environment{ext}"))
  302. vr = VirtualRunEnv(self)
  303. vr.generate()
  304. self._generate_cura_version(os.path.join(self.source_folder, "cura"))
  305. self._generate_about_dialog(os.path.join(self.source_folder, "resources", "qml", "Dialogs"))
  306. if self.options.devtools:
  307. entitlements_file = "'{}'".format(os.path.join(self.source_folder, "packaging", "MacOS", "cura.entitlements"))
  308. self._generate_pyinstaller_spec(location = self.generators_folder,
  309. entrypoint_location = "'{}'".format(os.path.join(self.source_folder, self.conan_data["pyinstaller"]["runinfo"]["entrypoint"])).replace("\\", "\\\\"),
  310. icon_path = "'{}'".format(os.path.join(self.source_folder, "packaging", self.conan_data["pyinstaller"]["icon"][str(self.settings.os)])).replace("\\", "\\\\"),
  311. entitlements_file = entitlements_file if self.settings.os == "Macos" else "None")
  312. # Update the po files
  313. if self.settings.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type=str):
  314. vb = VirtualBuildEnv(self)
  315. vb.generate()
  316. # FIXME: once m4, autoconf, automake are Conan V2 ready use self.win_bash and add gettext as base tool_requirement
  317. cpp_info = self.dependencies["gettext"].cpp_info
  318. for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"):
  319. pot_file = self.source_path.joinpath("resources", "i18n", po_file.with_suffix('.pot').name)
  320. mkdir(self, str(unix_path(self, pot_file.parent)))
  321. self.run(
  322. f"{cpp_info.bindirs[0]}/msgmerge --no-wrap --no-fuzzy-matching -width=140 -o {po_file} {po_file} {pot_file}",
  323. env="conanbuild", ignore_errors=True)
  324. def build(self):
  325. if self.options.devtools:
  326. if self.settings.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str):
  327. # FIXME: once m4, autoconf, automake are Conan V2 ready use self.win_bash and add gettext as base tool_requirement
  328. for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"):
  329. mo_file = Path(self.build_folder, po_file.with_suffix('.mo').relative_to(self.source_path))
  330. mo_file = mo_file.parent.joinpath("LC_MESSAGES", mo_file.name)
  331. mkdir(self, str(unix_path(self, Path(mo_file).parent)))
  332. cpp_info = self.dependencies["gettext"].cpp_info
  333. self.run(f"{cpp_info.bindirs[0]}/msgfmt {po_file} -o {mo_file} -f", env="conanbuild", ignore_errors=True)
  334. def imports(self):
  335. self.copy("CuraEngine.exe", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False)
  336. self.copy("CuraEngine", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False)
  337. rmdir(self, os.path.join(self.source_folder, "resources", "materials"))
  338. self.copy("*.fdm_material", root_package = "fdm_materials", src = "@resdirs", dst = "resources/materials", keep_path = False)
  339. self.copy("*.sig", root_package = "fdm_materials", src = "@resdirs", dst = "resources/materials", keep_path = False)
  340. if self.options.internal:
  341. self.copy("*", root_package = "cura_private_data", src = self.deps_cpp_info["cura_private_data"].resdirs[0],
  342. dst = self._share_dir.joinpath("cura", "resources"), keep_path = True)
  343. # Copy resources of cura_binary_data
  344. self.copy("*", root_package = "cura_binary_data", src = self.deps_cpp_info["cura_binary_data"].resdirs[0],
  345. dst = self._share_dir.joinpath("cura", "resources"), keep_path = True)
  346. self.copy("*", root_package = "cura_binary_data", src = self.deps_cpp_info["cura_binary_data"].resdirs[1],
  347. dst =self._share_dir.joinpath("uranium", "resources"), keep_path = True)
  348. self.copy("*.dll", src = "@bindirs", dst = self._site_packages)
  349. self.copy("*.pyd", src = "@libdirs", dst = self._site_packages)
  350. self.copy("*.pyi", src = "@libdirs", dst = self._site_packages)
  351. self.copy("*.dylib", src = "@libdirs", dst = self._script_dir)
  352. def deploy(self):
  353. # Copy CuraEngine.exe to bindirs of Virtual Python Environment
  354. # TODO: Fix source such that it will get the curaengine relative from the executable (Python bindir in this case)
  355. self.copy_deps("CuraEngine.exe", root_package = "curaengine", src = self.deps_cpp_info["curaengine"].bindirs[0],
  356. dst = self._base_dir,
  357. keep_path = False)
  358. self.copy_deps("CuraEngine", root_package = "curaengine", src = self.deps_cpp_info["curaengine"].bindirs[0], dst = self._base_dir,
  359. keep_path = False)
  360. # Copy resources of Cura (keep folder structure)
  361. self.copy("*", src = self.cpp_info.bindirs[0], dst = self._base_dir, keep_path = False)
  362. self.copy("*", src = self.cpp_info.libdirs[0], dst = self._site_packages.joinpath("cura"), keep_path = True)
  363. self.copy("*", src = self.cpp_info.resdirs[0], dst = self._share_dir.joinpath("cura", "resources"), keep_path = True)
  364. self.copy("*", src = self.cpp_info.resdirs[1], dst = self._share_dir.joinpath("cura", "plugins"), keep_path = True)
  365. # Copy materials (flat)
  366. self.copy_deps("*.fdm_material", root_package = "fdm_materials", src = self.deps_cpp_info["fdm_materials"].resdirs[0],
  367. dst = self._share_dir.joinpath("cura", "resources", "materials"), keep_path = False)
  368. self.copy_deps("*.sig", root_package = "fdm_materials", src = self.deps_cpp_info["fdm_materials"].resdirs[0],
  369. dst = self._share_dir.joinpath("cura", "resources", "materials"), keep_path = False)
  370. # Copy internal resources
  371. if self.options.internal:
  372. self.copy_deps("*", root_package = "cura_private_data", src = self.deps_cpp_info["cura_private_data"].resdirs[0],
  373. dst = self._share_dir.joinpath("cura", "resources"), keep_path = True)
  374. self.copy_deps("*", root_package = "cura_private_data", src = self.deps_cpp_info["cura_private_data"].resdirs[1],
  375. dst = self._share_dir.joinpath("cura", "plugins"), keep_path = True)
  376. # Copy resources of Uranium (keep folder structure)
  377. self.copy_deps("*", root_package = "uranium", src = self.deps_cpp_info["uranium"].resdirs[0],
  378. dst = self._share_dir.joinpath("uranium", "resources"), keep_path = True)
  379. self.copy_deps("*", root_package = "uranium", src = self.deps_cpp_info["uranium"].resdirs[1],
  380. dst = self._share_dir.joinpath("uranium", "plugins"), keep_path = True)
  381. self.copy_deps("*", root_package = "uranium", src = self.deps_cpp_info["uranium"].libdirs[0],
  382. dst = self._site_packages.joinpath("UM"),
  383. keep_path = True)
  384. self.copy_deps("*", root_package = "uranium", src = str(os.path.join(self.deps_cpp_info["uranium"].libdirs[0], "Qt", "qml", "UM")),
  385. dst = self._site_packages.joinpath("PyQt6", "Qt6", "qml", "UM"),
  386. keep_path = True)
  387. # Copy resources of cura_binary_data
  388. self.copy_deps("*", root_package = "cura_binary_data", src = self.deps_cpp_info["cura_binary_data"].resdirs[0],
  389. dst = self._share_dir.joinpath("cura"), keep_path = True)
  390. self.copy_deps("*", root_package = "cura_binary_data", src = self.deps_cpp_info["cura_binary_data"].resdirs[1],
  391. dst = self._share_dir.joinpath("uranium"), keep_path = True)
  392. if self.settings.os == "Windows":
  393. self.copy_deps("*", root_package = "cura_binary_data", src = self.deps_cpp_info["cura_binary_data"].resdirs[2],
  394. dst = self._share_dir.joinpath("windows"), keep_path = True)
  395. self.copy_deps("*.dll", src = "@bindirs", dst = self._site_packages)
  396. self.copy_deps("*.pyd", src = "@libdirs", dst = self._site_packages)
  397. self.copy_deps("*.pyi", src = "@libdirs", dst = self._site_packages)
  398. self.copy_deps("*.dylib", src = "@libdirs", dst = self._base_dir.joinpath("lib"))
  399. # Copy packaging scripts
  400. self.copy("*", src = self.cpp_info.resdirs[2], dst = self._base_dir.joinpath("packaging"))
  401. # Copy requirements.txt's
  402. self.copy("*.txt", src = self.cpp_info.resdirs[-1], dst = self._base_dir.joinpath("pip_requirements"))
  403. # Generate the GitHub Action version info Environment
  404. version = self.conf_info.get("user.cura:version", default = self.version, check_type = str)
  405. cura_version = Version(version)
  406. env_prefix = "Env:" if self.settings.os == "Windows" else ""
  407. activate_github_actions_version_env = Template(r"""echo "CURA_VERSION_MAJOR={{ cura_version_major }}" >> ${{ env_prefix }}GITHUB_ENV
  408. echo "CURA_VERSION_MINOR={{ cura_version_minor }}" >> ${{ env_prefix }}GITHUB_ENV
  409. echo "CURA_VERSION_PATCH={{ cura_version_patch }}" >> ${{ env_prefix }}GITHUB_ENV
  410. echo "CURA_VERSION_BUILD={{ cura_version_build }}" >> ${{ env_prefix }}GITHUB_ENV
  411. echo "CURA_VERSION_FULL={{ cura_version_full }}" >> ${{ env_prefix }}GITHUB_ENV
  412. echo "CURA_APP_NAME={{ cura_app_name }}" >> ${{ env_prefix }}GITHUB_ENV
  413. """).render(cura_version_major = cura_version.major,
  414. cura_version_minor = cura_version.minor,
  415. cura_version_patch = cura_version.patch,
  416. cura_version_build = cura_version.build if cura_version.build != "" else "0",
  417. cura_version_full = self.version,
  418. cura_app_name = self._app_name,
  419. env_prefix = env_prefix)
  420. ext = ".sh" if self.settings.os != "Windows" else ".ps1"
  421. save(self, os.path.join(self._script_dir, f"activate_github_actions_version_env{ext}"), activate_github_actions_version_env)
  422. self._generate_cura_version(os.path.join(self._site_packages, "cura"))
  423. entitlements_file = "'{}'".format(Path(self.cpp_info.res_paths[2], "MacOS", "cura.entitlements"))
  424. self._generate_pyinstaller_spec(location = self._base_dir,
  425. entrypoint_location = "'{}'".format(os.path.join(self.package_folder, self.cpp_info.bindirs[0], self.conan_data["pyinstaller"]["runinfo"]["entrypoint"])).replace("\\", "\\\\"),
  426. icon_path = "'{}'".format(os.path.join(self.package_folder, self.cpp_info.resdirs[2], self.conan_data["pyinstaller"]["icon"][str(self.settings.os)])).replace("\\", "\\\\"),
  427. entitlements_file = entitlements_file if self.settings.os == "Macos" else "None")
  428. def package(self):
  429. copy(self, "cura_app.py", src = self.source_folder, dst = os.path.join(self.package_folder, self.cpp.package.bindirs[0]))
  430. copy(self, "*", src = os.path.join(self.source_folder, "cura"), dst = os.path.join(self.package_folder, self.cpp.package.libdirs[0]))
  431. copy(self, "*", src = os.path.join(self.source_folder, "resources"), dst = os.path.join(self.package_folder, self.cpp.package.resdirs[0]))
  432. copy(self, "*.mo", os.path.join(self.build_folder, "resources"), os.path.join(self.package_folder, "resources"))
  433. copy(self, "*", src = os.path.join(self.source_folder, "plugins"), dst = os.path.join(self.package_folder, self.cpp.package.resdirs[1]))
  434. copy(self, "requirement*.txt", src = self.source_folder, dst = os.path.join(self.package_folder, self.cpp.package.resdirs[-1]))
  435. copy(self, "*", src = os.path.join(self.source_folder, "packaging"), dst = os.path.join(self.package_folder, self.cpp.package.resdirs[2]))
  436. def package_info(self):
  437. self.user_info.pip_requirements = "requirements.txt"
  438. self.user_info.pip_requirements_git = "requirements-ultimaker.txt"
  439. self.user_info.pip_requirements_build = "requirements-dev.txt"
  440. if self.in_local_cache:
  441. self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "site-packages"))
  442. self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "plugins"))
  443. else:
  444. self.runenv_info.append_path("PYTHONPATH", self.source_folder)
  445. self.runenv_info.append_path("PYTHONPATH", os.path.join(self.source_folder, "plugins"))
  446. def package_id(self):
  447. self.info.clear()
  448. # The following options shouldn't be used to determine the hash, since these are only used to set the CuraVersion.py
  449. # which will als be generated by the deploy method during the `conan install cura/5.1.0@_/_`
  450. del self.info.options.enterprise
  451. del self.info.options.staging
  452. del self.info.options.devtools
  453. del self.info.options.cloud_api_version
  454. del self.info.options.display_name
  455. del self.info.options.cura_debug_mode
  456. # TODO: Use the hash of requirements.txt and requirements-ultimaker.txt, Because changing these will actually result in a different
  457. # Cura. This is needed because the requirements.txt aren't managed by Conan and therefor not resolved in the package_id. This isn't
  458. # ideal but an acceptable solution for now.