Skip to content

Commit 498c727

Browse files
authored
Change logger names to have a common prefix of "celpy" (cloud-custodian#102)
Also, change logging level to DEBUG for some messages that were formerly INFO. This can reduce clutter. Fix a small problem in pyproject.toml Cleanup documentation and Makefile Restructure the RE2 inclusion to improve code coverage for tests.
1 parent 0e53c7d commit 498c727

20 files changed

Lines changed: 687 additions & 139 deletions

‎Makefile‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# export PATH="/usr/local/go/bin:/usr/local/bin:$PATH"
1818
# export GOPATH="~/go"
1919

20-
install:
21-
poetry install
20+
build:
21+
uv build
2222

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

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

51-
ghpages:
52-
-git checkout gh-pages && \
53-
mv docs/build/html new-docs && \
54-
rm -rf docs && \
55-
mv new-docs docs && \
56-
git add -u && \
57-
git add -A && \
58-
git commit -m "Updated generated Sphinx documentation"
59-
6051
lint:
6152
tox -e lint
6253

‎docs/source/api.rst‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,3 @@ parser
3030

3131
.. automodule:: celpy.celparser
3232

33-
tools.textproto_to_gherkin
34-
==========================
35-
36-
37-
.. automodule:: textproto_to_gherkin

‎docs/source/c7n_functions.rst‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ Resource Type Implementations for {function.name}:
958958

959959
:example:
960960

961-
.. code-block:: yaml
961+
.. code:: yaml
962962
963963
policies:
964964
- name: ami-remove-launch-permissions
@@ -980,7 +980,7 @@ Resource Type Implementations for {function.name}:
980980

981981
:Example:
982982

983-
.. code-block:: yaml
983+
.. code:: yaml
984984
985985
policies:
986986
- name: ec2-ancient-ami
@@ -3711,7 +3711,7 @@ tag value syntax.
37113711
# up mon-fri from 6am-9pm; up sun from 10am-6pm; pacific time
37123712
off=[(M-F,21),(U,18)];on=[(M-F,6),(U,10)];tz=pt
37133713

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

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

40324032
:example:
40334033

4034-
.. code-block:
4034+
.. code-block:: yaml
40354035
40364036
policies:
40374037
- name: glacier-cross-account
@@ -4159,7 +4159,7 @@ Resource Type Implementations for {function.name}:
41594159

41604160
:example:
41614161

4162-
.. code-block:
4162+
.. code-block:: yaml
41634163
41644164
policies:
41654165
- name: sns-cross-account
@@ -4239,9 +4239,9 @@ This, in turn, leads to a raft of special functions required to extract the info
42394239

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

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

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

42464246
- :py:func:`c7nlib.arn_split`
42474247

@@ -4538,7 +4538,7 @@ on the resource type.
45384538
is-not-logging
45394539
--------------
45404540

4541-
See `is_logging`_.
4541+
See `is-logging`_.
45424542

45434543
Schema
45444544

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

9775-
.. code-block: json
9776-
{
9777-
'Version': '2012-10-17',
9778-
'Statement': [{
9779-
'Action': '*',
9780-
'Resource': '*',
9781-
'Effect': 'Allow'
9782-
}]
9783-
}
9775+
.. code-block:: json
9776+
9777+
{
9778+
"Version": "2012-10-17",
9779+
"Statement": [{
9780+
"Action": "*",
9781+
"Resource": "*",
9782+
"Effect": "Allow"
9783+
}]
9784+
}
97849785
97859786
Additionally, the policy checks if the statement has no 'Condition' or
97869787
'NotAction'

‎docs/source/configuration.rst‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. comment
2+
# Copyright 2020 The Cloud Custodian Authors.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
######################
6+
Configuration
7+
######################
8+
9+
The CLI application can bind argument values from the environment.
10+
The command-line provides variable names and type information.
11+
The OS environment provides string values.
12+
13+
.. code:: bash
14+
15+
export x=6
16+
export y=7
17+
celpy -n --arg x:int --arg y:int 'x*y'
18+
42
19+
20+
While this example uses the OS environment,
21+
it isn't the usual sense of *configuration*.
22+
The only configuration options available for the command-line application are the logging configuration.
23+
24+
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.
25+
26+
This file must have a ``logging`` paragraph.
27+
This paragraph can contain the parameters for logging configuration.
28+
29+
.. code:: toml
30+
31+
[logging]
32+
version = 1
33+
formatters.minimal.format = "%(message)s"
34+
formatters.console.format = "%(levelname)s:%(name)s:%(message)s"
35+
formatters.details.format = "%(levelname)s:%(name)s:%(module)s:%(lineno)d:%(message)s"
36+
root.level = "WARNING"
37+
root.handlers = ["console"]
38+
39+
[logging.handlers.console]
40+
class = "logging.StreamHandler"
41+
formatter = "console"

‎docs/source/index.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ Specifically, the intent is to be part of Cloud Custodian, C7N, as part of the s
2929
:maxdepth: 2
3030
:caption: Contents:
3131

32+
installation
3233
cli
3334
integration
35+
configuration
3436
structure
3537
api
3638
c7n_functions

‎docs/source/installation.rst‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. comment
2+
# Copyright 2020 The Cloud Custodian Authors.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
######################
6+
Installation
7+
######################
8+
9+
When using **poetry** or **uv**, add "cel-python" to the dependencies.
10+
11+
.. code-block:: bash
12+
13+
uv add cel-python
14+
15+
The optional RE2 package significantly speeds up regular expression matching.
16+
17+
.. code-block:: bash
18+
19+
uv add cel-python[re2]
20+
21+
For other tooling and virtual environment configurations, this can be installed with **PIP** commands.
22+
23+
.. code-block:: bash
24+
25+
python -m pip install cel-python
26+
27+
The optional RE2 package significantly speeds up regular expression matching.
28+
29+
.. code-block:: bash
30+
31+
python -m pip install cel-python[re2]
32+
33+
.. warning::
34+
35+
In the case where the platform is "darwin" and the architecture is "arm64" and python is "3.13",
36+
RE2 may not compile properly during installation.

‎features/expr_test_bc.feature‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ Then stdout matches '42'
4747
And stderr is ''
4848
And exit status is 0
4949

50+
Scenario: Variables provided as environment variables
51+
Given OS environment sets x to 6
52+
And OS environment sets y to 7
53+
When celpy -n --arg x:int --arg y:int 'x*y' is run
54+
Then stdout matches '42'
55+
And stderr is ''
56+
And exit status is 0
57+
5058
Scenario: Formatting integer results in hexadecimal
5159
When celpy -n -f '#8x' '0xdeadbeef' is run
5260
Then stdout matches '0xdeadbeef'

‎features/steps/cli_binding.py‎

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,22 @@ def step_impl(context, json):
3939
context.data['json'].append(json)
4040

4141

42+
@given(u'OS environment sets {name} to {value}')
43+
def step_impl(context, name, value):
44+
context.data['bindings'][name] = str(value)
45+
46+
4247
@when(u'echo document | celpy {arguments} is run')
4348
def step_impl(context, arguments):
4449
if "PYTHONPATH" in context.config.userdata:
4550
environment = {"PYTHONPATH": context.config.userdata["PYTHONPATH"]}
4651
else:
4752
environment = {}
48-
if sys.version_info.minor <= 6:
49-
extra = {}
50-
else:
51-
extra = {'text': True}
53+
environment.update(context.data['bindings'])
54+
# if sys.version_info.minor <= 6:
55+
# extra = {}
56+
# else:
57+
extra = {'text': True}
5258

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

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

7379
context.data['status'] = result.returncode
74-
if sys.version_info.minor <= 6:
75-
context.data['stdout'] = result.stdout.decode('utf-8')
76-
context.data['stderr'] = result.stderr.decode('utf-8')
77-
else:
78-
context.data['stdout'] = result.stdout
79-
context.data['stderr'] = result.stderr
80+
# if sys.version_info.minor <= 6:
81+
# context.data['stdout'] = result.stdout.decode('utf-8')
82+
# context.data['stderr'] = result.stderr.decode('utf-8')
83+
# else:
84+
context.data['stdout'] = result.stdout
85+
context.data['stderr'] = result.stderr
8086

8187
if "debug" in context.config.userdata:
8288
for line in context.data['stdout'].splitlines():
@@ -95,10 +101,11 @@ def step_impl(context, arguments):
95101
environment = {"PYTHONPATH": context.config.userdata["PYTHONPATH"]}
96102
else:
97103
environment = {}
98-
if sys.version_info.minor <= 6:
99-
extra = {}
100-
else:
101-
extra = {'text': True}
104+
environment.update(context.data['bindings'])
105+
# if sys.version_info.minor <= 6:
106+
# extra = {}
107+
# else:
108+
extra = {'text': True}
102109

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

@@ -111,12 +118,12 @@ def step_impl(context, arguments):
111118
)
112119

113120
context.data['status'] = result.returncode
114-
if sys.version_info.minor <= 6:
115-
context.data['stdout'] = result.stdout.decode('utf-8')
116-
context.data['stderr'] = result.stderr.decode('utf-8')
117-
else:
118-
context.data['stdout'] = result.stdout
119-
context.data['stderr'] = result.stderr
121+
# if sys.version_info.minor <= 6:
122+
# context.data['stdout'] = result.stdout.decode('utf-8')
123+
# context.data['stderr'] = result.stderr.decode('utf-8')
124+
# else:
125+
context.data['stdout'] = result.stdout
126+
context.data['stderr'] = result.stderr
120127

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

127134

135+
128136
@then(u'stdout matches \'{regex}\'')
129137
def step_impl(context, regex):
130138
pattern = re.compile(regex)

‎pyproject.toml‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ authors = [
2727
{ name = "S.Lott", email = "slott56@gmail.com" }
2828
]
2929
requires-python = ">=3.9"
30-
packages = [{ include = "celpy", from = "src"}]
3130

3231
dependencies = [
3332
"lark>=1.2.2",
3433
"pendulum>=3.1.0",
3534
"pyyaml>=6.0.2",
3635
"jmespath>=1.0.1",
36+
"tomli >= 1.1.0 ; python_version < '3.11'",
37+
"sphinx>=7.4.7",
3738
]
3839

3940
[project.scripts]
@@ -48,21 +49,8 @@ re2 = [
4849
requires = ["hatchling"]
4950
build-backend = "hatchling.build"
5051

51-
#[build-system]
52-
#requires = ["uv_build>=0.7.7,<0.8.0"]
53-
#build-backend = "uv_build"
54-
55-
#[build-system]
56-
#requires = ["flit"]
57-
#build-backend = "flit.api:main"
58-
59-
#[build-system]
60-
#requires = ["pdm-backend"]
61-
#build-backend = "pdm.backend"
62-
63-
#[build-system]
64-
#requires = ["setuptools", "setuptools-scm"]
65-
#build-backend = "setuptools.build_meta"
52+
[tool.hatch.build.targets.wheel]
53+
packages = ["src/celpy"]
6654

6755
[dependency-groups]
6856
dev = [

‎src/cel_python/__init__.py‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)