Skip to content

Commit 507236a

Browse files
committed
Baseline
1 parent e6fb1cd commit 507236a

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

cppython/core/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class CPPythonModel(BaseModel):
1616
"""The base model to use for all CPPython models"""
1717

18-
model_config = ConfigDict(validate_by_name=False, validate_by_alias=True, arbitrary_types_allowed=True)
18+
model_config = ConfigDict(validate_by_name=True, validate_by_alias=True, arbitrary_types_allowed=True)
1919

2020

2121
class ProjectData(CPPythonModel, extra='forbid'):

cppython/plugins/vcpkg/resolution.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Builder to help build vcpkg state"""
22

3+
from subprocess import CalledProcessError, check_output
34
from typing import Any
45

56
from packaging.requirements import Requirement
@@ -24,13 +25,21 @@ def generate_manifest(core_data: CorePluginData, data: VcpkgData) -> Manifest:
2425
Returns:
2526
The manifest
2627
"""
27-
manifest = {
28-
'name': core_data.pep621_data.name,
29-
'version_string': core_data.pep621_data.version,
30-
'dependencies': data.dependencies,
31-
}
32-
33-
return Manifest(**manifest)
28+
# If builtin_baseline is None, we set it to the current commit of the cloned vcpkg repository
29+
if data.builtin_baseline is None:
30+
try:
31+
# Get the current commit hash from the vcpkg repository
32+
result = check_output(['git', 'rev-parse', 'HEAD'], cwd=str(core_data.project_data.project_root))
33+
data.builtin_baseline = result.decode('utf-8').strip()
34+
except (CalledProcessError, FileNotFoundError) as e:
35+
raise ConfigException('Failed to get the current commit hash from the vcpkg repository.', []) from e
36+
37+
return Manifest(
38+
name=core_data.pep621_data.name,
39+
version_string=core_data.pep621_data.version,
40+
dependencies=data.dependencies,
41+
builtin_baseline=data.builtin_baseline,
42+
)
3443

3544

3645
def resolve_vcpkg_data(data: dict[str, Any], core_data: CorePluginData) -> VcpkgData:
@@ -64,6 +73,7 @@ def resolve_vcpkg_data(data: dict[str, Any], core_data: CorePluginData) -> Vcpkg
6473
return VcpkgData(
6574
install_directory=modified_install_directory,
6675
dependencies=vcpkg_dependencies,
76+
builtin_baseline=parsed_data.builtin_baseline,
6777
)
6878

6979

@@ -83,18 +93,18 @@ def resolve_vcpkg_dependency(requirement: Requirement) -> VcpkgDependency:
8393
raise ConfigException('Multiple specifiers are not supported. Please provide a single specifier.', [])
8494

8595
# Extract the version from the single specifier
86-
version = None
96+
min_version = None
8797
if len(specifiers) == 1:
8898
specifier = next(iter(specifiers))
8999
if specifier.operator != '>=':
90100
raise ConfigException(f"Unsupported specifier '{specifier.operator}'. Only '>=' is supported.", [])
91-
version = specifier.version
101+
min_version = specifier.version
92102

93103
return VcpkgDependency(
94104
name=requirement.name,
95105
default_features=True,
96106
features=[],
97-
version=version,
107+
version_ge=min_version,
98108
platform=None,
99109
host=False,
100110
)

cppython/plugins/vcpkg/schema.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class VcpkgDependency(CPPythonModel):
2323
list[str],
2424
Field(description='A list of additional features to require for the dependency.'),
2525
] = []
26-
version: Annotated[
26+
version_ge: Annotated[
2727
str | None,
2828
Field(
2929
alias='version>=',
@@ -45,6 +45,7 @@ class VcpkgData(CPPythonModel):
4545

4646
install_directory: Path
4747
dependencies: list[VcpkgDependency]
48+
builtin_baseline: str | None
4849

4950

5051
class VcpkgConfiguration(CPPythonModel):
@@ -58,14 +59,23 @@ class VcpkgConfiguration(CPPythonModel):
5859
),
5960
] = Path('build')
6061

62+
builtin_baseline: Annotated[
63+
str | None,
64+
Field(
65+
alias='builtin-baseline',
66+
description='A shortcut for specifying the baseline for version resolution in the default registry.',
67+
),
68+
] = None
69+
6170

6271
class Manifest(CPPythonModel):
6372
"""The manifest schema"""
6473

6574
name: Annotated[str, Field(description='The project name')]
6675

67-
version_string: Annotated[str, Field(alias='version-string', description='The arbitrary version string')] = ''
76+
version_string: Annotated[str, Field(alias='version-string', description='The arbitrary version string')]
6877

6978
description: Annotated[str, Field(description='The project description')] = ''
7079
homepage: Annotated[HttpUrl | None, Field(description='Homepage URL')] = None
7180
dependencies: Annotated[list[VcpkgDependency], Field(description='List of dependencies')] = []
81+
builtin_baseline: Annotated[str, Field(alias='builtin-baseline', description='The arbitrary version string')]

tests/integration/examples/test_vcpkg_cmake.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""TODO"""
22

3+
import subprocess
4+
35
from typer.testing import CliRunner
46

57
from cppython.console.entry import app
@@ -21,3 +23,21 @@ def test_simple(example_runner: CliRunner) -> None:
2123
)
2224

2325
assert result.exit_code == 0, result.output
26+
27+
# Run the CMake configuration command
28+
cmake_result = subprocess.run(['cmake', '--preset=default'], capture_output=True, text=True, check=False)
29+
30+
assert cmake_result.returncode == 0, f'CMake configuration failed: {cmake_result.stderr}'
31+
32+
# Run the CMake build command
33+
build_result = subprocess.run(['cmake', '--build', 'build'], capture_output=True, text=True, check=False)
34+
35+
assert build_result.returncode == 0, f'CMake build failed: {build_result.stderr}'
36+
assert 'Build finished successfully' in build_result.stdout, 'CMake build did not finish successfully'
37+
38+
# Execute the built program and verify the output
39+
program_result = subprocess.run(['build/HelloWorld'], capture_output=True, text=True, check=False)
40+
41+
assert program_result.returncode == 0, f'Program execution failed: {program_result.stderr}'
42+
43+
assert 'Hello, World!' in program_result.stdout, 'Program output did not match expected output'

tests/unit/plugins/vcpkg/test_resolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_resolve_vcpkg_dependency() -> None:
1616
dependency = resolve_vcpkg_dependency(requirement)
1717

1818
assert dependency.name == 'example-package'
19-
assert dependency.version == '1.2.3'
19+
assert dependency.version_ge == '1.2.3'
2020
assert dependency.default_features is True
2121
assert dependency.features == []
2222
assert dependency.platform is None

0 commit comments

Comments
 (0)