Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# export PATH="/usr/local/go/bin:/usr/local/bin:$PATH"
# export GOPATH="~/go"

install:
poetry install
build:
uv build

install-tools:
cd tools && export PATH="/usr/local/go/bin:/usr/local/bin:$PATH" && go mod init mkgherkin && go mod tidy
Expand All @@ -44,19 +44,10 @@ unit-test:
PYTHONPATH=src python -m doctest tools/*.py
PYTHONPATH=src python -m doctest features/steps/*.py

sphinx:
docs: $(wildcard docs/source/*.rst)
PYTHONPATH=src python -m doctest docs/source/*.rst
export PYTHONPATH=$(PWD)/src:$(PWD)/tools && cd docs && $(MAKE) html

ghpages:
-git checkout gh-pages && \
mv docs/build/html new-docs && \
rm -rf docs && \
mv new-docs docs && \
git add -u && \
git add -A && \
git commit -m "Updated generated Sphinx documentation"

lint:
tox -e lint

Expand Down
5 changes: 0 additions & 5 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ parser

.. automodule:: celpy.celparser

tools.textproto_to_gherkin
==========================


.. automodule:: textproto_to_gherkin
35 changes: 18 additions & 17 deletions docs/source/c7n_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ Resource Type Implementations for {function.name}:

:example:

.. code-block:: yaml
.. code:: yaml

policies:
- name: ami-remove-launch-permissions
Expand All @@ -980,7 +980,7 @@ Resource Type Implementations for {function.name}:

:Example:

.. code-block:: yaml
.. code:: yaml

policies:
- name: ec2-ancient-ami
Expand Down Expand Up @@ -3711,7 +3711,7 @@ tag value syntax.
# up mon-fri from 6am-9pm; up sun from 10am-6pm; pacific time
off=[(M-F,21),(U,18)];on=[(M-F,6),(U,10)];tz=pt

The :py:`resource_schedule` function reaches into the :py:class:`c7n.filters.offhours.ScheduleParser` class
The :py:func:`resource_schedule` function reaches into the :py:class:`c7n.filters.offhours.ScheduleParser` class
to parse the schedule text and compare it against the current day and hour in the given ``Now`` value.

An alternative is to eschew this special language and replace it with CEL.
Expand Down Expand Up @@ -4031,7 +4031,7 @@ Resource Type Implementations for {function.name}:

:example:

.. code-block:
.. code-block:: yaml

policies:
- name: glacier-cross-account
Expand Down Expand Up @@ -4159,7 +4159,7 @@ Resource Type Implementations for {function.name}:

:example:

.. code-block:
.. code-block:: yaml

policies:
- name: sns-cross-account
Expand Down Expand Up @@ -4239,9 +4239,9 @@ This, in turn, leads to a raft of special functions required to extract the info

- :py:func:`c7nlib.get_key_policy` which depends on :py:meth:`CELFilter.get_key_policy`

- :py:func:`c7nlib.describe_subscription_filters` which depends on :py:attr:`CELFilter.manager
- :py:func:`c7nlib.describe_subscription_filters` which depends on :py:attr:`CELFilter.manager`

- :py:func:`c7nlib.describe_db_snapshot_attributes` which depends on :py:attr:`CELFilter.manager
- :py:func:`c7nlib.describe_db_snapshot_attributes` which depends on :py:attr:`CELFilter.manager`

- :py:func:`c7nlib.arn_split`

Expand Down Expand Up @@ -4538,7 +4538,7 @@ on the resource type.
is-not-logging
--------------

See `is_logging`_.
See `is-logging`_.

Schema

Expand Down Expand Up @@ -9772,15 +9772,16 @@ Resource Type Implementations for {function.name}:
The policy will trigger on the following IAM policy (statement).
For example:

.. code-block: json
{
'Version': '2012-10-17',
'Statement': [{
'Action': '*',
'Resource': '*',
'Effect': 'Allow'
}]
}
.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [{
"Action": "*",
"Resource": "*",
"Effect": "Allow"
}]
}

Additionally, the policy checks if the statement has no 'Condition' or
'NotAction'
Expand Down
41 changes: 41 additions & 0 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. comment
# Copyright 2020 The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0

######################
Configuration
######################

The CLI application can bind argument values from the environment.
The command-line provides variable names and type information.
The OS environment provides string values.

.. code:: bash

export x=6
export y=7
celpy -n --arg x:int --arg y:int 'x*y'
42

While this example uses the OS environment,
it isn't the usual sense of *configuration*.
The only configuration options available for the command-line application are the logging configuration.

If a ``celpy.toml`` file exists in the local directory or the user's ``HOME`` directory, this will be used to provide logging configuration for the ``celpy`` application.

This file must have a ``logging`` paragraph.
This paragraph can contain the parameters for logging configuration.

.. code:: toml

[logging]
version = 1
formatters.minimal.format = "%(message)s"
formatters.console.format = "%(levelname)s:%(name)s:%(message)s"
formatters.details.format = "%(levelname)s:%(name)s:%(module)s:%(lineno)d:%(message)s"
root.level = "WARNING"
root.handlers = ["console"]

[logging.handlers.console]
class = "logging.StreamHandler"
formatter = "console"
2 changes: 2 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ Specifically, the intent is to be part of Cloud Custodian, C7N, as part of the s
:maxdepth: 2
:caption: Contents:

installation
cli
integration
configuration
structure
api
c7n_functions
Expand Down
36 changes: 36 additions & 0 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. comment
# Copyright 2020 The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0

######################
Installation
######################

When using **poetry** or **uv**, add "cel-python" to the dependencies.

.. code-block:: bash

uv add cel-python

The optional RE2 package significantly speeds up regular expression matching.

.. code-block:: bash

uv add cel-python[re2]

For other tooling and virtual environment configurations, this can be installed with **PIP** commands.

.. code-block:: bash

python -m pip install cel-python

The optional RE2 package significantly speeds up regular expression matching.

.. code-block:: bash

python -m pip install cel-python[re2]

.. warning::

In the case where the platform is "darwin" and the architecture is "arm64" and python is "3.13",
RE2 may not compile properly during installation.
8 changes: 8 additions & 0 deletions features/expr_test_bc.feature
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ Then stdout matches '42'
And stderr is ''
And exit status is 0

Scenario: Variables provided as environment variables
Given OS environment sets x to 6
And OS environment sets y to 7
When celpy -n --arg x:int --arg y:int 'x*y' is run
Then stdout matches '42'
And stderr is ''
And exit status is 0

Scenario: Formatting integer results in hexadecimal
When celpy -n -f '#8x' '0xdeadbeef' is run
Then stdout matches '0xdeadbeef'
Expand Down
48 changes: 28 additions & 20 deletions features/steps/cli_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ def step_impl(context, json):
context.data['json'].append(json)


@given(u'OS environment sets {name} to {value}')
def step_impl(context, name, value):
context.data['bindings'][name] = str(value)


@when(u'echo document | celpy {arguments} is run')
def step_impl(context, arguments):
if "PYTHONPATH" in context.config.userdata:
environment = {"PYTHONPATH": context.config.userdata["PYTHONPATH"]}
else:
environment = {}
if sys.version_info.minor <= 6:
extra = {}
else:
extra = {'text': True}
environment.update(context.data['bindings'])
# if sys.version_info.minor <= 6:
# extra = {}
# else:
extra = {'text': True}

context.data['arguments'] = shlex.split(arguments)

Expand All @@ -71,12 +77,12 @@ def step_impl(context, arguments):
test_dir.rmdir()

context.data['status'] = result.returncode
if sys.version_info.minor <= 6:
context.data['stdout'] = result.stdout.decode('utf-8')
context.data['stderr'] = result.stderr.decode('utf-8')
else:
context.data['stdout'] = result.stdout
context.data['stderr'] = result.stderr
# if sys.version_info.minor <= 6:
# context.data['stdout'] = result.stdout.decode('utf-8')
# context.data['stderr'] = result.stderr.decode('utf-8')
# else:
context.data['stdout'] = result.stdout
context.data['stderr'] = result.stderr

if "debug" in context.config.userdata:
for line in context.data['stdout'].splitlines():
Expand All @@ -95,10 +101,11 @@ def step_impl(context, arguments):
environment = {"PYTHONPATH": context.config.userdata["PYTHONPATH"]}
else:
environment = {}
if sys.version_info.minor <= 6:
extra = {}
else:
extra = {'text': True}
environment.update(context.data['bindings'])
# if sys.version_info.minor <= 6:
# extra = {}
# else:
extra = {'text': True}

context.data['arguments'] = shlex.split(arguments)

Expand All @@ -111,12 +118,12 @@ def step_impl(context, arguments):
)

context.data['status'] = result.returncode
if sys.version_info.minor <= 6:
context.data['stdout'] = result.stdout.decode('utf-8')
context.data['stderr'] = result.stderr.decode('utf-8')
else:
context.data['stdout'] = result.stdout
context.data['stderr'] = result.stderr
# if sys.version_info.minor <= 6:
# context.data['stdout'] = result.stdout.decode('utf-8')
# context.data['stderr'] = result.stderr.decode('utf-8')
# else:
context.data['stdout'] = result.stdout
context.data['stderr'] = result.stderr

if "debug" in context.config.userdata:
for line in context.data['stdout'].splitlines():
Expand All @@ -125,6 +132,7 @@ def step_impl(context, arguments):
print(f"ERR: {line}", file=sys.stderr)



@then(u'stdout matches \'{regex}\'')
def step_impl(context, regex):
pattern = re.compile(regex)
Expand Down
20 changes: 4 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ authors = [
{ name = "S.Lott", email = "slott56@gmail.com" }
]
requires-python = ">=3.9"
packages = [{ include = "celpy", from = "src"}]

dependencies = [
"lark>=1.2.2",
"pendulum>=3.1.0",
"pyyaml>=6.0.2",
"jmespath>=1.0.1",
"tomli >= 1.1.0 ; python_version < '3.11'",
"sphinx>=7.4.7",
]

[project.scripts]
Expand All @@ -48,21 +49,8 @@ re2 = [
requires = ["hatchling"]
build-backend = "hatchling.build"

#[build-system]
#requires = ["uv_build>=0.7.7,<0.8.0"]
#build-backend = "uv_build"

#[build-system]
#requires = ["flit"]
#build-backend = "flit.api:main"

#[build-system]
#requires = ["pdm-backend"]
#build-backend = "pdm.backend"

#[build-system]
#requires = ["setuptools", "setuptools-scm"]
#build-backend = "setuptools.build_meta"
[tool.hatch.build.targets.wheel]
packages = ["src/celpy"]

[dependency-groups]
dev = [
Expand Down
2 changes: 0 additions & 2 deletions src/cel_python/__init__.py

This file was deleted.

Loading
Loading