conanfile.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import os
  2. from pathlib import Path
  3. from platform import python_version
  4. from jinja2 import Template
  5. from conan import ConanFile
  6. from conan.tools import files
  7. from conans import tools
  8. from conan.errors import ConanInvalidConfiguration
  9. required_conan_version = ">=1.47.0"
  10. class CuraConan(ConanFile):
  11. name = "cura"
  12. license = "LGPL-3.0"
  13. author = "Ultimaker B.V."
  14. url = "https://github.com/Ultimaker/cura"
  15. description = "3D printer / slicing GUI built on top of the Uranium framework"
  16. topics = ("conan", "python", "pyqt5", "qt", "qml", "3d-printing", "slicer")
  17. build_policy = "missing"
  18. exports = "LICENSE*"
  19. settings = "os", "compiler", "build_type", "arch"
  20. no_copy_source = True # We won't build so no need to copy sources to the build folder
  21. # FIXME: Remove specific branch once merged to main
  22. # Extending the conanfile with the UMBaseConanfile https://github.com/Ultimaker/conan-ultimaker-index/tree/CURA-9177_Fix_CI_CD/recipes/umbase
  23. python_requires = "umbase/0.1.1@ultimaker/testing"
  24. python_requires_extend = "umbase.UMBaseConanfile"
  25. options = {
  26. "enterprise": ["True", "False", "true", "false"], # Workaround for GH Action passing boolean as lowercase string
  27. "staging": ["True", "False", "true", "false"], # Workaround for GH Action passing boolean as lowercase string
  28. "devtools": [True, False], # FIXME: Split this up in testing and (development / build (pyinstaller) / system installer) tools
  29. "cloud_api_version": "ANY",
  30. "display_name": "ANY", # TODO: should this be an option??
  31. "cura_debug_mode": [True, False] # FIXME: Use profiles
  32. }
  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
  40. }
  41. scm = {
  42. "type": "git",
  43. "subfolder": ".",
  44. "url": "auto",
  45. "revision": "auto"
  46. }
  47. @property
  48. def _staging(self):
  49. return self.options.staging in ["True", 'true']
  50. @property
  51. def _enterprise(self):
  52. return self.options.enterprise in ["True", 'true']
  53. @property
  54. def _cloud_api_root(self):
  55. return "https://api-staging.ultimaker.com" if self._staging else "https://api.ultimaker.com"
  56. @property
  57. def _cloud_account_api_root(self):
  58. return "https://account-staging.ultimaker.com" if self._staging else "https://account.ultimaker.com"
  59. @property
  60. def _marketplace_root(self):
  61. return "https://marketplace-staging.ultimaker.com" if self._staging else "https://marketplace.ultimaker.com"
  62. @property
  63. def _digital_factory_url(self):
  64. return "https://digitalfactory-staging.ultimaker.com" if self._staging else "https://digitalfactory.ultimaker.com"
  65. @property
  66. def requirements_txts(self):
  67. if self.options.devtools:
  68. return ["requirements.txt", "requirements-ultimaker.txt", "requirements-dev.txt"]
  69. return ["requirements.txt", "requirements-ultimaker.txt"]
  70. def configure(self):
  71. self.options["*"].shared = True
  72. if self.settings.os == "Windows":
  73. # Needed to compile CPython on Windows with our configuration voor Visual Studio
  74. self.options["mpdecimal"].cxx = True
  75. self.options["mpdecimal"].shared = False
  76. self.options["libffi"].shared = False
  77. def validate(self):
  78. if self.version and tools.Version(self.version) <= tools.Version("4"):
  79. raise ConanInvalidConfiguration("Only versions 5+ are support")
  80. def requirements(self):
  81. for req in self._um_data(self.version)["requirements"]:
  82. self.requires(req)
  83. def layout(self):
  84. self.folders.source = "."
  85. self.folders.build = "venv"
  86. self.folders.generators = os.path.join(self.folders.build, "conan")
  87. self.cpp.package.libdirs = ["site-packages"]
  88. def generate(self):
  89. # TODO: handle materials when running from source and using the fdm_materials
  90. with open(Path(self.source_folder, "cura", "CuraVersion.py.jinja"), "r") as f:
  91. cura_version_py = Template(f.read())
  92. with open(Path(self.source_folder, "cura", "CuraVersion.py"), "w") as f:
  93. f.write(cura_version_py.render(
  94. cura_app_name = self.name,
  95. cura_app_display_name = self.options.display_name,
  96. cura_version = self.version,
  97. cura_build_type = "Enterprise" if self._enterprise else "",
  98. cura_debug_mode = self.options.cura_debug_mode,
  99. cura_cloud_api_root = self._cloud_api_root,
  100. cura_cloud_api_version = self.options.cloud_api_version,
  101. cura_cloud_account_api_root = self._cloud_account_api_root,
  102. cura_marketplace_root = self._marketplace_root,
  103. cura_digital_factory_url = self._digital_factory_url))
  104. # Create the Ultimaker-Cura.spec
  105. # TODO: Create a generator for this
  106. # TODO: Create exception for not in_local_cache
  107. # TODO: Allow for paths to be determine when installing from local cache without root_folder
  108. with open(Path(self.source_folder, "Ultimaker-Cura.spec.jinja"), "r") as f:
  109. pyinstaller = Template(f.read())
  110. pyinstaller_metadata = self._um_data(self.version)["pyinstaller"]
  111. datas = []
  112. for data in pyinstaller_metadata["datas"].values():
  113. if "package" in data: # get the paths from conan package
  114. if data["package"] == self.name:
  115. src_path = Path(self.package_folder, data["src"])
  116. else:
  117. src_path = Path(self.deps_cpp_info[data["package"]].rootpath, data["src"])
  118. elif "root" in data: # get the paths relative from the sourcefolder
  119. src_path = Path(self.source_folder, data["root"], data["src"])
  120. else:
  121. continue
  122. if src_path.exists():
  123. datas.append((str(src_path), data["dst"]))
  124. binaries = []
  125. for binary in pyinstaller_metadata["binaries"].values():
  126. if "package" in binary: # get the paths from conan package
  127. src_path = Path(self.deps_cpp_info[binary["package"]].rootpath, binary["src"])
  128. elif "root" in binary: # get the paths relative from the sourcefolder
  129. src_path = Path(self.source_folder, binary["root"], binary["src"])
  130. else:
  131. continue
  132. if not src_path.exists():
  133. continue
  134. for bin in src_path.glob(binary["binary"] + ".*[exe|dll|so|dylib]"):
  135. binaries.append((str(bin), binary["dst"]))
  136. for bin in src_path.glob(binary["binary"]):
  137. binaries.append((str(bin), binary["dst"]))
  138. with open(Path(self.generators_folder, "Ultimaker-Cura.spec"), "w") as f:
  139. f.write(pyinstaller.render(
  140. name = str(self.options.display_name).replace(" ", "-"),
  141. entrypoint = os.path.join("..", "..", self._um_data(self.version)["runinfo"]["entrypoint"]),
  142. datas = datas,
  143. binaries = binaries,
  144. hiddenimports = pyinstaller_metadata["hiddenimports"],
  145. collect_all = pyinstaller_metadata["collect_all"],
  146. icon = os.path.join("..", "..", pyinstaller_metadata["icon"][str(self.settings.os)])
  147. ))
  148. def imports(self):
  149. self.copy("CuraEngine.exe", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False)
  150. self.copy("CuraEngine", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False)
  151. files.rmdir(self, "resources/materials")
  152. self.copy("*.fdm_material", root_package = "fdm_materials", src = "@resdirs", dst = "resources/materials", keep_path = False)
  153. self.copy("*.sig", root_package = "fdm_materials", src = "@resdirs", dst = "resources/materials", keep_path = False)
  154. self.copy("*.dll", src = "@bindirs", dst = "venv/Lib/site-packages")
  155. self.copy("*.pyd", src = "@libdirs", dst = "venv/Lib/site-packages")
  156. self.copy("*.pyi", src = "@libdirs", dst = "venv/Lib/site-packages")
  157. self.copy("*.dylib", src = "@libdirs", dst = "venv/bin")
  158. def package(self):
  159. self.copy("*", src = "cura", dst = os.path.join(self.cpp.package.libdirs[0], "cura"))
  160. self.copy("*", src = "plugins", dst = os.path.join(self.cpp.package.libdirs[0], "plugins"))
  161. self.copy("*", src = "resources", dst = os.path.join(self.cpp.package.resdirs[0], "resources"))
  162. def package_info(self):
  163. if self.in_local_cache:
  164. self.runenv_info.append_path("PYTHONPATH", self.cpp_info.libdirs[0])
  165. else:
  166. self.runenv_info.append_path("PYTHONPATH", self.source_folder)
  167. def package_id(self):
  168. del self.info.settings.os
  169. del self.info.settings.compiler
  170. del self.info.settings.build_type
  171. del self.info.settings.arch