Skip to content

Commit a0067cb

Browse files
committed
Remove Conf
1 parent b9787ed commit a0067cb

File tree

4 files changed

+3
-94
lines changed

4 files changed

+3
-94
lines changed

cppython/plugins/conan/builder.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Construction of Conan data"""
22

3-
import shutil
4-
from pathlib import Path, PurePosixPath
3+
from pathlib import Path
54

65
from pydantic import DirectoryPath
76

@@ -20,15 +19,13 @@ def _create_base_conanfile(
2019
base_file: Path,
2120
dependencies: list[ConanDependency],
2221
dependency_groups: dict[str, list[ConanDependency]],
23-
cmake_binary: Path | None = None,
2422
) -> None:
2523
"""Creates a conanfile_base.py with CPPython managed dependencies.
2624
2725
Args:
2826
base_file: Path to write the base conanfile
2927
dependencies: List of main dependencies
3028
dependency_groups: Dictionary of dependency groups (e.g., 'test')
31-
cmake_binary: Optional path to CMake binary to use
3229
"""
3330
test_dependencies = dependency_groups.get('test', [])
3431

@@ -46,16 +43,6 @@ def _create_base_conanfile(
4643
'\n'.join(test_requires_lines) if test_requires_lines else ' pass # No test requirements'
4744
)
4845

49-
# Generate configure method content for cmake_program if specified
50-
if cmake_binary:
51-
# Use PurePosixPath for conan compatibility and space handling
52-
cmake_path_str = f'"{PurePosixPath(cmake_binary.resolve())}"'
53-
configure_content = f''' def configure(self):
54-
"""CPPython managed configuration."""
55-
self.conf.define("tools.cmake:cmake_program", {repr(cmake_path_str)})'''
56-
else:
57-
configure_content = ''
58-
5946
content = f'''"""CPPython managed base ConanFile.
6047
6148
This file is auto-generated by CPPython. Do not edit manually.
@@ -67,7 +54,6 @@ def _create_base_conanfile(
6754
6855
class CPPythonBase(ConanFile):
6956
"""Base ConanFile with CPPython managed dependencies."""
70-
{configure_content}
7157
7258
def requirements(self):
7359
"""CPPython managed requirements."""
@@ -164,25 +150,13 @@ def generate_conanfile(
164150
165151
Args:
166152
directory: The project directory
167-
data: Generation data containing dependencies, project info, and cmake binary path.
168-
If cmake_binary is not provided, attempts to find cmake in the current
169-
Python environment.
153+
data: Generation data containing dependencies and project info.
170154
"""
171155
directory.mkdir(parents=True, exist_ok=True)
172156

173-
# Resolve cmake binary path
174-
resolved_cmake: Path | None = None
175-
if data.cmake_binary and data.cmake_binary != 'cmake':
176-
resolved_cmake = Path(data.cmake_binary).resolve()
177-
else:
178-
# Try to find cmake in the current Python environment (venv)
179-
cmake_path = shutil.which('cmake')
180-
if cmake_path:
181-
resolved_cmake = Path(cmake_path).resolve()
182-
183157
# Always regenerate the base conanfile with managed dependencies
184158
base_file = directory / 'conanfile_base.py'
185-
self._create_base_conanfile(base_file, data.dependencies, data.dependency_groups, resolved_cmake)
159+
self._create_base_conanfile(base_file, data.dependencies, data.dependency_groups)
186160

187161
# Only create conanfile.py if it doesn't exist
188162
conan_file = directory / self._filename

cppython/plugins/conan/plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def _prepare_installation(self, groups: list[str] | None = None) -> Path:
121121
dependency_groups=resolved_dependency_groups,
122122
name=self.core_data.pep621_data.name,
123123
version=self.core_data.pep621_data.version,
124-
cmake_binary=self._cmake_binary,
125124
)
126125

127126
self.builder.generate_conanfile(

cppython/plugins/conan/schema.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ class ConanfileGenerationData(CPPythonModel):
307307
dependency_groups: dict[str, list[ConanDependency]]
308308
name: str
309309
version: str
310-
cmake_binary: str | None = None
311310

312311

313312
class ConanConfiguration(CPPythonModel):

tests/unit/plugins/conan/test_builder.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -171,66 +171,3 @@ def test_inheritance_chain(self, builder: Builder, tmp_path: Path) -> None:
171171
assert 'class TestProjectPackage(CPPythonBase):' in user_content
172172
assert 'super().requirements()' in user_content
173173
assert 'super().build_requirements()' in user_content
174-
175-
def test_cmake_binary_configure(self, builder: Builder, tmp_path: Path) -> None:
176-
"""Test that cmake_binary generates configure() with forward slashes."""
177-
base_file = tmp_path / 'conanfile_base.py'
178-
cmake_path = Path('C:/Program Files/CMake/bin/cmake.exe')
179-
180-
builder._create_base_conanfile(base_file, [], {}, cmake_binary=cmake_path)
181-
182-
content = base_file.read_text(encoding='utf-8')
183-
assert 'def configure(self):' in content
184-
assert 'self.conf.define("tools.cmake:cmake_program"' in content
185-
assert 'C:/Program Files/CMake/bin/cmake.exe' in content
186-
assert '\\' not in content.split('tools.cmake:cmake_program')[1].split('"')[1]
187-
188-
def test_cmake_binary_path_with_spaces(self, builder: Builder, tmp_path: Path) -> None:
189-
"""Test that cmake_binary paths with spaces are quoted to prevent shell parsing errors."""
190-
base_file = tmp_path / 'conanfile_base.py'
191-
cmake_path = Path('C:/Program Files/CMake/bin/cmake.exe')
192-
193-
builder._create_base_conanfile(base_file, [], {}, cmake_binary=cmake_path)
194-
195-
content = base_file.read_text(encoding='utf-8')
196-
# The path must be wrapped in quotes so Conan passes it as a single argument
197-
assert '"C:/Program Files/CMake/bin/cmake.exe"' in content
198-
199-
def test_no_cmake_binary(self, builder: Builder, tmp_path: Path) -> None:
200-
"""Test that no cmake_binary means no configure() method."""
201-
base_file = tmp_path / 'conanfile_base.py'
202-
203-
builder._create_base_conanfile(base_file, [], {}, cmake_binary=None)
204-
205-
content = base_file.read_text(encoding='utf-8')
206-
assert 'def configure(self):' not in content
207-
208-
@pytest.mark.parametrize(
209-
('venv_cmake', 'expect_configure'),
210-
[
211-
('/path/to/venv/bin/cmake', True),
212-
(None, False),
213-
],
214-
)
215-
def test_cmake_binary_venv_fallback(
216-
self,
217-
builder: Builder,
218-
tmp_path: Path,
219-
monkeypatch: pytest.MonkeyPatch,
220-
venv_cmake: str | None,
221-
expect_configure: bool,
222-
) -> None:
223-
"""Test venv cmake fallback when cmake_binary is default."""
224-
monkeypatch.setattr('cppython.plugins.conan.builder.shutil.which', lambda _: venv_cmake)
225-
226-
data = ConanfileGenerationData(
227-
dependencies=[],
228-
dependency_groups={},
229-
name='test-project',
230-
version='1.0.0',
231-
cmake_binary='cmake',
232-
)
233-
builder.generate_conanfile(directory=tmp_path, data=data)
234-
235-
content = (tmp_path / 'conanfile_base.py').read_text(encoding='utf-8')
236-
assert ('def configure(self):' in content) == expect_configure

0 commit comments

Comments
 (0)