conanfile.py 29 KB

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