Cura/conanfile.py
j.spijker@ultimaker.com 5d740d7368 Set the CuraVersion with the conan options
Contributes to CURA-9365
2022-06-12 19:09:22 +02:00

128 lines
5.3 KiB
Python

import os
from pathlib import Path
from platform import python_version
from jinja2 import Template
from conan import ConanFile
from conans import tools
from conan.errors import ConanInvalidConfiguration
required_conan_version = ">=1.47.0"
class CuraConan(ConanFile):
name = "cura"
license = "LGPL-3.0"
author = "Ultimaker B.V."
url = "https://github.com/Ultimaker/cura"
description = "3D printer / slicing GUI built on top of the Uranium framework"
topics = ("conan", "python", "pyqt5", "qt", "qml", "3d-printing", "slicer")
build_policy = "missing"
exports = "LICENSE*"
settings = "os", "compiler", "build_type", "arch"
short_paths = True
generators = "VirtualPythonEnv"
options = {
"python_version": "ANY",
"enterprise": [True, False],
"staging": [True, False],
"external_engine": [True, False],
"devtools": [True, False],
"cloud_api_version": "ANY",
"display_name": "ANY"
}
default_options = {
"python_version": "system",
"enterprise": False,
"staging": False,
"external_engine": False,
"devtools": False,
"cloud_api_version": "1",
"display_name": "Ultimaker Cura"
}
scm = {
"type": "git",
"subfolder": ".",
"url": "auto",
"revision": "auto"
}
def set_version(self):
if not self.version and "CURA_VERSION" in os.environ:
self.version = os.environ["CURA_VERSION"]
@property
def _cloud_api_root(self):
return "https://api-staging.ultimaker.com" if self.options.staging else "https://api.ultimaker.com"
@property
def _cloud_account_api_root(self):
return "https://account-staging.ultimaker.com" if self.options.staging else "https://account.ultimaker.com"
@property
def _marketplace_root(self):
return "https://marketplace-staging.ultimaker.com" if self.options.staging else "https://marketplace.ultimaker.com"
@property
def _digital_factory_url(self):
return "https://digitalfactory-staging.ultimaker.com" if self.options.staging else "https://digitalfactory.ultimaker.com"
@property
def requirements_txts(self):
if self.options.devtools:
return ["requirements.txt", "requirements-dev.txt"]
return "requirements.txt"
def config_options(self):
if self.options.python_version == "system":
self.options.python_version = python_version()
def configure(self):
self.options["*"].shared = True
def validate(self):
if self.version:
if tools.Version(self.version) <= tools.Version("4"):
raise ConanInvalidConfiguration("Only versions 5+ are support")
def requirements(self):
self.requires("curaengine/latest@ultimaker/cura-9365") # FIXME: change to ultimaker/stable once the curaengine PR for CURA-9365 has been merged
self.requires("arcus/latest@ultimaker/cura-9365") # FIXME: change to ultimaker/stable once the arcus PR for CURA-9365 has been merged
self.requires("savitar/latest@ultimaker/cura-9365") # FIXME: change to ultimaker/stable once the savitar PR for CURA-9365 has been merged
self.requires("pynest2d/latest@ultimaker/cura-9365") # FIXME: change to ultimaker/stable once the pynest2d PR for CURA-9365 has been merged
def generate(self):
with open(Path(self.source_folder, "cura", "CuraVersion.py.jinja"), "r") as f:
cura_version_py = Template(f.read())
with open(Path(self.source_folder, "cura", "CuraVersion.py"), "w") as f:
f.write(cura_version_py.render(
cura_app_name = self.name,
cura_app_display_name = self.options.display_name,
cura_version = self.version if self.version else "master",
cura_build_type = "Enterprise" if self.options.enterprise else "",
cura_debug_mode = self.settings.build_type != "Release",
cura_cloud_api_root = self._cloud_api_root,
cura_cloud_api_version = self.options.cloud_api_version,
cura_cloud_account_api_root = self._cloud_account_api_root,
cura_marketplace_root = self._marketplace_root,
cura_digital_factory_url = self._digital_factory_url))
def layout(self):
self.folders.source = "."
self.folders.build = "venv"
self.folders.generators = os.path.join(self.folders.build, "conan")
# FIXME: Once libCharon en Uranium are also Packages
if "PYTHONPATH" in os.environ:
self.runenv_info.append_path("PYTHONPATH", os.environ["PYTHONPATH"])
def imports(self):
self.copy("CuraEngine.exe", root_package = "curaengine", src = "@bindirs", dst = self.source_folder, keep_path = False)
self.copy("CuraEngine", root_package = "curaengine", src = "@bindirs", dst = self.source_folder, keep_path = False)
self.copy("*.dll", src = "@bindirs", dst = os.path.join(self.folders.build, "Lib", "site-packages"))
self.copy("*.pyd", src = "@libdirs", dst = os.path.join(self.folders.build, "Lib", "site-packages"))
self.copy("*.pyi", src = "@libdirs", dst = os.path.join(self.folders.build, "Lib", "site-packages"))
self.copy("*.dylib", src = "@libdirs", dst = os.path.join(self.folders.build, "bin"))