conanfile.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. import os
  2. from io import StringIO
  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, update_conandata
  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.2.0]@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", "true", "false"], # Workaround for GH Action passing boolean as lowercase string
  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 = self.conan_data["version"]
  47. @property
  48. def _i18n_options(self):
  49. return self.conf.get("user.i18n:options", default = {"extract": True, "build": True}, check_type = dict)
  50. @property
  51. def _pycharm_targets(self):
  52. return self.conan_data["pycharm_targets"]
  53. # FIXME: These env vars should be defined in the runenv.
  54. _cura_env = None
  55. @property
  56. def _cura_run_env(self):
  57. if self._cura_env:
  58. return self._cura_env
  59. self._cura_env = Environment()
  60. self._cura_env.define("QML2_IMPORT_PATH", str(self._site_packages.joinpath("PyQt6", "Qt6", "qml")))
  61. self._cura_env.define("QT_PLUGIN_PATH", str(self._site_packages.joinpath("PyQt6", "Qt6", "plugins")))
  62. if not self.in_local_cache:
  63. self._cura_env.define("CURA_DATA_ROOT", str(self._share_dir.joinpath("cura")))
  64. if self.settings.os == "Linux":
  65. self._cura_env.define("QT_QPA_FONTDIR", "/usr/share/fonts")
  66. self._cura_env.define("QT_QPA_PLATFORMTHEME", "xdgdesktopportal")
  67. self._cura_env.define("QT_XKB_CONFIG_ROOT", "/usr/share/X11/xkb")
  68. return self._cura_env
  69. @property
  70. def _enterprise(self):
  71. return self.options.enterprise in ["True", 'true']
  72. @property
  73. def _internal(self):
  74. return self.options.internal in ["True", 'true']
  75. @property
  76. def _app_name(self):
  77. if self._enterprise:
  78. return str(self.options.display_name) + " Enterprise"
  79. return str(self.options.display_name)
  80. @property
  81. def _urls(self):
  82. if self.options.staging in ["True", 'true']:
  83. return "staging"
  84. return "default"
  85. @property
  86. def requirements_txts(self):
  87. if self.options.devtools:
  88. return ["requirements.txt", "requirements-ultimaker.txt", "requirements-dev.txt"]
  89. return ["requirements.txt", "requirements-ultimaker.txt"]
  90. @property
  91. def _base_dir(self):
  92. if self.install_folder is None:
  93. if self.build_folder is not None:
  94. return Path(self.build_folder)
  95. return Path(os.getcwd(), "venv")
  96. if self.in_local_cache:
  97. return Path(self.install_folder)
  98. else:
  99. return Path(self.source_folder, "venv")
  100. @property
  101. def _share_dir(self):
  102. return self._base_dir.joinpath("share")
  103. @property
  104. def _script_dir(self):
  105. if self.settings.os == "Windows":
  106. return self._base_dir.joinpath("Scripts")
  107. return self._base_dir.joinpath("bin")
  108. @property
  109. def _site_packages(self):
  110. if self.settings.os == "Windows":
  111. return self._base_dir.joinpath("Lib", "site-packages")
  112. py_version = Version(self.deps_cpp_info["cpython"].version)
  113. return self._base_dir.joinpath("lib", f"python{py_version.major}.{py_version.minor}", "site-packages")
  114. @property
  115. def _py_interp(self):
  116. py_interp = self._script_dir.joinpath(Path(self.deps_user_info["cpython"].python).name)
  117. if self.settings.os == "Windows":
  118. py_interp = Path(*[f'"{p}"' if " " in p else p for p in py_interp.parts])
  119. return py_interp
  120. @property
  121. def _pyinstaller_spec_arch(self):
  122. if self.settings.os == "Macos":
  123. if self.settings.arch == "armv8":
  124. return "'arm64'"
  125. return "'x86_64'"
  126. return "None"
  127. def _conan_installs(self):
  128. self.output.info("Collecting conan installs")
  129. conan_installs = {}
  130. # list of conan installs
  131. for dependency in self.dependencies.host.values():
  132. conan_installs[dependency.ref.name] = {
  133. "version": dependency.ref.version,
  134. "revision": dependency.ref.revision
  135. }
  136. return conan_installs
  137. def _python_installs(self):
  138. self.output.info("Collecting python installs")
  139. python_installs = {}
  140. # list of python installs
  141. run_env = VirtualRunEnv(self)
  142. env = run_env.environment()
  143. env.prepend_path("PYTHONPATH", str(self._site_packages.as_posix()))
  144. venv_vars = env.vars(self, scope = "run")
  145. outer = '"' if self.settings.os == "Windows" else "'"
  146. inner = "'" if self.settings.os == "Windows" else '"'
  147. buffer = StringIO()
  148. with venv_vars.apply():
  149. self.run(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}""",
  150. env = "conanrun",
  151. output = buffer)
  152. packages = str(buffer.getvalue()).split("-----------------\n")
  153. packages = packages[1].strip('\r\n').split(";")
  154. for package in packages:
  155. name, version = package.split(",")
  156. python_installs[name] = {"version": version}
  157. return python_installs
  158. def _generate_cura_version(self, location):
  159. with open(os.path.join(self.recipe_folder, "CuraVersion.py.jinja"), "r") as f:
  160. cura_version_py = Template(f.read())
  161. # If you want a specific Cura version to show up on the splash screen add the user configuration `user.cura:version=VERSION`
  162. # the global.conf, profile, package_info (of dependency) or via the cmd line `-c user.cura:version=VERSION`
  163. cura_version = Version(self.conf.get("user.cura:version", default = self.version, check_type = str))
  164. pre_tag = f"-{cura_version.pre}" if cura_version.pre else ""
  165. build_tag = f"+{cura_version.build}" if cura_version.build else ""
  166. internal_tag = f"+internal" if self._internal else ""
  167. cura_version = f"{cura_version.major}.{cura_version.minor}.{cura_version.patch}{pre_tag}{build_tag}{internal_tag}"
  168. with open(os.path.join(location, "CuraVersion.py"), "w") as f:
  169. f.write(cura_version_py.render(
  170. cura_app_name = self.name,
  171. cura_app_display_name = self._app_name,
  172. cura_version = cura_version,
  173. cura_build_type = "Enterprise" if self._enterprise else "",
  174. cura_debug_mode = self.options.cura_debug_mode,
  175. cura_cloud_api_root = self.conan_data["urls"][self._urls]["cloud_api_root"],
  176. cura_cloud_api_version = self.options.cloud_api_version,
  177. cura_cloud_account_api_root = self.conan_data["urls"][self._urls]["cloud_account_api_root"],
  178. cura_marketplace_root = self.conan_data["urls"][self._urls]["marketplace_root"],
  179. cura_digital_factory_url = self.conan_data["urls"][self._urls]["digital_factory_url"],
  180. cura_latest_url=self.conan_data["urls"][self._urls]["cura_latest_url"],
  181. conan_installs=self._conan_installs(),
  182. python_installs=self._python_installs(),
  183. ))
  184. def _delete_unwanted_binaries(self, root):
  185. dynamic_binary_file_exts = [".so", ".dylib", ".dll", ".pyd", ".pyi"]
  186. prohibited = [
  187. "qt5compat",
  188. "qtcharts",
  189. "qtcoap",
  190. "qtdatavis3d",
  191. "qtlottie",
  192. "qtmqtt",
  193. "qtnetworkauth",
  194. "qtquick3d",
  195. "qtquick3dphysics",
  196. "qtquicktimeline",
  197. "qtvirtualkeyboard",
  198. "qtwayland"
  199. ]
  200. forbiddens = [x.encode() for x in prohibited]
  201. to_remove_files = []
  202. to_remove_dirs = []
  203. for root, dir_, files in os.walk(root):
  204. for filename in files:
  205. if not any([(x in filename) for x in dynamic_binary_file_exts]):
  206. continue
  207. pathname = os.path.join(root, filename)
  208. still_exist = True
  209. for forbidden in prohibited:
  210. if forbidden.lower() in str(pathname).lower():
  211. to_remove_files.append(pathname)
  212. still_exist = False
  213. break
  214. if not still_exist:
  215. continue
  216. with open(pathname, "rb") as file:
  217. bytez = file.read().lower()
  218. for forbidden in forbiddens:
  219. if bytez.find(forbidden) >= 0:
  220. to_remove_files.append(pathname)
  221. for dirname in dir_:
  222. for forbidden in prohibited:
  223. if forbidden.lower() == str(dirname).lower():
  224. pathname = os.path.join(root, dirname)
  225. to_remove_dirs.append(pathname)
  226. break
  227. for file in to_remove_files:
  228. try:
  229. os.remove(file)
  230. print(f"deleted file: {file}")
  231. except Exception as ex:
  232. print(f"WARNING: Attempt to delete file {file} results in: {str(ex)}")
  233. for dir_ in to_remove_dirs:
  234. try:
  235. rmdir(self, dir_)
  236. print(f"deleted dir_: {dir_}")
  237. except Exception as ex:
  238. print(f"WARNING: Attempt to delete folder {dir_} results in: {str(ex)}")
  239. def _generate_pyinstaller_spec(self, location, entrypoint_location, icon_path, entitlements_file):
  240. pyinstaller_metadata = self.conan_data["pyinstaller"]
  241. datas = []
  242. for data in pyinstaller_metadata["datas"].values():
  243. if not self._internal and data.get("internal", False):
  244. continue
  245. if "package" in data: # get the paths from conan package
  246. if data["package"] == self.name:
  247. if self.in_local_cache:
  248. src_path = os.path.join(self.package_folder, data["src"])
  249. else:
  250. src_path = os.path.join(self.source_folder, data["src"])
  251. else:
  252. if data["package"] not in self.deps_cpp_info.deps:
  253. continue
  254. src_path = os.path.join(self.deps_cpp_info[data["package"]].rootpath, data["src"])
  255. elif "root" in data: # get the paths relative from the install folder
  256. src_path = os.path.join(self.install_folder, data["root"], data["src"])
  257. else:
  258. continue
  259. if Path(src_path).exists():
  260. datas.append((str(src_path), data["dst"]))
  261. binaries = []
  262. for binary in pyinstaller_metadata["binaries"].values():
  263. if "package" in binary: # get the paths from conan package
  264. src_path = os.path.join(self.deps_cpp_info[binary["package"]].rootpath, binary["src"])
  265. elif "root" in binary: # get the paths relative from the sourcefolder
  266. src_path = str(self.source_path.joinpath(binary["root"], binary["src"]))
  267. if self.settings.os == "Windows":
  268. src_path = src_path.replace("\\", "\\\\")
  269. else:
  270. continue
  271. if not Path(src_path).exists():
  272. self.output.warning(f"Source path for binary {binary['binary']} does not exist")
  273. continue
  274. for bin in Path(src_path).glob(binary["binary"] + "*[.exe|.dll|.so|.dylib|.so.]*"):
  275. binaries.append((str(bin), binary["dst"]))
  276. for bin in Path(src_path).glob(binary["binary"]):
  277. binaries.append((str(bin), binary["dst"]))
  278. # Make sure all Conan dependencies which are shared are added to the binary list for pyinstaller
  279. for _, dependency in self.dependencies.host.items():
  280. for bin_paths in dependency.cpp_info.bindirs:
  281. binaries.extend([(f"{p}", ".") for p in Path(bin_paths).glob("**/*.dll")])
  282. for lib_paths in dependency.cpp_info.libdirs:
  283. binaries.extend([(f"{p}", ".") for p in Path(lib_paths).glob("**/*.so*")])
  284. binaries.extend([(f"{p}", ".") for p in Path(lib_paths).glob("**/*.dylib*")])
  285. # Copy dynamic libs from lib path
  286. binaries.extend([(f"{p}", ".") for p in Path(self._base_dir.joinpath("lib")).glob("**/*.dylib*")])
  287. binaries.extend([(f"{p}", ".") for p in Path(self._base_dir.joinpath("lib")).glob("**/*.so*")])
  288. # Collect all dll's from PyQt6 and place them in the root
  289. binaries.extend([(f"{p}", ".") for p in Path(self._site_packages, "PyQt6", "Qt6").glob("**/*.dll")])
  290. with open(os.path.join(self.recipe_folder, "UltiMaker-Cura.spec.jinja"), "r") as f:
  291. pyinstaller = Template(f.read())
  292. version = self.conf.get("user.cura:version", default = self.version, check_type = str)
  293. cura_version = Version(version)
  294. # filter all binary files in binaries on the blacklist
  295. blacklist = pyinstaller_metadata["blacklist"]
  296. filtered_binaries = [b for b in binaries if not any([all([(part in b[0].lower()) for part in parts]) for parts in blacklist])]
  297. # In case the installer isn't actually pyinstaller (Windows at the moment), outright remove the offending files:
  298. specifically_delete = set(binaries) - set(filtered_binaries)
  299. for (unwanted_path, _) in specifically_delete:
  300. try:
  301. os.remove(unwanted_path)
  302. print(f"delete: {unwanted_path}")
  303. except Exception as ex:
  304. print(f"WARNING: Attempt to delete binary {unwanted_path} results in: {str(ex)}")
  305. # Write the actual file:
  306. with open(os.path.join(location, "UltiMaker-Cura.spec"), "w") as f:
  307. f.write(pyinstaller.render(
  308. name = str(self.options.display_name).replace(" ", "-"),
  309. display_name = self._app_name,
  310. entrypoint = entrypoint_location,
  311. datas = datas,
  312. binaries = filtered_binaries,
  313. venv_script_path = str(self._script_dir),
  314. hiddenimports = pyinstaller_metadata["hiddenimports"],
  315. collect_all = pyinstaller_metadata["collect_all"],
  316. icon = icon_path,
  317. entitlements_file = entitlements_file,
  318. osx_bundle_identifier = "'nl.ultimaker.cura'" if self.settings.os == "Macos" else "None",
  319. upx = str(self.settings.os == "Windows"),
  320. 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
  321. target_arch = self._pyinstaller_spec_arch,
  322. macos = self.settings.os == "Macos",
  323. version = f"'{version}'",
  324. short_version = f"'{cura_version.major}.{cura_version.minor}.{cura_version.patch}'",
  325. ))
  326. def export(self):
  327. update_conandata(self, {"version": self.version})
  328. def export_sources(self):
  329. copy(self, "*", os.path.join(self.recipe_folder, "plugins"), os.path.join(self.export_sources_folder, "plugins"))
  330. copy(self, "*", os.path.join(self.recipe_folder, "resources"), os.path.join(self.export_sources_folder, "resources"), excludes = "*.mo")
  331. copy(self, "*", os.path.join(self.recipe_folder, "tests"), os.path.join(self.export_sources_folder, "tests"))
  332. copy(self, "*", os.path.join(self.recipe_folder, "cura"), os.path.join(self.export_sources_folder, "cura"), excludes="CuraVersion.py")
  333. copy(self, "*", os.path.join(self.recipe_folder, "packaging"), os.path.join(self.export_sources_folder, "packaging"))
  334. copy(self, "*", os.path.join(self.recipe_folder, ".run_templates"), os.path.join(self.export_sources_folder, ".run_templates"))
  335. copy(self, "requirements.txt", self.recipe_folder, self.export_sources_folder)
  336. copy(self, "requirements-dev.txt", self.recipe_folder, self.export_sources_folder)
  337. copy(self, "requirements-ultimaker.txt", self.recipe_folder, self.export_sources_folder)
  338. copy(self, "cura_app.py", self.recipe_folder, self.export_sources_folder)
  339. def config_options(self):
  340. if self.settings.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", check_type=str):
  341. del self.options.enable_i18n
  342. def configure(self):
  343. self.options["pyarcus"].shared = True
  344. self.options["pysavitar"].shared = True
  345. self.options["pynest2d"].shared = True
  346. self.options["dulcificum"].shared = self.settings.os != "Windows"
  347. self.options["cpython"].shared = True
  348. self.options["boost"].header_only = True
  349. if self.settings.os == "Linux":
  350. self.options["openssl"].shared = True
  351. if self.conf.get("user.curaengine:sentry_url", "", check_type=str) != "":
  352. self.options["curaengine"].enable_sentry = True
  353. self.options["arcus"].enable_sentry = True
  354. self.options["clipper"].enable_sentry = True
  355. def validate(self):
  356. version = self.conf.get("user.cura:version", default = self.version, check_type = str)
  357. if version and Version(version) <= Version("4"):
  358. raise ConanInvalidConfiguration("Only versions 5+ are support")
  359. def requirements(self):
  360. for req in self.conan_data["requirements"]:
  361. if self._internal and "fdm_materials" in req:
  362. continue
  363. if not self._enterprise and "native_cad_plugin" in req:
  364. continue
  365. self.requires(req)
  366. if self._internal:
  367. for req in self.conan_data["requirements_internal"]:
  368. self.requires(req)
  369. self.requires("cpython/3.10.4@ultimaker/stable")
  370. self.requires("clipper/6.4.2@ultimaker/stable")
  371. self.requires("openssl/3.2.0")
  372. self.requires("protobuf/3.21.12")
  373. self.requires("boost/1.82.0")
  374. self.requires("spdlog/1.12.0")
  375. self.requires("fmt/10.1.1")
  376. self.requires("zlib/1.2.13")
  377. def build_requirements(self):
  378. if self.options.get_safe("enable_i18n", False):
  379. self.tool_requires("gettext/0.21", force_host_context = True)
  380. def layout(self):
  381. self.folders.source = "."
  382. self.folders.build = "venv"
  383. self.folders.generators = os.path.join(self.folders.build, "conan")
  384. self.cpp.package.libdirs = [os.path.join("site-packages", "cura")]
  385. self.cpp.package.bindirs = ["bin"]
  386. self.cpp.package.resdirs = ["resources", "plugins", "packaging", "pip_requirements"] # pip_requirements should be the last item in the list
  387. def generate(self):
  388. copy(self, "cura_app.py", self.source_folder, str(self._script_dir))
  389. cura_run_envvars = self._cura_run_env.vars(self, scope = "run")
  390. ext = ".ps1" if self.settings.os == "Windows" else ".sh"
  391. cura_run_envvars.save_script(os.path.join(self.folders.generators, f"cura_run_environment{ext}"))
  392. vr = VirtualRunEnv(self)
  393. vr.generate()
  394. self._generate_cura_version(os.path.join(self.source_folder, "cura"))
  395. if not self.in_local_cache:
  396. # Copy CuraEngine.exe to bindirs of Virtual Python Environment
  397. curaengine = self.dependencies["curaengine"].cpp_info
  398. copy(self, "CuraEngine.exe", curaengine.bindirs[0], self.source_folder, keep_path = False)
  399. copy(self, "CuraEngine", curaengine.bindirs[0], self.source_folder, keep_path = False)
  400. # Copy the external plugins that we want to bundle with Cura
  401. if self._enterprise:
  402. rmdir(self, str(self.source_path.joinpath("plugins", "NativeCADplugin")))
  403. native_cad_plugin = self.dependencies["native_cad_plugin"].cpp_info
  404. copy(self, "*", native_cad_plugin.resdirs[0], str(self.source_path.joinpath("plugins", "NativeCADplugin")), keep_path = True)
  405. copy(self, "bundled_*.json", native_cad_plugin.resdirs[1], str(self.source_path.joinpath("resources", "bundled_packages")), keep_path = False)
  406. # Copy resources of cura_binary_data
  407. cura_binary_data = self.dependencies["cura_binary_data"].cpp_info
  408. copy(self, "*", cura_binary_data.resdirs[0], str(self._share_dir.joinpath("cura")), keep_path = True)
  409. copy(self, "*", cura_binary_data.resdirs[1], str(self._share_dir.joinpath("uranium")), keep_path = True)
  410. if self.settings.os == "Windows":
  411. copy(self, "*", cura_binary_data.resdirs[2], str(self._share_dir.joinpath("windows")), keep_path = True)
  412. for dependency in self.dependencies.host.values():
  413. for bindir in dependency.cpp_info.bindirs:
  414. self._delete_unwanted_binaries(bindir)
  415. copy(self, "*.dll", bindir, str(self._site_packages), keep_path = False)
  416. for libdir in dependency.cpp_info.libdirs:
  417. self._delete_unwanted_binaries(libdir)
  418. copy(self, "*.pyd", libdir, str(self._site_packages), keep_path = False)
  419. copy(self, "*.pyi", libdir, str(self._site_packages), keep_path = False)
  420. copy(self, "*.dylib", libdir, str(self._base_dir.joinpath("lib")), keep_path = False)
  421. # Copy materials (flat)
  422. rmdir(self, os.path.join(self.source_folder, "resources", "materials"))
  423. fdm_materials = self.dependencies["fdm_materials"].cpp_info
  424. copy(self, "*", fdm_materials.resdirs[0], self.source_folder)
  425. # Copy internal resources
  426. if self._internal:
  427. cura_private_data = self.dependencies["cura_private_data"].cpp_info
  428. copy(self, "*", cura_private_data.resdirs[0], str(self._share_dir.joinpath("cura")))
  429. if self.options.devtools:
  430. entitlements_file = "'{}'".format(os.path.join(self.source_folder, "packaging", "MacOS", "cura.entitlements"))
  431. self._generate_pyinstaller_spec(
  432. location=self.generators_folder,
  433. entrypoint_location="'{}'".format(
  434. os.path.join(self.source_folder, self.conan_data["pyinstaller"]["runinfo"]["entrypoint"])).replace(
  435. "\\", "\\\\"),
  436. icon_path="'{}'".format(os.path.join(self.source_folder, "packaging",
  437. self.conan_data["pyinstaller"]["icon"][
  438. str(self.settings.os)])).replace("\\", "\\\\"),
  439. entitlements_file=entitlements_file if self.settings.os == "Macos" else "None"
  440. )
  441. if self.options.get_safe("enable_i18n", False) and self._i18n_options["extract"]:
  442. vb = VirtualBuildEnv(self)
  443. vb.generate()
  444. # # FIXME: once m4, autoconf, automake are Conan V2 ready use self.win_bash and add gettext as base tool_requirement
  445. cpp_info = self.dependencies["gettext"].cpp_info
  446. pot = self.python_requires["translationextractor"].module.ExtractTranslations(self, cpp_info.bindirs[0])
  447. pot.generate()
  448. def build(self):
  449. if self.options.get_safe("enable_i18n", False) and self._i18n_options["build"]:
  450. for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"):
  451. mo_file = Path(self.build_folder, po_file.with_suffix('.mo').relative_to(self.source_path))
  452. mo_file = mo_file.parent.joinpath("LC_MESSAGES", mo_file.name)
  453. mkdir(self, str(unix_path(self, Path(mo_file).parent)))
  454. cpp_info = self.dependencies["gettext"].cpp_info
  455. self.run(f"{cpp_info.bindirs[0]}/msgfmt {po_file} -o {mo_file} -f", env="conanbuild", ignore_errors=True)
  456. def deploy(self):
  457. copy(self, "*", os.path.join(self.package_folder, self.cpp.package.resdirs[2]), os.path.join(self.install_folder, "packaging"), keep_path = True)
  458. # Copy resources of Cura (keep folder structure) needed by pyinstaller to determine the module structure
  459. copy(self, "*", os.path.join(self.package_folder, self.cpp_info.bindirs[0]), str(self._base_dir), keep_path = False)
  460. copy(self, "*", os.path.join(self.package_folder, self.cpp_info.libdirs[0]), str(self._site_packages.joinpath("cura")), keep_path = True)
  461. copy(self, "*", os.path.join(self.package_folder, self.cpp_info.resdirs[0]), str(self._share_dir.joinpath("cura", "resources")), keep_path = True)
  462. copy(self, "*", os.path.join(self.package_folder, self.cpp_info.resdirs[1]), str(self._share_dir.joinpath("cura", "plugins")), keep_path = True)
  463. # Copy the cura_resources resources from the package
  464. rm(self, "conanfile.py", os.path.join(self.package_folder, self.cpp.package.resdirs[0]))
  465. cura_resources = self.dependencies["cura_resources"].cpp_info
  466. for res_dir in cura_resources.resdirs:
  467. copy(self, "*", res_dir, str(self._share_dir.joinpath("cura", "resources", Path(res_dir).name)), keep_path = True)
  468. # Copy resources of Uranium (keep folder structure)
  469. uranium = self.dependencies["uranium"].cpp_info
  470. copy(self, "*", uranium.resdirs[0], str(self._share_dir.joinpath("uranium", "resources")), keep_path = True)
  471. copy(self, "*", uranium.resdirs[1], str(self._share_dir.joinpath("uranium", "plugins")), keep_path = True)
  472. copy(self, "*", uranium.libdirs[0], str(self._site_packages.joinpath("UM")), keep_path = True)
  473. # Generate the GitHub Action version info Environment
  474. version = self.conf.get("user.cura:version", default = self.version, check_type = str)
  475. cura_version = Version(version)
  476. env_prefix = "Env:" if self.settings.os == "Windows" else ""
  477. activate_github_actions_version_env = Template(r"""echo "CURA_VERSION_MAJOR={{ cura_version_major }}" >> ${{ env_prefix }}GITHUB_ENV
  478. echo "CURA_VERSION_MINOR={{ cura_version_minor }}" >> ${{ env_prefix }}GITHUB_ENV
  479. echo "CURA_VERSION_PATCH={{ cura_version_patch }}" >> ${{ env_prefix }}GITHUB_ENV
  480. echo "CURA_VERSION_BUILD={{ cura_version_build }}" >> ${{ env_prefix }}GITHUB_ENV
  481. echo "CURA_VERSION_FULL={{ cura_version_full }}" >> ${{ env_prefix }}GITHUB_ENV
  482. echo "CURA_APP_NAME={{ cura_app_name }}" >> ${{ env_prefix }}GITHUB_ENV
  483. """).render(cura_version_major = cura_version.major,
  484. cura_version_minor = cura_version.minor,
  485. cura_version_patch = cura_version.patch,
  486. cura_version_build = cura_version.build if cura_version.build != "" else "0",
  487. cura_version_full = self.version,
  488. cura_app_name = self._app_name,
  489. env_prefix = env_prefix)
  490. ext = ".sh" if self.settings.os != "Windows" else ".ps1"
  491. save(self, os.path.join(self._script_dir, f"activate_github_actions_version_env{ext}"), activate_github_actions_version_env)
  492. self._generate_cura_version(os.path.join(self._site_packages, "cura"))
  493. self._delete_unwanted_binaries(self._site_packages)
  494. self._delete_unwanted_binaries(self.package_folder)
  495. self._delete_unwanted_binaries(self._base_dir)
  496. self._delete_unwanted_binaries(self._share_dir)
  497. entitlements_file = "'{}'".format(Path(self.cpp_info.res_paths[2], "MacOS", "cura.entitlements"))
  498. self._generate_pyinstaller_spec(location = self._base_dir,
  499. entrypoint_location = "'{}'".format(os.path.join(self.package_folder, self.cpp_info.bindirs[0], self.conan_data["pyinstaller"]["runinfo"]["entrypoint"])).replace("\\", "\\\\"),
  500. icon_path = "'{}'".format(os.path.join(self.package_folder, self.cpp_info.resdirs[2], self.conan_data["pyinstaller"]["icon"][str(self.settings.os)])).replace("\\", "\\\\"),
  501. entitlements_file = entitlements_file if self.settings.os == "Macos" else "None")
  502. def package(self):
  503. copy(self, "cura_app.py", src = self.source_folder, dst = os.path.join(self.package_folder, self.cpp.package.bindirs[0]))
  504. copy(self, "*", src = os.path.join(self.source_folder, "cura"), dst = os.path.join(self.package_folder, self.cpp.package.libdirs[0]))
  505. copy(self, "*", src = os.path.join(self.source_folder, "resources"), dst = os.path.join(self.package_folder, self.cpp.package.resdirs[0]))
  506. copy(self, "*.mo", os.path.join(self.build_folder, "resources"), os.path.join(self.package_folder, "resources"))
  507. copy(self, "*", src = os.path.join(self.source_folder, "plugins"), dst = os.path.join(self.package_folder, self.cpp.package.resdirs[1]))
  508. copy(self, "requirement*.txt", src = self.source_folder, dst = os.path.join(self.package_folder, self.cpp.package.resdirs[-1]))
  509. copy(self, "*", src = os.path.join(self.source_folder, "packaging"), dst = os.path.join(self.package_folder, self.cpp.package.resdirs[2]))
  510. # Remove the fdm_materials from the package
  511. rmdir(self, os.path.join(self.package_folder, self.cpp.package.resdirs[0], "materials"))
  512. # Remove the cura_resources resources from the package
  513. rm(self, "conanfile.py", os.path.join(self.package_folder, self.cpp.package.resdirs[0]))
  514. cura_resources = self.dependencies["cura_resources"].cpp_info
  515. for res_dir in cura_resources.resdirs:
  516. rmdir(self, os.path.join(self.package_folder, self.cpp.package.resdirs[0], Path(res_dir).name))
  517. def package_info(self):
  518. self.user_info.pip_requirements = "requirements.txt"
  519. self.user_info.pip_requirements_git = "requirements-ultimaker.txt"
  520. self.user_info.pip_requirements_build = "requirements-dev.txt"
  521. if self.in_local_cache:
  522. self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "site-packages"))
  523. self.env_info.PYTHONPATH.append(os.path.join(self.package_folder, "site-packages"))
  524. self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "plugins"))
  525. self.env_info.PYTHONPATH.append(os.path.join(self.package_folder, "plugins"))
  526. else:
  527. self.runenv_info.append_path("PYTHONPATH", self.source_folder)
  528. self.env_info.PYTHONPATH.append(self.source_folder)
  529. self.runenv_info.append_path("PYTHONPATH", os.path.join(self.source_folder, "plugins"))
  530. self.env_info.PYTHONPATH.append(os.path.join(self.source_folder, "plugins"))
  531. def package_id(self):
  532. self.info.clear()
  533. # The following options shouldn't be used to determine the hash, since these are only used to set the CuraVersion.py
  534. # which will als be generated by the deploy method during the `conan install cura/5.1.0@_/_`
  535. del self.info.options.enterprise
  536. del self.info.options.staging
  537. del self.info.options.devtools
  538. del self.info.options.cloud_api_version
  539. del self.info.options.display_name
  540. del self.info.options.cura_debug_mode
  541. if self.options.get_safe("enable_i18n", False):
  542. del self.info.options.enable_i18n
  543. # TODO: Use the hash of requirements.txt and requirements-ultimaker.txt, Because changing these will actually result in a different
  544. # Cura. This is needed because the requirements.txt aren't managed by Conan and therefor not resolved in the package_id. This isn't
  545. # ideal but an acceptable solution for now.