Skip to content

Commit

Permalink
Merge pull request #54 from AI-Planning/docs-and-release
Browse files Browse the repository at this point in the history
Docs, util functions, and release
  • Loading branch information
haz authored Dec 23, 2022
2 parents 7302f23 + 0c63e38 commit e1d3abb
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)>
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions pddl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 3 additions & 5 deletions pddl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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__":
Expand Down
6 changes: 4 additions & 2 deletions pddl/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 18 additions & 6 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
),
],
)
Expand All @@ -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):
Expand Down

0 comments on commit e1d3abb

Please sign in to comment.