summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2023-08-14 10:17:54 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2023-08-15 15:54:37 -0700
commitd07d5410f3507813f9a01f84b6ffbd5b0b17291f (patch)
tree2f2ad85f5aca439205180eaa5d9647dea451e521 /lib
parent1db73eb1f222048fbdaf43835000ac17c12694bf (diff)
downloadspack-d07d5410f3507813f9a01f84b6ffbd5b0b17291f.tar.gz
spack-d07d5410f3507813f9a01f84b6ffbd5b0b17291f.tar.bz2
spack-d07d5410f3507813f9a01f84b6ffbd5b0b17291f.tar.xz
spack-d07d5410f3507813f9a01f84b6ffbd5b0b17291f.zip
Rename "stringify", improve docs
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/solver/asp.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index 71aa57e1bf..f429501aca 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -591,20 +591,24 @@ class NodeArgument(NamedTuple):
pkg: str
-def stringify(sym):
- """Stringify symbols from clingo models.
+def intermediate_repr(sym):
+ """Returns an intermediate representation of clingo models for Spack's spec builder.
- This will turn a ``clingo.Symbol`` into a string, or a sequence of ``clingo.Symbol``
- objects into a tuple of strings.
+ Currently, transforms symbols from clingo models either to strings or to NodeArgument objects.
+ Returns:
+ This will turn a ``clingo.Symbol`` into a string or NodeArgument, or a sequence of
+ ``clingo.Symbol`` objects into a tuple of those objects.
"""
# TODO: simplify this when we no longer have to support older clingo versions.
if isinstance(sym, (list, tuple)):
- return tuple(stringify(a) for a in sym)
+ return tuple(intermediate_repr(a) for a in sym)
try:
if sym.name == "node":
- return NodeArgument(id=stringify(sym.arguments[0]), pkg=stringify(sym.arguments[1]))
+ return NodeArgument(
+ id=intermediate_repr(sym.arguments[0]), pkg=intermediate_repr(sym.arguments[1])
+ )
except RuntimeError:
# This happens when using clingo w/ CFFI and trying to access ".name" for symbols
# that are not functions
@@ -623,10 +627,10 @@ def stringify(sym):
def extract_args(model, predicate_name):
"""Extract the arguments to predicates with the provided name from a model.
- Pull out all the predicates with name ``predicate_name`` from the model, and return
- their stringified arguments as tuples.
+ Pull out all the predicates with name ``predicate_name`` from the model, and
+ return their intermediate representation.
"""
- return [stringify(sym.arguments) for sym in model if sym.name == predicate_name]
+ return [intermediate_repr(sym.arguments) for sym in model if sym.name == predicate_name]
class ErrorHandler:
@@ -874,7 +878,8 @@ class PyclingoDriver:
for sym in best_model:
if sym.name not in ("attr", "error", "opt_criterion"):
tty.debug(
- "UNKNOWN SYMBOL: %s(%s)" % (sym.name, ", ".join(stringify(sym.arguments)))
+ "UNKNOWN SYMBOL: %s(%s)"
+ % (sym.name, ", ".join(intermediate_repr(sym.arguments)))
)
elif cores: