conanfile.py 28 KB

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