From c5eb37a5598d36288572b2fa8bbee3f31f875770 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Mon, 12 Feb 2024 12:40:38 +0100 Subject: [PATCH] Use Conan v2 Contributes to CURA-11622 --- .github/workflows/conan-package.yml | 225 ++++++------------ .../workflows/requirements-conan-package.txt | 2 - .github/workflows/requirements-runner.txt | 0 .gitignore | 8 + conandata.yml | 3 + conanfile.py | 59 ++--- test_package/conanfile.py | 15 +- 7 files changed, 119 insertions(+), 193 deletions(-) delete mode 100644 .github/workflows/requirements-conan-package.txt create mode 100644 .github/workflows/requirements-runner.txt create mode 100644 conandata.yml diff --git a/.github/workflows/conan-package.yml b/.github/workflows/conan-package.yml index 33695af..b5cbee9 100644 --- a/.github/workflows/conan-package.yml +++ b/.github/workflows/conan-package.yml @@ -1,157 +1,78 @@ ---- name: conan-package -# Exports the recipe, sources and binaries for Mac, Windows and Linux and upload these to the server such that these can -# be used downstream. -# -# It should run on pushes against main or CURA-* branches, but it will only create the binaries for main and release branches - on: - workflow_dispatch: - inputs: - # FIXME: Not yet implemented - conan_id: - required: false - type: string - description: 'The full conan package ID, e.g. "libnest2d/1.2.3@ultimaker/stable"' - create_latest_alias: - required: true - default: false - type: boolean - description: 'Create latest alias' - create_binaries_windows: - required: true - default: false - type: boolean - description: 'create binaries Windows' - create_binaries_linux: - required: true - default: false - type: boolean - description: 'create binaries Linux' - create_binaries_macos: - required: true - default: false - type: boolean - description: 'create binaries Macos' - - push: - paths: - - 'python/**' - - 'test_package/**' - - 'cmake/**' - - 'conanfile.py' - - 'conandata.yml' - - 'CMakeLists.txt' - - '.github/workflows/conan-package.yml' - - '.github/workflows/requirements*' - branches: - - main - - 'CURA-*' - - '[0-9]+.[0-9]+' - tags: - - '[0-9]+.[0-9]+.[0-9]*' + push: + paths: + - 'python/**' + - 'test_package/**' + - 'cmake/**' + - 'conanfile.py' + - 'conandata.yml' + - 'CMakeLists.txt' + - '.github/workflows/conan-package.yml' + - '.github/workflows/requirements*' + branches: + - main + - 'CURA-*' + - 'PP-*' + - 'NP-*' + - '[0-9].[0-9]*' + - '[0-9].[0-9][0-9]*' jobs: - conan-recipe-version: - uses: ultimaker/cura/.github/workflows/conan-recipe-version.yml@main - with: - project_name: pysavitar - - conan-package-export: - needs: [ conan-recipe-version ] - uses: ultimaker/cura/.github/workflows/conan-recipe-export.yml@main - with: - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - recipe_id_latest: ${{ needs.conan-recipe-version.outputs.recipe_id_latest }} - runs_on: 'ubuntu-20.04' - python_version: '3.10.x' - conan_logging_level: 'info' - secrets: inherit - - conan-package-create-windows: - if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true' )) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_windows) }} - needs: [ conan-recipe-version, conan-package-export ] - - uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main - with: - project_name: ${{ needs.conan-recipe-version.outputs.project_name }} - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - build_id: 4 - build_info: false - runs_on: 'windows-2022' - python_version: '3.10.x' - conan_config_branch: '' - conan_logging_level: 'info' - secrets: inherit - - conan-package-create-macos: - if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_macos) }} - needs: [ conan-recipe-version, conan-package-export ] - - uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main - with: - project_name: ${{ needs.conan-recipe-version.outputs.project_name }} - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - build_id: 3 - build_info: false - runs_on: 'macos-11' - python_version: '3.10.x' - conan_logging_level: 'info' - secrets: inherit - - conan-package-create-linux-modern: - if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_linux) }} - needs: [ conan-recipe-version, conan-package-export ] - - uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main - with: - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - project_name: ${{ needs.conan-recipe-version.outputs.project_name }} - build_id: 2 - build_info: false - runs_on: 'ubuntu-22.04' - python_version: '3.10.x' - conan_logging_level: 'info' - secrets: inherit - - conan-package-create-linux: - if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_linux) }} - needs: [ conan-recipe-version, conan-package-export ] - - uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main - with: - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - project_name: ${{ needs.conan-recipe-version.outputs.project_name }} - build_id: 1 - build_info: false - runs_on: 'ubuntu-20.04' - python_version: '3.10.x' - conan_logging_level: 'info' - secrets: inherit - - notify-export: - if: ${{ always() }} - needs: [ conan-recipe-version, conan-package-export ] - - uses: ultimaker/cura/.github/workflows/notify.yml@main - with: - success: ${{ contains(join(needs.*.result, ','), 'success') }} - success_title: "New Conan recipe exported in ${{ github.repository }}" - success_body: "Exported ${{ needs.conan-recipe-version.outputs.recipe_id_full }}" - failure_title: "Failed to export Conan Export in ${{ github.repository }}" - failure_body: "Failed to exported ${{ needs.conan-recipe-version.outputs.recipe_id_full }}" - secrets: inherit - - notify-create: - if: ${{ always() && ((github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch)) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_linux)) }} - needs: [ conan-recipe-version, conan-package-create-macos, conan-package-create-windows, conan-package-create-linux, conan-package-create-linux-modern ] - - uses: ultimaker/cura/.github/workflows/notify.yml@main - with: - success: ${{ contains(join(needs.*.result, ','), 'success') }} - success_title: "New binaries created in ${{ github.repository }}" - success_body: "Created binaries for ${{ needs.conan-recipe-version.outputs.recipe_id_full }}" - failure_title: "Failed to create binaries in ${{ github.repository }}" - failure_body: "Failed to created binaries for ${{ needs.conan-recipe-version.outputs.recipe_id_full }}" - secrets: inherit +# FIXME: Use main once merged + conan-recipe-version: + uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-version.yml@CURA-11622_conan_v2 + with: + project_name: pysavitar + +# FIXME: Use main once merged + conan-package-export: + needs: [ conan-recipe-version ] + uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-export.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit + +# FIXME: Use main once merged + conan-package-create-macos: + needs: [ conan-recipe-version, conan-package-export ] + if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} + uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-macos.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit + +# FIXME: Use main once merged + conan-package-create-windows: + needs: [ conan-recipe-version, conan-package-export ] + if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} + uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-windows.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit + +# FIXME: Use main once merged + conan-package-create-linux: + needs: [ conan-recipe-version, conan-package-export ] + if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} + uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-linux.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/requirements-conan-package.txt b/.github/workflows/requirements-conan-package.txt deleted file mode 100644 index 790edfb..0000000 --- a/.github/workflows/requirements-conan-package.txt +++ /dev/null @@ -1,2 +0,0 @@ -conan -sip diff --git a/.github/workflows/requirements-runner.txt b/.github/workflows/requirements-runner.txt new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index edb951d..8d53433 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,11 @@ test_package/build/ pyproject.toml build-*/ +/test_package/metadata/ +/test_package/conanbuild.sh +/test_package/conanbuildenv-release-x86_64.sh +/test_package/conanrun.sh +/test_package/conanrunenv-release-x86_64.sh +/test_package/deactivate_conanbuild.sh +/test_package/deactivate_conanrun.sh +/test_package/deactivate_conanrunenv-release-x86_64.sh diff --git a/conandata.yml b/conandata.yml new file mode 100644 index 0000000..dfbd975 --- /dev/null +++ b/conandata.yml @@ -0,0 +1,3 @@ +version: "5.4.0-alpha.0" +requirements: + - "savitar/[>=5.4.0]@ultimaker/cura_11622" diff --git a/conanfile.py b/conanfile.py index 590696b..b0320a5 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,19 +1,17 @@ import os from pathlib import Path -from os import path from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout from conan.tools.env import VirtualBuildEnv -from conan.tools.files import copy, mkdir +from conan.tools.files import copy, mkdir, update_conandata from conan.tools.build import check_min_cppstd from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime -from conan.tools.scm import Version +from conan.tools.scm import Version, Git - -required_conan_version = ">=1.56.0" +required_conan_version = ">=1.58.0" class PySavitarConan(ConanFile): @@ -24,11 +22,10 @@ class PySavitarConan(ConanFile): description = "pySavitar is a c++ implementation of 3mf loading with SIP python bindings" topics = ("conan", "cura", "3mf", "c++") settings = "os", "compiler", "build_type", "arch" - revision_mode = "scm" exports = "LICENSE*" - generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv" + generators = "CMakeDeps", "VirtualRunEnv" - python_requires = "pyprojecttoolchain/[>=0.1.7]@ultimaker/stable", "sipbuildtool/[>=0.2.4]@ultimaker/stable" + python_requires = "pyprojecttoolchain/[>=0.2.0]@ultimaker/cura_11622", "sipbuildtool/[>=0.3.0]@ultimaker/cura_11622" # FIXME: use stable after merge options = { "shared": [True, False], @@ -45,7 +42,11 @@ class PySavitarConan(ConanFile): def set_version(self): if not self.version: - self.version = "5.4.0-alpha" + self.version = self.conan_data["version"] + + def export(self): + git = Git(self) + update_conandata(self, {"version": self.version, "commit": git.get_commit()}) @property def _min_cppstd(self): @@ -63,11 +64,11 @@ def _compilers_minimum_version(self): def export_sources(self): copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder) - copy(self, "*", path.join(self.recipe_folder, "python"), path.join(self.export_sources_folder, "python")) + copy(self, "*", os.path.join(self.recipe_folder, "python"), os.path.join(self.export_sources_folder, "python")) def requirements(self): - self.requires("savitar/(latest)@ultimaker/testing") - self.requires("cpython/3.10.4") + for req in self.conan_data["requirements"]: + self.requires(req) def validate(self): if self.settings.compiler.cppstd: @@ -81,8 +82,9 @@ def validate(self): ) def build_requirements(self): - self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable") - self.test_requires("sipbuildtool/[>=0.2.4]@ultimaker/stable") + self.test_requires("standardprojectsettings/[>=0.2.0]@ultimaker/cura_11622") # FIXME: use stable after merge + self.test_requires("sipbuildtool/[>=0.3.0]@ultimaker/cura_11622") # FIXME: use stable after merge + self.test_requires("cpython/3.12.2@ultimaker/cura_11622") # FIXME: use stable after merge def config_options(self): if self.settings.os == "Windows": @@ -104,10 +106,12 @@ def generate(self): tc = CMakeToolchain(self) if is_msvc(self): tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self) - tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" - tc.variables["Python_EXECUTABLE"] = self.deps_user_info["cpython"].python.replace("\\", "/") - tc.variables["Python_USE_STATIC_LIBS"] = not self.options["cpython"].shared - tc.variables["Python_ROOT_DIR"] = self.deps_cpp_info["cpython"].rootpath.replace("\\", "/") + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0148"] = "OLD" + cpython_conf = self.dependencies["cpython"].conf_info + tc.variables["Python_EXECUTABLE"] = cpython_conf.get("user.cpython:python").replace("\\", "/") + tc.variables["Python_ROOT_DIR"] = cpython_conf.get("user.cpython:python_root").replace("\\", "/") + cpython_options = self.dependencies["cpython"].options + tc.variables["Python_USE_STATIC_LIBS"] = not cpython_options.shared tc.variables["Python_FIND_FRAMEWORK"] = "NEVER" tc.variables["Python_FIND_REGISTRY"] = "NEVER" tc.variables["Python_FIND_IMPLEMENTATIONS"] = "CPython" @@ -129,6 +133,12 @@ def layout(self): if self.settings.os in ["Linux", "FreeBSD", "Macos"]: self.cpp.package.system_libs = ["pthread"] + self.cpp.package.lib = ["pySavitar"] + self.cpp.package.libdirs = ["lib"] + + self.layouts.build.runenv_info.prepend_path("PYTHONPATH", ".") + self.layouts.package.runenv_info.prepend_path("PYTHONPATH", "lib") + def build(self): cmake = CMake(self) cmake.configure() @@ -136,15 +146,8 @@ def build(self): def package(self): copy(self, pattern="LICENSE*", dst="licenses", src=self.source_folder) - for ext in ("*.pyi", "*.so", "*.lib", "*.a", "*.pyd"): - copy(self, ext, src = self.build_folder, dst = path.join(self.package_folder, "lib"), keep_path = False) - - for ext in ("*.dll", "*.so", "*.dylib"): - copy(self, ext, src = self.build_folder, dst = path.join(self.package_folder, "bin"), keep_path = False) + for ext in ("*.pyi", "*.so", "*.lib", "*.a", "*.pyd", "*.dll", "*.dylib"): + copy(self, ext, src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) def package_info(self): - self.cpp_info.libdirs = [ os.path.join(self.package_folder, "lib")] - if self.in_local_cache: - self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "lib")) - else: - self.runenv_info.append_path("PYTHONPATH", self.build_folder) + self.conf_info.define("user.pysavitar:pythonpath", os.path.join(self.package_folder, "lib")) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 445ab73..77150be 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,6 +1,4 @@ -import shutil from io import StringIO -from pathlib import Path from conan import ConanFile from conan.tools.build import can_run @@ -11,7 +9,6 @@ class PySavitarTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "VirtualRunEnv" test_type = "explicit" def requirements(self): @@ -22,19 +19,15 @@ def generate(self): venv.generate() cpp_info = self.dependencies[self.tested_reference_str].cpp_info - copy(self, "*.pyd", src = cpp_info.libdirs[0], dst =self.build_folder) + copy(self, "*.pyd", src=cpp_info.libdirs[0], dst=self.build_folder) for dep in self.dependencies.values(): for bin_dir in dep.cpp_info.bindirs: - copy(self, "*.dll", src = bin_dir, dst = self.build_folder) - - def build(self): - if can_run(self): - shutil.copy(Path(self.source_folder).joinpath("test.py"), Path(self.build_folder).joinpath("test.py")) + copy(self, "*.dll", src=bin_dir, dst=self.build_folder) def test(self): if can_run(self): test_buf = StringIO() - self.run(f"python test.py", env = "conanrun", output = test_buf) + self.run(f"python test.py", env="conanrun", stdout=test_buf, scope="run") if "True" not in test_buf.getvalue(): - raise ConanException("pynest2d wasn't build correctly!") + raise ConanException("pySavitar wasn't build correctly!")