Skip to content

Commit bae7fbd

Browse files
authored
Merge pull request #12 from Ultimaker/CURA-11622_conan_v2
Cura 11622 conan v2
2 parents ec8062a + 5758553 commit bae7fbd

File tree

6 files changed

+59
-94
lines changed

6 files changed

+59
-94
lines changed

.github/workflows/conan-package.yml

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,20 @@ on:
66
- 'src/**'
77
- 'test_package/**'
88
- 'include/**'
9-
- 'cmake/**'
109
- 'conanfile.py'
1110
- 'CMakeLists.txt'
1211
- '.github/workflows/conan-package.yml'
1312
- '.github/workflows/requirements*'
1413
- 'conandata.yml'
15-
- '.gitattributes'
1614
branches:
17-
- main
18-
- 'CURA-*'
19-
- 'PP-*'
20-
- '[0-9].[0-9]*'
21-
- '[0-9].[0-9][0-9]*'
15+
- main
16+
- 'CURA-*'
17+
- 'PP-*'
18+
- 'NP-*'
19+
- '[0-9].[0-9]*'
20+
- '[0-9].[0-9][0-9]*'
2221

2322
jobs:
24-
conan-recipe-version:
25-
uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-version.yml@main
26-
with:
27-
project_name: pyarcus
28-
29-
conan-package-export:
30-
needs: [ conan-recipe-version ]
31-
uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-export.yml@main
32-
with:
33-
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
34-
recipe_id_latest: ${{ needs.conan-recipe-version.outputs.recipe_id_latest }}
35-
secrets: inherit
36-
37-
conan-package-create-macos:
38-
needs: [ conan-recipe-version, conan-package-export ]
39-
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }}
40-
uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-macos.yml@main
41-
with:
42-
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
43-
secrets: inherit
44-
45-
conan-package-create-windows:
46-
needs: [ conan-recipe-version, conan-package-export ]
47-
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }}
48-
uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-windows.yml@main
49-
with:
50-
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
51-
secrets: inherit
52-
53-
conan-package-create-linux:
54-
needs: [ conan-recipe-version, conan-package-export ]
55-
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }}
56-
uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-linux.yml@main
57-
with:
58-
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
59-
secrets: inherit
23+
conan-package:
24+
uses: ultimaker/cura-workflows/.github/workflows/conan-package.yml@main
25+
secrets: inherit

.github/workflows/requirements-runner.txt

Whitespace-only changes.

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@ test_package/build/
8888

8989
pyproject.toml
9090
build-*/
91+
/test_package/metadata/
92+
/test_package/conanbuild.sh
93+
/test_package/conanbuildenv-release-x86_64.sh
94+
/test_package/conanrunenv-release-x86_64.sh
95+
/test_package/conanrun.sh
96+
/test_package/deactivate_conanbuild.sh
97+
/test_package/deactivate_conanrun.sh
98+
/test_package/deactivate_conanrunenv-release-x86_64.sh

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
cmake_minimum_required(VERSION 3.20)
12
cmake_policy(SET CMP0091 NEW)
23
project(pyarcus)
3-
cmake_minimum_required(VERSION 3.20)
44

55
find_package(protobuf REQUIRED)
6-
find_package(cpython REQUIRED)
6+
find_package(Python REQUIRED)
77
find_package(arcus REQUIRED)
88

99
find_package(standardprojectsettings REQUIRED)
@@ -20,4 +20,3 @@ target_include_directories(pyArcus
2020
target_link_libraries(pyArcus INTERFACE arcus::arcus protobuf::libprotobuf cpython::cpython)
2121
add_sip_module(pyArcus)
2222
install_sip_module(pyArcus)
23-

conanfile.py

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import os
12
from pathlib import Path
2-
from os import path
33

44
from conan import ConanFile
55
from conan.errors import ConanInvalidConfiguration
66
from conan.tools.build import check_min_cppstd
77
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
8-
from conan.tools.env import VirtualBuildEnv
8+
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
99
from conan.tools.files import copy, update_conandata
1010
from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime
1111
from conan.tools.scm import Version, Git
1212

13-
required_conan_version = ">=1.58.0"
13+
required_conan_version = ">=2.7.0"
1414

1515

1616
class ArcusConan(ConanFile):
@@ -21,11 +21,11 @@ class ArcusConan(ConanFile):
2121
description = "Communication library between internal components for Ultimaker software"
2222
topics = ("conan", "python", "binding", "sip", "cura", "protobuf")
2323
settings = "os", "compiler", "build_type", "arch"
24-
revision_mode = "scm"
2524
exports = "LICENSE*"
26-
generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv"
25+
generators = "CMakeDeps"
26+
package_type = "library"
2727

28-
python_requires = "pyprojecttoolchain/[>=0.1.7]@ultimaker/stable", "sipbuildtool/[>=0.2.4]@ultimaker/stable"
28+
python_requires = "pyprojecttoolchain/[>=0.2.0]@ultimaker/stable", "sipbuildtool/[>=0.3.0]@ultimaker/stable"
2929

3030
options = {
3131
"shared": [True, False],
@@ -42,8 +42,7 @@ class ArcusConan(ConanFile):
4242

4343
def set_version(self):
4444
if not self.version:
45-
build_meta = "" if self.develop else "+source"
46-
self.version = self.conan_data["version"] + build_meta
45+
self.version = self.conan_data["version"]
4746

4847
def export(self):
4948
git = Git(self)
@@ -65,16 +64,16 @@ def _compilers_minimum_version(self):
6564

6665
def export_sources(self):
6766
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
68-
copy(self, "*", path.join(self.recipe_folder, "src"), path.join(self.export_sources_folder, "src"))
69-
copy(self, "*", path.join(self.recipe_folder, "include"), path.join(self.export_sources_folder, "include"))
70-
copy(self, "*", path.join(self.recipe_folder, "python"), path.join(self.export_sources_folder, "python"))
67+
copy(self, "*", os.path.join(self.recipe_folder, "src"), os.path.join(self.export_sources_folder, "src"))
68+
copy(self, "*", os.path.join(self.recipe_folder, "include"),
69+
os.path.join(self.export_sources_folder, "include"))
70+
copy(self, "*", os.path.join(self.recipe_folder, "python"), os.path.join(self.export_sources_folder, "python"))
7171

7272
def requirements(self):
7373
for req in self.conan_data["requirements"]:
7474
self.requires(req)
75-
self.requires("protobuf/3.21.9", transitive_headers=True)
76-
self.requires("cpython/3.10.4@ultimaker/stable") # Maybe place this in build_requirements as well
77-
self.requires("zlib/1.2.12")
75+
self.requires("protobuf/3.21.12", transitive_headers=True)
76+
self.requires("cpython/3.12.2")
7877

7978
def validate(self):
8079
if self.settings.compiler.cppstd:
@@ -88,8 +87,8 @@ def validate(self):
8887
)
8988

9089
def build_requirements(self):
91-
self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable")
92-
self.test_requires("sipbuildtool/[>=0.2.4]@ultimaker/stable")
90+
self.test_requires("standardprojectsettings/[>=0.2.0]@ultimaker/stable")
91+
self.test_requires("sipbuildtool/[>=0.3.0]@ultimaker/stable")
9392

9493
def config_options(self):
9594
if self.settings.os == "Windows":
@@ -98,34 +97,27 @@ def config_options(self):
9897
def configure(self):
9998
if self.options.shared:
10099
self.options.rm_safe("fPIC")
101-
self.options["cpython"].shared = True
102100

103101
def generate(self):
104102
# Generate the pyproject.toml
105103
pp = self.python_requires["pyprojecttoolchain"].module.PyProjectToolchain(self)
106104
pp.blocks["tool_sip_project"].values["sip_files_dir"] = str(Path("python").as_posix())
107-
pp.blocks["tool_sip_bindings"].values["name"] = "pyArcus"
108105
pp.blocks["tool_sip_metadata"].values["name"] = "pyArcus"
106+
pp.blocks["tool_sip_bindings"].values["name"] = "pyArcus"
109107
pp.blocks["extra_sources"].values["headers"] = ["PythonMessage.h"]
110108
pp.blocks["extra_sources"].values["sources"] = [str(Path("src", "PythonMessage.cpp").as_posix())]
111109
pp.generate()
112110

113111
tc = CMakeToolchain(self)
114112
if is_msvc(self):
115113
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)
116-
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
117-
tc.variables["Python_EXECUTABLE"] = self.deps_user_info["cpython"].python.replace("\\", "/")
118-
tc.variables["Python_USE_STATIC_LIBS"] = not self.options["cpython"].shared
119-
tc.variables["Python_ROOT_DIR"] = self.deps_cpp_info["cpython"].rootpath.replace("\\", "/")
120-
tc.variables["Python_FIND_FRAMEWORK"] = "NEVER"
121-
tc.variables["Python_FIND_REGISTRY"] = "NEVER"
122-
tc.variables["Python_FIND_IMPLEMENTATIONS"] = "CPython"
123-
tc.variables["Python_FIND_STRATEGY"] = "LOCATION"
124-
tc.variables["Python_SITEARCH"] = "site-packages"
125114
tc.generate()
126115

127116
vb = VirtualBuildEnv(self)
128-
vb.generate(scope="build")
117+
vb.generate()
118+
119+
vr = VirtualRunEnv(self)
120+
vr.generate(scope="build")
129121

130122
# Generate the Source code from SIP
131123
sip = self.python_requires["sipbuildtool"].module.SipBuildTool(self)
@@ -138,23 +130,25 @@ def layout(self):
138130
if self.settings.os in ["Linux", "FreeBSD", "Macos"]:
139131
self.cpp.package.system_libs = ["pthread"]
140132

133+
self.cpp.package.lib = ["pyArcus"]
134+
135+
self.cpp.package.libdirs = ["lib"]
136+
self.layouts.build.runenv_info.prepend_path("PYTHONPATH", ".")
137+
self.layouts.package.runenv_info.prepend_path("PYTHONPATH", "lib")
138+
141139
def build(self):
142140
cmake = CMake(self)
143141
cmake.configure()
144142
cmake.build()
145143

146144
def package(self):
147145
copy(self, pattern="LICENSE*", dst="licenses", src=self.source_folder)
148-
for ext in ("*.pyi", "*.so", "*.lib", "*.a", "*.pyd"):
149-
copy(self, ext, src = self.build_folder, dst = path.join(self.package_folder, "lib"), keep_path = False)
150146

151-
for ext in ("*.dll", "*.so", "*.dylib"):
152-
copy(self, ext, src = self.build_folder, dst = path.join(self.package_folder, "bin"), keep_path = False)
153-
copy(self, "*.h", path.join(self.source_folder, "include"), path.join(self.package_folder, "include"))
147+
for ext in ("*.pyi", "*.so", "*.lib", "*.a", "*.pyd", "*.dylib", "*.dll"):
148+
copy(self, ext, src=self.build_folder,
149+
dst=os.path.join(self.package_folder, "lib"), keep_path=False)
150+
151+
copy(self, "*.h", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include"))
154152

155153
def package_info(self):
156-
self.cpp_info.libdirs = [ path.join(self.package_folder, "lib") ]
157-
if self.in_local_cache:
158-
self.runenv_info.append_path("PYTHONPATH", path.join(self.package_folder, "lib"))
159-
else:
160-
self.runenv_info.append_path("PYTHONPATH", self.build_folder)
154+
self.conf_info.define("user.pyarcus:pythonpath", os.path.join(self.package_folder, self.cpp.package.libdirs[0]))

test_package/conanfile.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
class ArcusTestConan(ConanFile):
1414
settings = "os", "compiler", "build_type", "arch"
15-
generators = "VirtualRunEnv"
1615
test_type = "explicit"
1716

1817
def requirements(self):
@@ -23,22 +22,21 @@ def generate(self):
2322
venv.generate()
2423

2524
cpp_info = self.dependencies[self.tested_reference_str].cpp_info
26-
copy(self, "*.pyd", src = cpp_info.libdirs[0], dst =self.build_folder)
25+
copy(self, "*.pyd", src=cpp_info.libdirs[0], dst=self.build_folder)
2726

2827
for dep in self.dependencies.values():
2928
for bin_dir in dep.cpp_info.bindirs:
30-
copy(self, "*.dll", src = bin_dir, dst = self.build_folder)
31-
32-
def build(self):
33-
if can_run(self):
34-
shutil.copy(Path(self.source_folder).joinpath("test.py"), Path(self.build_folder).joinpath("test.py"))
35-
shutil.copy(Path(self.source_folder).joinpath("test.proto"), Path(self.build_folder).joinpath("test.proto"))
36-
29+
copy(self, "*.dll", src=bin_dir, dst=self.build_folder)
3730

3831
def test(self):
3932
if can_run(self):
4033
test_buf = StringIO()
41-
self.run(f"python test.py", env = "conanrun", output = test_buf, run_environment=True)
34+
try:
35+
self.run("python test.py", env="conanrun", stdout=test_buf, scope="run")
36+
except ConanException as ex:
37+
# As long as it still outputs 'True', at least we can say the package is build correctly.
38+
# (For example: A non-zero exit code might indicate a bug, but that's more the domain of unit-tests, not really relevant to wether or not that _package_ has been build correctly.)
39+
print(f"WARNING: {str(ex)}")
4240
ret_val = test_buf.getvalue()
4341
if "True" not in ret_val:
4442
raise ConanException("pyArcus wasn't build correctly!")

0 commit comments

Comments
 (0)