Skip to content

Commit

Permalink
fix: address formatting and style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ssardina committed Mar 19, 2024
1 parent ca3612e commit eeb12f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
25 changes: 12 additions & 13 deletions pddl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
It contains the class definitions to build and modify PDDL domains or problems.
"""
from textwrap import indent
from typing import AbstractSet, Collection, Dict, Optional, Tuple, cast

from pddl._validation import (
Expand All @@ -26,23 +27,21 @@
from pddl.action import Action
from pddl.custom_types import name as name_type
from pddl.custom_types import namelike, parse_name, to_names, to_types # noqa: F401
from pddl.formatter import (
print_constants,
print_function_skeleton,
print_predicates_with_types,
print_types_or_functions_with_parents,
remove_empty_lines,
sort_and_print_collection,
)
from pddl.helpers.base import assert_, check, ensure, ensure_set
from pddl.logic.base import And, Formula, is_literal
from pddl.logic.functions import FunctionExpression, Metric, NumericFunction
from pddl.logic.predicates import DerivedPredicate, Predicate
from pddl.logic.terms import Constant
from pddl.requirements import Requirements

from pddl.formatter import (
sort_and_print_collection,
print_types_or_functions_with_parents,
print_predicates_with_types,
remove_empty_lines,
print_constants,
print_function_skeleton,
indent,
)


class Domain:
"""A class for a PDDL domain file."""
Expand Down Expand Up @@ -220,9 +219,9 @@ def __init__(
self._domain, self._domain_name = self._parse_domain_and_domain_name(
domain, domain_name
)
self._requirements: Optional[
AbstractSet[Requirements]
] = self._parse_requirements(domain, requirements)
self._requirements: Optional[AbstractSet[Requirements]] = (
self._parse_requirements(domain, requirements)
)
self._objects: AbstractSet[Constant] = ensure_set(objects)
self._init: AbstractSet[Formula] = ensure_set(init)
self._goal: Formula = ensure(goal, And())
Expand Down
15 changes: 14 additions & 1 deletion pddl/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#

"""Formatting utilities for PDDL domains and problems."""
from textwrap import indent
from typing import Callable, Collection, Dict, List, Optional, TypeVar

from pddl.custom_types import name
Expand All @@ -33,6 +32,20 @@ def sort_and_print_collection(
to_string: Callable = str,
is_mandatory: bool = False,
):
"""Given a collection (requirements, actions, objects, etc.) produced its sorted string version with prefix and postfix strings.
Prefix is used to start with strings like "(:requirements" or "(:actions"
Postfix is used to close the structure, usually with ")\n"
Args:
prefix (str): start of the string
collection (Collection): the collection of entities to report as a string
postfix (str): the end of the string
to_string (Callable, optional): the function to use to convert to string. Defaults to str.
is_mandatory (bool, optional): if the string is mandatory even if the collection is empty. Defaults to False.
Returns:
str: a string with <prefix> <string of collection> <postfix>
"""
if len(collection) > 0:
return prefix + " ".join(sorted(map(to_string, collection))) + postfix
elif is_mandatory:
Expand Down

0 comments on commit eeb12f9

Please sign in to comment.