Attempt to add solver constraint

This commit is contained in:
Philip Sakievich 2025-03-25 21:09:27 -06:00 committed by psakiev
parent eda744718e
commit 9224994dad
3 changed files with 16 additions and 5 deletions

View File

@ -1001,15 +1001,15 @@ def version_or_package_attr(self, attr, version, default=None):
raise PackageError(f"{attr} attribute not defined on {self.name}")
return value
@property
def needs_commit(self) -> bool:
@classmethod
def needs_commit(cls, version) -> bool:
"""
Method for checking if the package instance needs a commit sha to be found
"""
if isinstance(self.version, GitVersion):
if isinstance(version, GitVersion):
return True
ver_attrs = self.versions.get(self.version)
ver_attrs = cls.versions.get(version)
if ver_attrs:
return bool(ver_attrs.get("tag") or ver_attrs.get("branch"))

View File

@ -1522,6 +1522,7 @@ def __init__(self, tests: bool = False):
self.assumptions: List[Tuple["clingo.Symbol", bool]] = [] # type: ignore[name-defined]
self.declared_versions: Dict[str, List[DeclaredVersion]] = collections.defaultdict(list)
self.possible_versions: Dict[str, Set[GitOrStandardVersion]] = collections.defaultdict(set)
self.git_commit_versions: Dict[str, Set[GitOrStandardVersion]] = collections.defaultdict(set)
self.deprecated_versions: Dict[str, Set[GitOrStandardVersion]] = collections.defaultdict(
set
)
@ -1593,6 +1594,8 @@ def key_fn(version):
),
)
)
if pkg.needs_commit(declared_version.version):
self.git_commit_versions[pkg.name].add(declared_version.version)
# Declare deprecated versions for this package, if any
deprecated = self.deprecated_versions[pkg.name]
@ -2897,11 +2900,14 @@ def virtual_providers(self):
def define_version_constraints(self):
"""Define what version_satisfies(...) means in ASP logic."""
# TODO(psakiev)
for pkg_name, versions in sorted(self.version_constraints):
# generate facts for each package constraint and the version
# that satisfies it
for v in sorted(v for v in self.possible_versions[pkg_name] if v.satisfies(versions)):
self.gen.fact(fn.pkg_fact(pkg_name, fn.version_satisfies(versions, v)))
if v in self.git_commit_versions[pkg_name]:
self.gen.fact(fn.pkg_fact(pkg_name, fn.version_needs_commit(v)))
self.gen.newline()
@ -4199,7 +4205,7 @@ def _specs_with_commits(spec):
if not (has_commit_var or has_git_version):
return
# StandardVersions paired to git branches or tags and GitVersions
assert spec.package.needs_commit, f"{spec.name}@{spec.version} can not have a commit variant"
assert spec.package.needs_commit(spec.version), f"{spec.name}@{spec.version} can not have a commit variant"
# Specs with commit variants
# - variant value satsifies commit regex

View File

@ -335,6 +335,11 @@ attr("node_version_satisfies", node(ID, Package), Constraint)
:- attr("version", node(ID, Package), Version),
pkg_fact(Package, version_satisfies(Constraint, Version)).
% Specs with a commit variant can't use versions that don't need commits
:- attr("version", node(ID, Package), Version),
not pkg_fact(Package, version_needs_commit(Version)),
attr("variant_value", PackageNode, "commit", _).
#defined version_satisfies/3.
#defined deprecated_versions_not_allowed/0.
#defined deprecated_version/2.