conanfile.py 28 KB

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