Skip to content

Commit 0f8eac3

Browse files
committed
try fix profile
1 parent 6d9c3c0 commit 0f8eac3

File tree

1 file changed

+94
-39
lines changed

1 file changed

+94
-39
lines changed

setup.py

Lines changed: 94 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,114 @@
88

99

1010
class CMakeExtension(Extension):
11-
def __init__(self, name: str, sourcedir: Path) -> None:
11+
def __init__(self, name: str, source_dir: Path) -> None:
1212
super().__init__(name, sources=[])
13-
self.sourcedir = sourcedir.resolve()
13+
self.source_dir = source_dir.resolve()
1414

1515

1616
class CMakeBuild(build_ext):
17-
def build_extension(self, ext: CMakeExtension) -> None:
18-
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
19-
extdir = ext_fullpath.parent.resolve()
17+
def conan_profile(self) -> str:
18+
subprocess.run(["conan", "profile", "detect", "-e"], check=True)
2019

21-
build_temp = Path(self.build_temp) / ext.name
22-
build_temp.mkdir(parents=True, exist_ok=True)
20+
default_path = Path.home() / ".conan2" / "profiles" / "default"
2321

24-
subprocess.run(["conan", "profile", "detect", "-e"], check=True)
22+
with open(default_path, "r") as f:
23+
default_profile = f.read()
24+
default_profile = default_profile.replace("compiler.cppstd=gnu14", "compiler.cppstd=gnu20")
25+
with open(default_path, "w") as f:
26+
f.write(default_profile)
2527

26-
conan_odr_remote = "https://artifactory.opendocument.app/artifactory/api/conan/conan"
28+
def conan_remote(self) -> str:
29+
conan_odr_remote = (
30+
"https://artifactory.opendocument.app/artifactory/api/conan/conan"
31+
)
2732

28-
result = subprocess.run(["conan", "remote", "list"], check=True, capture_output=True, text=True)
33+
result = subprocess.run(
34+
["conan", "remote", "list"], check=True, capture_output=True, text=True
35+
)
2936
if conan_odr_remote not in result.stdout:
3037
print(f"Adding Conan remote {conan_odr_remote}")
31-
subprocess.run([
38+
subprocess.run(
39+
[
40+
"conan",
41+
"remote",
42+
"add",
43+
"odr",
44+
conan_odr_remote,
45+
],
46+
check=True,
47+
)
48+
49+
def conan_install(self, source_dir: Path, build_dir: Path) -> None:
50+
subprocess.run(
51+
[
3252
"conan",
33-
"remote",
34-
"add",
35-
"odr",
36-
conan_odr_remote,
37-
], check=True)
38-
39-
conan_args = [
40-
f"--output-folder={str(build_temp)}",
41-
"--build=missing",
42-
"-s",
43-
"build_type=Release",
44-
]
45-
46-
subprocess.run(["conan", "install", str(ext.sourcedir), *conan_args], check=True)
47-
48-
cmake_args = [
49-
f"-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake",
50-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={str(extdir)}{os.sep}",
51-
f"-DPYTHON_EXECUTABLE={sys.executable}",
52-
f"-DCMAKE_BUILD_TYPE=Release",
53-
]
54-
55-
build_args = [
56-
"--config",
57-
"Release",
58-
]
53+
"install",
54+
str(source_dir),
55+
f"--output-folder={str(build_dir)}",
56+
"--build=missing",
57+
"-s",
58+
"build_type=Release",
59+
],
60+
check=True,
61+
)
62+
63+
def cmake_configure(self, source_dir: Path, build_dir: Path, ext_dir: Path) -> None:
64+
subprocess.run(
65+
[
66+
"cmake",
67+
"-S",
68+
str(source_dir),
69+
"-B",
70+
str(build_dir),
71+
f"-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake",
72+
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={str(ext_dir)}{os.sep}",
73+
f"-DPYTHON_EXECUTABLE={sys.executable}",
74+
f"-DCMAKE_BUILD_TYPE=Release",
75+
],
76+
check=True,
77+
)
5978

79+
def cmake_build(self, build_dir: Path) -> None:
6080
subprocess.run(
61-
["cmake", "-S", str(ext.sourcedir), "-B", str(build_temp), *cmake_args], check=True
81+
[
82+
"cmake",
83+
"--build",
84+
str(build_dir),
85+
"--config",
86+
"Release",
87+
],
88+
check=True,
6289
)
63-
subprocess.run(["cmake", "--build", str(build_temp), *build_args], check=True)
90+
91+
def cmake_install(self, build_dir: Path) -> None:
92+
subprocess.run(
93+
[
94+
"cmake",
95+
"--install",
96+
str(build_dir),
97+
"--config",
98+
"Release",
99+
],
100+
check=True,
101+
)
102+
103+
def build_extension(self, ext: CMakeExtension) -> None:
104+
source_dir = Path(ext.source_dir)
105+
106+
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
107+
ext_dir = ext_fullpath.parent.resolve()
108+
109+
build_temp = Path(self.build_temp) / ext.name
110+
build_temp.mkdir(parents=True, exist_ok=True)
111+
112+
self.conan_profile()
113+
self.conan_remote()
114+
self.conan_install(source_dir, build_temp)
115+
116+
self.cmake_configure(source_dir, build_temp, ext_dir)
117+
self.cmake_build(build_temp)
118+
self.cmake_install(build_temp)
64119

65120

66121
setup(

0 commit comments

Comments
 (0)