From b2e57a984b079d76a9953925fe264c989980b1ac Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Thu, 5 Aug 2021 15:04:10 +0200 Subject: [PATCH 1/5] Added Conan support I'm currently working on integrating Conan as a dependency manager in my workflow. While Charon doesn't have a lot of dependencies, it is one of Cura. This script allows Conan to create a package which stores the Python files and adds that path to the PYTHONPATH. > **Pro tip!** > Install Conan > > Install Cura configuration files: > `conan config install https://github.com/jellespijker/conan-config.git` > > If you want to let Conan handle the dependencies just use: > `-DCMAKE_TOOLCHAIN_FILE=cmake-build-/conan_toolchain.cmake` > Install Conan plugin in Clion go to Conan settings `ctrl+alt+s`add Conan arguments > `--build=missing pr:b cura_release.jinja` > Match the build profiles with the Conan profiles in the Conan plugin sidebar > > If you want to use this as a dependency add the requirement `Charon/4.10.0@ultimaker/testing` > to your `conanfile.py` or `conanfile.txt` > If you want to use this source as the dependency (work on multiple projects at the same time) > make this an editable with `conan editable . Charon/4.10.0@ultimaker/testing` the auto > generated config files should now point to these source files and the compiled binaries. --- conanfile.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 conanfile.py diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..a434170 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,66 @@ +import os +import pathlib + +from conans import ConanFile +from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake + +class CharonConan(ConanFile): + name = "Charon" + version = "4.10.0" + license = "LGPL-3.0" + author = "Ultimaker B.V." + url = "https://github.com/Ultimaker/libCharon" + description = "File metadata and streaming library" + topics = ("conan", "python", "cura", "ufp") + settings = "os", "compiler", "build_type", "arch" + exports = "LICENSE" + options = { + "python_version": "ANY" + } + default_options = { + "python_version": "3.8" + } + scm = { + "type": "git", + "subfolder": ".", + "url": "auto", + "revision": "auto" + } + + def build_requirements(self): + self.build_requires("cmake/[>=3.16.2]") + + def generate(self): + cmake = CMakeDeps(self) + cmake.generate() + + tc = CMakeToolchain(self) + tc.variables["CURA_PYTHON_VERSION"] = self.options.python_version + tc.generate() + + _cmake = None + + def configure_cmake(self): + if self._cmake: + return self._cmake + self._cmake = CMake(self) + self._cmake.configure() + return self._cmake + + def build(self): + cmake = self.configure_cmake() + cmake.build() + + def package(self): + cmake = self.configure_cmake() + cmake.install() + self.copy("*", src = os.path.join("package", "lib", f"python{self.options.python_version}", "site-packages"), dst = "site-packages") + + def package_info(self): + if self.in_local_cache: + self.runenv_info.prepend_path("PYTHONPATH", self.source_folder) + else: + self.runenv_info.prepend_path("PYTHONPATH", str(pathlib.Path(__file__).parent.absolute())) + + def package_id(self): + self.info.header_only() From 305daac5c45add653f82d8aae60492a07fa60afc Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 10 Aug 2021 07:07:39 +0200 Subject: [PATCH 2/5] Fixed PYTHONPATH location when packaged source_folder was None at that time --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index a434170..2eca8a5 100644 --- a/conanfile.py +++ b/conanfile.py @@ -58,7 +58,7 @@ def package(self): def package_info(self): if self.in_local_cache: - self.runenv_info.prepend_path("PYTHONPATH", self.source_folder) + self.runenv_info.prepend_path("PYTHONPATH", os.path.join(self.package_folder, "site-packages")) else: self.runenv_info.prepend_path("PYTHONPATH", str(pathlib.Path(__file__).parent.absolute())) From ecef2799f8939b5f3894b68a10c23b749fed73ec Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 10 Aug 2021 16:49:46 +0200 Subject: [PATCH 3/5] Simplified the recipe Build and config nor needed. This is basically a pure Python package for the consumer --- conanfile.py | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/conanfile.py b/conanfile.py index 2eca8a5..6b6bed9 100644 --- a/conanfile.py +++ b/conanfile.py @@ -14,12 +14,9 @@ class CharonConan(ConanFile): topics = ("conan", "python", "cura", "ufp") settings = "os", "compiler", "build_type", "arch" exports = "LICENSE" - options = { - "python_version": "ANY" - } - default_options = { - "python_version": "3.8" - } + exports_sources = "Charon/*" + no_copy_source = True + scm = { "type": "git", "subfolder": ".", @@ -27,34 +24,8 @@ class CharonConan(ConanFile): "revision": "auto" } - def build_requirements(self): - self.build_requires("cmake/[>=3.16.2]") - - def generate(self): - cmake = CMakeDeps(self) - cmake.generate() - - tc = CMakeToolchain(self) - tc.variables["CURA_PYTHON_VERSION"] = self.options.python_version - tc.generate() - - _cmake = None - - def configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.configure() - return self._cmake - - def build(self): - cmake = self.configure_cmake() - cmake.build() - def package(self): - cmake = self.configure_cmake() - cmake.install() - self.copy("*", src = os.path.join("package", "lib", f"python{self.options.python_version}", "site-packages"), dst = "site-packages") + self.copy("*.py", src = "Charon", dst = os.path.join("site-packages", "Charon")) def package_info(self): if self.in_local_cache: From 7670da979ccf1ab032b4edd0f6e382c94d7b7b03 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 8 Sep 2021 10:13:25 +0200 Subject: [PATCH 4/5] Update to 4.11 --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 6b6bed9..973f390 100644 --- a/conanfile.py +++ b/conanfile.py @@ -6,7 +6,7 @@ class CharonConan(ConanFile): name = "Charon" - version = "4.10.0" + version = "4.11.0" license = "LGPL-3.0" author = "Ultimaker B.V." url = "https://github.com/Ultimaker/libCharon" From b65bfc1dae99679e36f6243bfe65bab0d68830ad Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 8 Sep 2021 10:14:31 +0200 Subject: [PATCH 5/5] Changed rev mode to scm --- conanfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conanfile.py b/conanfile.py index 973f390..54f0028 100644 --- a/conanfile.py +++ b/conanfile.py @@ -13,6 +13,8 @@ class CharonConan(ConanFile): description = "File metadata and streaming library" topics = ("conan", "python", "cura", "ufp") settings = "os", "compiler", "build_type", "arch" + revision_mode = "scm" + build_policy = "missing" exports = "LICENSE" exports_sources = "Charon/*" no_copy_source = True