Skip to content

Commit

Permalink
Merge pull request #60 from AI-Planning/dev-maintainance
Browse files Browse the repository at this point in the history
Development maintainance
  • Loading branch information
haz authored May 15, 2023
2 parents 75ecdf4 + 0fceb87 commit fa78d45
Show file tree
Hide file tree
Showing 15 changed files with 1,210 additions and 441 deletions.
406 changes: 406 additions & 0 deletions .bandit.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox
run: pip install "tox>=4.5.1,<4.6.0"
- name: Generate Documentation
run: tox -e docs
8 changes: 5 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

timeout-minutes: 30

Expand All @@ -31,9 +31,11 @@ jobs:
tox -e flake8
- name: Unused code check
run: tox -e vulture
# - name: Docstring check
# run: tox -e darglint
- name: Static type check
run: tox -e mypy
- name: Check copyright
run: tox -e check-copyright
- name: Misc checks
run: |
tox -e bandit
tox -e safety
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox
run: pip install "tox>=4.5.1,<4.6.0"
- name: Unit tests and coverage
run: |
pyver=`echo ${{ matrix.python-version }} | tr -d "."`
tox -e py${{ matrix.python-version }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ clean-test: ## remove test and coverage artifacts
rm -fr .mypy_cache
rm -fr coverage.xml

lint-all: black isort lint static vulture darglint ## run all linters
lint-all: black isort lint static bandit safety vulture ## run all linters

lint: ## check style with flake8
flake8 pddl tests
Expand All @@ -77,12 +77,15 @@ black: ## apply black formatting
black-check: ## check black formatting
black --check --verbose pddl tests

bandit: ## run bandit
bandit --configfile .bandit.yml --recursive pddl tests scripts

safety: ## run safety
safety check

vulture: ## check unused code
vulture pddl scripts/whitelist.py

darglint: ## check docstrings
darglint pddl scripts/whitelist.py

test: ## run tests quickly with the default Python
pytest tests --doctest-modules \
pddl tests/ \
Expand Down
42 changes: 24 additions & 18 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[packages]

[dev-packages]
pytest = ">=7.2.0,<7.3.0"
pytest = ">=7.3.1,<7.4.0"
pytest-cov = ">=4.0.0,<4.1.0"
pytest-randomly = ">=3.12.0,<3.13.0"
pytest-lazy-fixture = ">=0.6.3 ,<0.7.0"
tox = "*"
ipython = "*"
codecov = "*"
tox-travis = "*"
black = ">=22.10.0,<22.11.0"
mypy = ">=0.910,<0.911"
flake8 = ">=4.0.1,<4.1.0"
flake8-docstrings = ">=1.6.0,<1.7.0"
mkdocs = "*"
markdown-include = "*"
isort = ">=5.10.1,<5.11.0"
mistune = "==2.0.0a4"
mkdocs-material = "*"
types-click = "*"
vulture = ">=2.3,<2.4"
pytest-lazy-fixture = "<0.7.0,>=0.6.3"
tox = "<4.6.0,>=4.5.1"
ipython = ">=8.13.2,<8.14.0"
codecov = ">=2.1.13,<2.2.0"
black = "<23.4.0,>=23.3.0"
mypy = ">=1.3.0,<1.4.0"
flake8 = ">=6.0.0,<6.1.0"
flake8-docstrings = "<1.8.0,>=1.7.0"
mkdocs = ">=1.4.3,<1.5.0"
markdown-include = ">=0.8.1,<0.9.0"
isort = "<5.13.0,>=5.12.0"
mistune = "<2.1.0,>=2.0.5"
mkdocs-material = ">=9.1.12,<9.2.0"
types-click = ">=7.1.8,<7.2.0"
vulture = "<2.8,>=2.7"
flake8-bugbear = "<23.6.0,>=23.5.9"
pymdown-extensions = "<9.12,>=9.11"
flake8-isort = ">=6.0.0,<6.1.0"
safety = "<2.4.0,>=2.3.4"
bandit = ">=1.7.5,<1.8.0"

[requires]
python_version = "3.7"
python_version = "3.10"
1,076 changes: 704 additions & 372 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pddl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

_ROOT_PATH = _get_current_path()


# Simple helpers
def parse_domain(fn):
from pddl.parser.domain import DomainParser
Expand Down
10 changes: 8 additions & 2 deletions pddl/helpers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ def _get_current_path() -> Path:
return Path(os.path.dirname(inspect.getfile(inspect.currentframe()))).parent # type: ignore


def assert_(condition: bool, message: str = ""):
"""User-defined assert."""
def assert_(condition: bool, message: str = "") -> None:
"""
User-defined assert.
This function is useful to avoid the use of the built-in assert statement, which is removed
when the code is compiled in optimized mode. For more information, see
https://bandit.readthedocs.io/en/1.7.5/plugins/b101_assert_used.html
"""
if not condition:
raise AssertionError(message)

Expand Down
4 changes: 2 additions & 2 deletions pddl/parser/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def domain(self, args):
elif isinstance(arg, DerivedPredicate):
derived_predicates.append(arg)
else:
assert isinstance(arg, dict)
assert_(isinstance(arg, dict))
kwargs.update(arg)
kwargs.update(actions=actions, derived_predicates=derived_predicates)
return Domain(**kwargs)
Expand Down Expand Up @@ -249,7 +249,7 @@ def cond_effect(self, args):
if len(args) >= 3 and args[1] == Symbols.AND.value:
p_effects = args[2:-1]
return And(*p_effects)
assert len(args) == 1
assert_(len(args) == 1)
return args[0]

def atomic_formula_term(self, args):
Expand Down
10 changes: 6 additions & 4 deletions pddl/parser/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from lark import Lark, ParseError, Transformer

from pddl.core import Problem, Requirements
from pddl.helpers.base import assert_
from pddl.logic.base import And, Not
from pddl.logic.predicates import EqualTo, Predicate
from pddl.logic.terms import Constant
Expand All @@ -43,9 +44,10 @@ def start(self, args):
def problem(self, args):
"""Process the 'problem' rule."""
args = [arg for arg in args if arg is not None]
assert (
args[0].value + args[1].value + args[-1].value == "(define)"
), "Problem should start with '(define' and close with ')'"
assert_(
(args[0].value + args[1].value + args[-1].value == "(define)"),
"Problem should start with '(define' and close with ')'",
)
return Problem(**dict(args[2:-1]))

def problem_def(self, args):
Expand Down Expand Up @@ -82,7 +84,7 @@ def typed_list_name(self, args):

def domain__type_def(self, names):
"""Process a domain type def."""
assert len(names) == 1
assert_(len(names) == 1)
return str(names[0])

def init(self, args):
Expand Down
4 changes: 2 additions & 2 deletions pddl/parser/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Symbols(Enum):
EQUAL = "="


ALL_SYMBOLS = {v.value for v in Symbols} # type: Set[str]
ALL_SYMBOLS: Set[str] = {v.value for v in Symbols}


class RequirementSymbols(Enum):
Expand All @@ -76,4 +76,4 @@ def strip(self) -> str:
return self.value[1:]


ALL_REQUIREMENTS = {v.value for v in RequirementSymbols} # type: Set[str]
ALL_REQUIREMENTS: Set[str] = {v.value for v in RequirementSymbols}
2 changes: 1 addition & 1 deletion tests/test_docs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
MISTUNE_BLOCK_CODE_ID = "block_code"


def compile_and_exec(code: str, locals_dict: Dict = None) -> Dict:
def compile_and_exec(code: str, locals_dict: Optional[Dict] = None) -> Dict:
"""
Compile and exec the code.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_helpers/test_cache_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#

"""Test the cache hash class decorator."""
import pickle
import pickle # nosec

from pddl.helpers.cache_hash import cache_hash

Expand Down Expand Up @@ -45,6 +45,6 @@ def test_hashable():
assert hasattr(obj, "__hash")
assert obj.__hash == h1 == h2

dumped_obj = pickle.dumps(obj)
actual_obj = pickle.loads(dumped_obj)
dumped_obj = pickle.dumps(obj) # nosec
actual_obj = pickle.loads(dumped_obj) # nosec
assert not hasattr(actual_obj, "__hash")
66 changes: 38 additions & 28 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tox]
envlist = check-copyright, black-check, isort-check, docs, flake8, mypy, py3.8, py3.7
envlist = check-copyright, black-check, isort-check, docs, flake8, mypy, py3{7,8,9,10}

[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
pytest>=7.2.0,<7.3.0
pytest<7.4.0,>=7.3.1
pytest-cov>=4.0.0,<4.1.0
pytest-randomly>=3.12.0,<3.13.0
pytest-lazy-fixture>=0.6.3 ,<0.7.0
mistune==2.0.0a4
pytest-lazy-fixture>=0.6.3,<0.7.0
mistune<2.1.0,>=2.0.5

commands =
pytest --basetemp={envtmpdir} --doctest-modules \
Expand All @@ -19,73 +19,83 @@ commands =
--cov-report=html \
--cov-report=term

[testenv:py3.7]
basepython = python3.7

[testenv:py3.8]
basepython = python3.8
[testenv:py{37,38,39,310}]
commands =
{[testenv]commands}

[testenv:flake8]
skip_install = True
deps =
flake8>=5.0.4,<5.1.0
flake8-docstrings>=1.6.0,<1.7.0
flake8-bugbear
pydocstyle
flake8<6.1.0,>=6.0.0
flake8-docstrings<1.8.0,>=1.7.0
flake8-bugbear<23.6.0,>=23.5.9
flake8-isort>=6.0.0,<6.1.0
commands =
flake8 pddl tests

[testenv:mypy]
skip_install = True
deps =
mypy>=0.910,<0.911
types-click>=7.1.7,<7.2.0
mypy>=1.3.0,<1.4.0
types-click>=7.1.8,<7.2.0
commands =
mypy pddl tests

[testenv:black]
skip_install = True
deps = black>=22.10.0,<22.11.0
deps = black<23.4.0,>=23.3.0
commands = black pddl tests

[testenv:black-check]
skip_install = True
deps = black>=22.10.0,<22.11.0
deps = black<23.4.0,>=23.3.0
commands = black pddl tests --check --verbose

[testenv:isort]
skip_install = True
deps = isort>=5.10.1,<5.11.0
deps = isort<5.13.0,>=5.12.0
commands = isort pddl tests

[testenv:isort-check]
skip_install = True
deps = isort>=5.10.1,<5.11.0
deps = isort<5.13.0,>=5.12.0
commands = isort --check-only pddl tests

[testenv:bandit]
skipsdist = True
skip_install = True
deps = bandit>=1.7.5,<1.8.0
commands = bandit --configfile .bandit.yml --recursive pddl tests scripts

[testenv:safety]
skipsdist = False
skip_install = False
deps = safety>=2.3.4,<2.4.0
commands = safety check

[testenv:vulture]
skipsdist = True
skip_install = True
deps = vulture>=2.3,<2.4
deps = vulture<2.8,>=2.7
commands = vulture pddl scripts/whitelist.py

[testenv:docs]
skip_install = True
deps =
mkdocs
mkdocs-material
markdown-include
pymdown-extensions
mkdocs>=1.4.3,<1.5.0
mkdocs-material>=9.1.12,<9.2.0
markdown-include>=0.8.1,<0.9.0
pymdown-extensions<9.12,>=9.11
commands =
mkdocs build --clean

[testenv:docs-serve]
skip_install = True
deps =
mkdocs
mkdocs-material
markdown-include
pymdown-extensions
mkdocs>=1.4.3,<1.5.0
mkdocs-material>=9.1.12,<9.2.0
markdown-include>=0.8.1,<0.9.0
pymdown-extensions<9.12,>=9.11
commands =
mkdocs build --clean
python -c 'print("###### Starting local server. Press Control+C to stop server ######")'
Expand Down

0 comments on commit fa78d45

Please sign in to comment.