diff --git a/AUTHORS.md b/AUTHORS.md index 1d4d6c4..630c82f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -7,4 +7,4 @@ ## Contributors -None yet. [Why not be the first](./contributing.md)? +* [Christian Muise](http://www.haz.ca) <[christian.muise@gmail.com](mailto:christian.muise@gmail.com)> diff --git a/README.md b/README.md index 9609fde..23d9975 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,13 @@ Output: ) ``` +Example parsing: +```python +from pddl import parse_domain, parse_problem +domain = parse_domain('d.pddl') +problem = parse_problem('p.pddl') +``` + ### As CLI tool The package can also be used as a CLI tool. diff --git a/pddl/__init__.py b/pddl/__init__.py index ea89182..ac20961 100644 --- a/pddl/__init__.py +++ b/pddl/__init__.py @@ -26,3 +26,19 @@ from .helpers.base import _get_current_path _ROOT_PATH = _get_current_path() + +# Simple helpers +def parse_domain(fn): + from pddl.parser.domain import DomainParser + + with open(fn, "r") as f: + dtext = f.read() + return DomainParser()(dtext) + + +def parse_problem(fn): + from pddl.parser.problem import ProblemParser + + with open(fn, "r") as f: + ptext = f.read() + return ProblemParser()(ptext) diff --git a/pddl/__main__.py b/pddl/__main__.py index 2269d53..6d1fb01 100644 --- a/pddl/__main__.py +++ b/pddl/__main__.py @@ -14,13 +14,11 @@ """Main entrypoint for the PDDL parser CLI tool.""" import os import sys -from pathlib import Path import click +from pddl import parse_domain, parse_problem from pddl.formatter import domain_to_string, problem_to_string -from pddl.parser.domain import DomainParser -from pddl.parser.problem import ProblemParser @click.group() @@ -38,7 +36,7 @@ def domain(domain_file, quiet): """Check a PDDL domain file is correct.""" if quiet: sys.stdout = open(os.devnull, "a") - print(domain_to_string(DomainParser()(Path(domain_file).read_text()))) + print(domain_to_string(parse_domain(domain_file))) @cli.command() @@ -48,7 +46,7 @@ def problem(problem_file, quiet): """Check a PDDL problem file is correct.""" if quiet: sys.stdout = open(os.devnull, "a") - print(problem_to_string(ProblemParser()(Path(problem_file).read_text()))) + print(problem_to_string(parse_problem(problem_file))) if __name__ == "__main__": diff --git a/pddl/__version__.py b/pddl/__version__.py index b6926e6..10e2e72 100644 --- a/pddl/__version__.py +++ b/pddl/__version__.py @@ -16,8 +16,10 @@ __title__ = "pddl" __description__ = "PDDL parser" __url__ = "https://github.com/AI-Planning/pddl.git" -__version__ = "0.1.0" +__version__ = "0.2.0" __author__ = "Marco Favorito, Francesco Fuggitti" -__author_email__ = "marco.favorito@gmail.com, fuggitti@diag.uniroma1.it" +__author_email__ = ( + "marco.favorito@gmail.com, fuggitti@diag.uniroma1.it, christian.muise@queensu.ca" +) __license__ = "MIT License" __copyright__ = "2021-2022 WhiteMech" diff --git a/tests/test_parser.py b/tests/test_parser.py index 2ae9056..d7af5b3 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -15,7 +15,7 @@ from pathlib import Path import pytest -from pytest import lazy_fixture # type: ignore # noqa +from pytest import lazy_fixture # type:ignore # noqa from pddl.core import Domain, Problem from tests.conftest import ( @@ -42,11 +42,17 @@ def test_problem_parser(problem_parser, pddl_file: Path): @pytest.mark.parametrize( "pddl_file,expected_domain", [ - (BLOCKSWORLD_FILES / "domain.pddl", lazy_fixture("blocksworld_domain")), - (TRIANGLE_FILES / "domain.pddl", lazy_fixture("triangle_tireworld_domain")), + ( + BLOCKSWORLD_FILES / "domain.pddl", + lazy_fixture("blocksworld_domain"), # type:ignore + ), + ( + TRIANGLE_FILES / "domain.pddl", + lazy_fixture("triangle_tireworld_domain"), # type:ignore + ), ( BLOCKSWORLD_FOND_FILES / "domain.pddl", - lazy_fixture("blocksworld_fond_domain"), + lazy_fixture("blocksworld_fond_domain"), # type:ignore ), ], ) @@ -61,8 +67,14 @@ def test_check_domain_parser_output(domain_parser, pddl_file: Path, expected_dom @pytest.mark.parametrize( "pddl_file,expected_problem", [ - (BLOCKSWORLD_FILES / "p01.pddl", lazy_fixture("blocksworld_problem_01")), - (BLOCKSWORLD_FOND_FILES / "p01.pddl", lazy_fixture("blocksworld_fond_01")), + ( + BLOCKSWORLD_FILES / "p01.pddl", + lazy_fixture("blocksworld_problem_01"), # type:ignore + ), + ( + BLOCKSWORLD_FOND_FILES / "p01.pddl", + lazy_fixture("blocksworld_fond_01"), # type:ignore + ), ], ) def test_check_problem_parser_output(problem_parser, pddl_file: Path, expected_problem):