conanfile.py 29 KB

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