Skip to content

Commit

Permalink
Merge pull request #60 from cloud-custodian/releng/fix-ci
Browse files Browse the repository at this point in the history
Releng/fix CI and problems with type hints
  • Loading branch information
slott56 committed May 21, 2024
2 parents 22ffa26 + c8011bf commit 4e2a632
Show file tree
Hide file tree
Showing 17 changed files with 1,325 additions and 224 deletions.
44 changes: 32 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: "CI"
on:
push:
pull_request:
env:
POETRY_VERSION: "1.8.3"
DEFAULT_PY_VERSION: "3.12"

jobs:
Lint:
Expand All @@ -11,25 +14,37 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: ${{ env.DEFAULT_PY_VERSION }}
- name: Linting
env:
RUFF_OUTPUT_FORMAT: github
run: |
pip install pre-commit
pre-commit run --all-files
pip install ruff
ruff check src
Tests:
needs: Lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
include:
- python-version: 3.7
tox-target: py37
- python-version: 3.8
- python-version: "3.8"
tox-target: py38
- python-version: "3.9"
tox-target: py39
- python-version: "3.10"
tox-target: py310
- python-version: "3.11"
tox-target: py311
- python-version: "3.12"
tox-target: py312

steps:
- uses: actions/checkout@v2
- name: Install poetry
shell: bash
run: pipx install poetry==${{ env.POETRY_VERSION }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
Expand All @@ -53,16 +68,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install poetry
shell: bash
run: pipx install poetry==${{ env.POETRY_VERSION }}

- uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: ${{ env.DEFAULT_PY_VERSION }}

- name: Install Test Runner
run: |
python -m pip install --upgrade pip
pip install tox
- name: Coverage Create and Upload XML
run: |
tox -e lint && \
bash <(curl -s https://codecov.io/bash) -Z -v -f coverage.xml
- name: Upload Code Coverage
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
name: codecov
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dmypy.json
# Pyre type checker
.pyre/
type_check/lineprecision.txt

# PyCharm Stuff
.idea/*
31 changes: 0 additions & 31 deletions .pre-commit-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ The ``cel_program`` in the above example is an executable CEL program wrapped in
... ast = self.env.compile(object["expr"])
... self.prgm = self.env.program(ast, cel_functions)
... def __call__(self, resource):
... now = datetime.datetime.utcnow()
... now = datetime.datetime.now(tz=datetime.timezone.utc)
... activation = {"resource": celpy.json_to_cel(resource), "now": celpy.celtypes.TimestampType(now)}
... return bool(self.prgm.evaluate(activation))

Expand Down
1,173 changes: 1,173 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

48 changes: 36 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
[project]
name = "celpy"
version = "0.0"
description = "Pure Python implementation of Google Common Expression Language"
readme = "README.rst"
requires-python = ">=3.6"
license = {file = "LICENSE.txt"}
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python"
]

[tool.pytest.ini_options]
markers = [
"refactor: tests that need to be refactored to use celfilter_instance"
Expand All @@ -35,3 +23,39 @@ skip = [
".bzr", ".direnv", ".eggs", ".git", ".hg", ".mypy_cache", ".nox", ".pants.d", ".svn", ".tox", ".venv",
"_build", "buck-out", "build", "dist", "node_modules", "venv", "*.feature", "*.textproto", "*.rst"
]

[tool.poetry]
name = "celpy"
version = "0.1.5"
description = "Pure Python implementation of Google Common Expression Language"
authors = ["S. Lott <slott56@gmail.com>"]
readme = "README.rst"
license = "LICENSE.txt"
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python"
]

[tool.poetry.dependencies]
python = "^3.8"
jmespath = "^1.0.1"
lark-parser = "^0.12.0"
python-dateutil = "^2.9.0.post0"
pyyaml = "^6.0.1"
types-pyyaml = "^6.0.12.20240311"
types-python-dateutil = "^2.9.0.20240316"

[tool.poetry.group.dev.dependencies]
behave = "^1.2.6"
ruff = "^0.4.4"
isort = "^5.13.2"
mypy = "^1.10.0"
pytest = "^8.2.1"
pytest-cov = "^5.0.0"
sphinx = "^6.0"
tox = "^4.15.0"
pre-commit = "^3.5"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
9 changes: 0 additions & 9 deletions requirements-dev.txt

This file was deleted.

9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

43 changes: 0 additions & 43 deletions setup.py

This file was deleted.

5 changes: 2 additions & 3 deletions src/celpy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def arg_type_value(text: str) -> Tuple[str, Annotation, celtypes.Value]:
except ValueError:
raise argparse.ArgumentTypeError(f"arg {text} value invalid for the supplied type")
else:
value = celtypes.StringType(value_text)
value = celtypes.StringType(value_text or "")
type_definition = celtypes.StringType
return name, type_definition, value

Expand Down Expand Up @@ -306,14 +306,13 @@ def do_quit(self, args: str) -> bool:
do_exit = do_quit
do_bye = do_quit

def default(self, args: str) -> bool:
def default(self, args: str) -> None:
"""Evaluate an expression."""
try:
value = self.cel_eval(args)
print(value)
except Exception as ex:
self.logger.error(ex)
return False


def process_json_doc(
Expand Down
20 changes: 11 additions & 9 deletions src/celpy/c7nlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ def process(self, resources):
import urllib.request
import zlib
from contextlib import closing
from distutils import version as version_lib
from packaging.version import Version
from types import TracebackType
from typing import (Any, Callable, Dict, Iterator, List, Optional, Type, Union,
cast)

import dateutil
import jmespath # type: ignore [import]
import jmespath # type: ignore [import-untyped]

from celpy import InterpretedRunner, celtypes
from celpy.adapter import json_to_cel
Expand Down Expand Up @@ -457,7 +457,7 @@ def supernet_of(self, other): # type: ignore[no-untyped-def]
CIDR_Class = Union[Type[IPv4Network], Callable[..., ipaddress.IPv4Address]]


def parse_cidr(value): # type: ignore[no-untyped-def]
def parse_cidr(value: str) -> CIDR:
"""
Process cidr ranges.
Expand All @@ -467,7 +467,7 @@ def parse_cidr(value): # type: ignore[no-untyped-def]
"""
klass: CIDR_Class = IPv4Network
if "/" not in value:
klass = ipaddress.ip_address
klass = ipaddress.ip_address # type: ignore[assignment]
v: CIDR
try:
v = klass(value)
Expand All @@ -478,23 +478,25 @@ def parse_cidr(value): # type: ignore[no-untyped-def]

def size_parse_cidr(value: celtypes.StringType,) -> Optional[celtypes.IntType]:
"""CIDR prefixlen value"""
cidr = parse_cidr(value) # type: ignore[no-untyped-call]
if cidr:
cidr = parse_cidr(value)
if cidr and isinstance(cidr, IPv4Network):
return celtypes.IntType(cidr.prefixlen)
else:
return None


class ComparableVersion(version_lib.LooseVersion):
class ComparableVersion(Version):
"""
The default LooseVersion will fail on comparing present strings, used
The old LooseVersion could fail on comparing present strings, used
in the value as shorthand for certain options.
The new Version doesn't fail as easily.
"""

def __eq__(self, other: object) -> bool:
try:
return super(ComparableVersion, self).__eq__(other)
except TypeError:
except TypeError: # pragma: no cover
return False


Expand Down
Loading

0 comments on commit 4e2a632

Please sign in to comment.