From e81ae6f22bd875cfa30a9e7be425ebc6916e1504 Mon Sep 17 00:00:00 2001 From: develop-cs <43383361+develop-cs@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:10:31 +0200 Subject: [PATCH 1/2] docs: fix simple example (#33) Signed-off-by: develop-cs <43383361+develop-cs@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/bug_report.md | 13 +++---- .github/ISSUE_TEMPLATE/feature_request.md | 9 ++--- .github/PULL_REQUEST_TEMPLATE.md | 8 ++-- .pre-commit-config.yaml | 20 +++++----- CHANGELOG.md | 5 +-- README.md | 10 ++++- docs/pages/a_simple_example.md | 13 ++++--- docs/pages/index.html | 7 ++-- pyproject.toml | 5 +-- .../default/rules_simple_cond.yaml | 0 .../ignore/rules_simple_cond_ignore.yaml | 0 .../rules_simple_cond_ignored_rules.yaml | 0 .../math/rules_simpl_cond_math.yaml | 0 .../raise/rules_simple_cond_raise.yaml | 0 .../rules_simple_cond_uppercase.yaml | 9 ++++- .../rules_simple_cond_whitespace.yaml | 0 .../dummy/ignore/rules_simple_dummy.yaml | 0 .../ignore/rules_simple_wrong_ignore.yaml | 0 .../wrong/raise/rules_simple_wrong_raise.yaml | 0 tests/unit/test_simple_condition.py | 38 +++++++++---------- 20 files changed, 74 insertions(+), 63 deletions(-) rename tests/examples/{simple_cond_conf => simple_condition}/default/rules_simple_cond.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/ignore/rules_simple_cond_ignore.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/ignored_rules/rules_simple_cond_ignored_rules.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/math/rules_simpl_cond_math.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/raise/rules_simple_cond_raise.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/uppercase/rules_simple_cond_uppercase.yaml (78%) rename tests/examples/{simple_cond_conf => simple_condition}/whitespace/rules_simple_cond_whitespace.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/wrong/dummy/ignore/rules_simple_dummy.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/wrong/ignore/rules_simple_wrong_ignore.yaml (100%) rename tests/examples/{simple_cond_conf => simple_condition}/wrong/raise/rules_simple_wrong_raise.yaml (100%) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 9e8de8c..e65b54c 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -4,28 +4,27 @@ about: Create a report to help us improve title: '' labels: bug assignees: '' - --- -**Describe the bug**: +### Describe the bug A clear and concise description of what the bug is. -**To Reproduce**: +### To Reproduce Steps to reproduce the behavior: 1. Import '...' 2. Call '....' 3. See error -**Expected behavior**: +### Expected behavior A clear and concise description of what you expected to happen. -**Screenshots**: +### Screenshots If applicable, add screenshots to help explain your problem. -**Desktop (please complete the following information):** +### Desktop (please complete the following information) - OS: `[e.g. linux]` - Python version(s): `[e.g. 3.12]` - Dependencies versions: `[e.g. pydantic 2.6.4]` -**Additional context**: +### Additional context Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index a52670b..33baf3e 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -4,17 +4,16 @@ about: Suggest an idea for this project title: '' labels: enhancement assignees: '' - --- -**Is your feature request related to a problem? Please describe**: +### Is your feature request related to a problem? Please describe A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -**Describe the solution you'd like**: +### Describe the solution you'd like A clear and concise description of what you want to happen. -**Describe alternatives you've considered**: +### Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. -**Additional context**: +### Additional context Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3d211a8..bab67e6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,14 +1,14 @@ -## What? +### What? Explain with one or more sentences what this change is doing. -## Have you done? +### Have you done? - [ ] Code tests - [ ] Update documentation - [ ] Update [changelog](https://github.com/MAIF/arta/blob/main/CHANGELOG.md) -## Details to be checked: (optional) +### Details to be checked: (optional) If needed, add some details here in order to verify the change (e.g., how to test). -## Linked issues: (optional) +### Linked issues: (optional) - Close ... - Close ... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 616524f..d12ede3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,23 +16,23 @@ repos: - id: end-of-file-fixer exclude: ^(docs/) - id: pretty-format-json - args: ['--autofix'] + args: [--autofix] - id: trailing-whitespace - args: ['--markdown-linebreak-ext=md'] + args: [--markdown-linebreak-ext=md] exclude: ^(docs/) - id: mixed-line-ending - args: ['--fix=lf'] + args: [--fix=lf] exclude: ^(docs/) - id: check-added-large-files - args: ['--maxkb=500'] + args: [--maxkb=500] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.4 + rev: v0.6.3 hooks: - id: ruff - args: [ --fix ] + args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.0 + rev: v1.11.2 hooks: - id: mypy args: [--config-file=pyproject.toml] @@ -46,9 +46,9 @@ repos: rev: v2.7.3 hooks: - id: pip-audit - args: ["--skip-editable"] + args: [--skip-editable] - repo: https://github.com/compilerla/conventional-pre-commit - rev: v3.3.0 + rev: v3.4.0 hooks: - id: conventional-pre-commit stages: [commit-msg] @@ -65,6 +65,6 @@ repos: name: Coverage language: system entry: pytest -v --cov=arta --cov-fail-under=90 - types: [ python ] + types: [python] pass_filenames: false always_run: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 5be35df..85fd54e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - +## [0.8.1] - September, 2024 ### Fixes -* *Simple condition:* an error occurs when the field is of type camelcase or pascalcase (e.g., `input.streetNumber`, `input.StreetNumber`). - +* *Simple condition:* an error occurs (#31) when the field is of type `camelCase` or `PascalCase` (e.g., `input.streetNumber`, `input.StreetNumber`). ## [0.8.0] - July, 2024 diff --git a/README.md b/README.md index 017c9f7..4638de5 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ## Overview -**Arta** is a simple python rules engine designed for python developers. +**Arta** is an *open source* python rules engine designed for and by python developers. ### Goal @@ -113,7 +113,13 @@ Check the [A Simple Example](https://maif.github.io/arta/a_simple_example/) sect ## Installation -Install using `pip install -U arta`. See the [Install](https://maif.github.io/arta/installation/) section in the documentation for more details. +Install using `pip install -U`: + +```shell +pip install -U arta +``` + +See the [Install](https://maif.github.io/arta/installation/) section in the documentation for more details. ## What's New diff --git a/docs/pages/a_simple_example.md b/docs/pages/a_simple_example.md index cab7f1e..ea00133 100644 --- a/docs/pages/a_simple_example.md +++ b/docs/pages/a_simple_example.md @@ -15,7 +15,7 @@ Imagine the following use case: The rules (intentionally simple) are: -``` mermaid +```mermaid --- title: Simple rule set example --- @@ -69,17 +69,17 @@ rules: simple_condition: input.language=="french" and input.age!=None action: set_course action_parameters: - value: french + course_id: french SENIOR: simple_condition: input.age==None action: set_course action_parameters: - value: senior + course_id: senior INTERNATIONAL: simple_condition: input.language!="french" action: set_course action_parameters: - value: international + course_id: international favorite_meal: EMAIL: simple_condition: input.favorite_meal!=None @@ -124,6 +124,9 @@ actions_source_modules: And could be for example (intentionally simple) in `actions.py`: ```python +from typing import Any + + def set_admission(value: bool, **kwargs: Any) -> dict[str, bool]: """Return a dictionary containing the admission result.""" return {"is_admitted": value} @@ -134,7 +137,7 @@ def set_course(course_id: str, **kwargs: Any) -> dict[str, str]: return {"course_id": course_id} -def send_email(mail_to: str, mail_content: str, meal: str, **kwargs: Any) -> bool: +def send_email(mail_to: str, mail_content: str, meal: str, **kwargs: Any) -> str | None: """Send an email.""" result: str | None = None diff --git a/docs/pages/index.html b/docs/pages/index.html index 8e32f50..15ccf98 100644 --- a/docs/pages/index.html +++ b/docs/pages/index.html @@ -49,12 +49,13 @@
- Arta is a simple python rules engine designed for python developers. + Arta is an open source python rules engine designed for and by python developers. There is one main reason to use Arta and it was the main goal of its development at MAIF: increase business rules maintainability. diff --git a/pyproject.toml b/pyproject.toml index 1485fcf..cc6b949 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta" [project] name = "arta" -version = "0.8.0" +version = "0.8.1" requires-python = ">3.8.0" -description = "An Open Source Rules Engine - Make rule handling simple" +description = "A Python Rules Engine - Make rule handling simple" readme = "README.md" license = {text = "Apache-2.0"} authors = [ @@ -34,7 +34,6 @@ classifiers = [ dependencies = [ "omegaconf>=2.0.0", "pydantic>=1.0.0", - "urllib3!=2.2.1", ] [project.urls] diff --git a/tests/examples/simple_cond_conf/default/rules_simple_cond.yaml b/tests/examples/simple_condition/default/rules_simple_cond.yaml similarity index 100% rename from tests/examples/simple_cond_conf/default/rules_simple_cond.yaml rename to tests/examples/simple_condition/default/rules_simple_cond.yaml diff --git a/tests/examples/simple_cond_conf/ignore/rules_simple_cond_ignore.yaml b/tests/examples/simple_condition/ignore/rules_simple_cond_ignore.yaml similarity index 100% rename from tests/examples/simple_cond_conf/ignore/rules_simple_cond_ignore.yaml rename to tests/examples/simple_condition/ignore/rules_simple_cond_ignore.yaml diff --git a/tests/examples/simple_cond_conf/ignored_rules/rules_simple_cond_ignored_rules.yaml b/tests/examples/simple_condition/ignored_rules/rules_simple_cond_ignored_rules.yaml similarity index 100% rename from tests/examples/simple_cond_conf/ignored_rules/rules_simple_cond_ignored_rules.yaml rename to tests/examples/simple_condition/ignored_rules/rules_simple_cond_ignored_rules.yaml diff --git a/tests/examples/simple_cond_conf/math/rules_simpl_cond_math.yaml b/tests/examples/simple_condition/math/rules_simpl_cond_math.yaml similarity index 100% rename from tests/examples/simple_cond_conf/math/rules_simpl_cond_math.yaml rename to tests/examples/simple_condition/math/rules_simpl_cond_math.yaml diff --git a/tests/examples/simple_cond_conf/raise/rules_simple_cond_raise.yaml b/tests/examples/simple_condition/raise/rules_simple_cond_raise.yaml similarity index 100% rename from tests/examples/simple_cond_conf/raise/rules_simple_cond_raise.yaml rename to tests/examples/simple_condition/raise/rules_simple_cond_raise.yaml diff --git a/tests/examples/simple_cond_conf/uppercase/rules_simple_cond_uppercase.yaml b/tests/examples/simple_condition/uppercase/rules_simple_cond_uppercase.yaml similarity index 78% rename from tests/examples/simple_cond_conf/uppercase/rules_simple_cond_uppercase.yaml rename to tests/examples/simple_condition/uppercase/rules_simple_cond_uppercase.yaml index af8f18c..ddf4458 100644 --- a/tests/examples/simple_cond_conf/uppercase/rules_simple_cond_uppercase.yaml +++ b/tests/examples/simple_condition/uppercase/rules_simple_cond_uppercase.yaml @@ -13,10 +13,15 @@ rules: action_parameters: list_str: - OK - camelCase : + camelcase: RULE_1: - simple_condition: input.streetNumber>0 and input.streetName!="" and input.postalCode >0 + simple_condition: input.streetNumber>0 and input.streetName!="" and input.PostalCode>0 action: concatenate_str action_parameters: list_str: - OK + RULE_2: + action: concatenate_str + action_parameters: + list_str: + - KO diff --git a/tests/examples/simple_cond_conf/whitespace/rules_simple_cond_whitespace.yaml b/tests/examples/simple_condition/whitespace/rules_simple_cond_whitespace.yaml similarity index 100% rename from tests/examples/simple_cond_conf/whitespace/rules_simple_cond_whitespace.yaml rename to tests/examples/simple_condition/whitespace/rules_simple_cond_whitespace.yaml diff --git a/tests/examples/simple_cond_conf/wrong/dummy/ignore/rules_simple_dummy.yaml b/tests/examples/simple_condition/wrong/dummy/ignore/rules_simple_dummy.yaml similarity index 100% rename from tests/examples/simple_cond_conf/wrong/dummy/ignore/rules_simple_dummy.yaml rename to tests/examples/simple_condition/wrong/dummy/ignore/rules_simple_dummy.yaml diff --git a/tests/examples/simple_cond_conf/wrong/ignore/rules_simple_wrong_ignore.yaml b/tests/examples/simple_condition/wrong/ignore/rules_simple_wrong_ignore.yaml similarity index 100% rename from tests/examples/simple_cond_conf/wrong/ignore/rules_simple_wrong_ignore.yaml rename to tests/examples/simple_condition/wrong/ignore/rules_simple_wrong_ignore.yaml diff --git a/tests/examples/simple_cond_conf/wrong/raise/rules_simple_wrong_raise.yaml b/tests/examples/simple_condition/wrong/raise/rules_simple_wrong_raise.yaml similarity index 100% rename from tests/examples/simple_cond_conf/wrong/raise/rules_simple_wrong_raise.yaml rename to tests/examples/simple_condition/wrong/raise/rules_simple_wrong_raise.yaml diff --git a/tests/unit/test_simple_condition.py b/tests/unit/test_simple_condition.py index 68826a7..01957c4 100644 --- a/tests/unit/test_simple_condition.py +++ b/tests/unit/test_simple_condition.py @@ -17,7 +17,7 @@ "power": "strength", "favorite_meal": "Spinach", }, - "simple_cond_conf/default", + "simple_condition/default", None, { "admission": {"admission": True}, @@ -32,7 +32,7 @@ "power": "fly", "favorite_meal": None, }, - "simple_cond_conf/default", + "simple_condition/default", None, { "admission": {"admission": True}, @@ -47,7 +47,7 @@ "power": "invisibility", "favorite_meal": "French Fries", }, - "simple_cond_conf/default", + "simple_condition/default", None, { "admission": {"admission": False}, @@ -57,13 +57,13 @@ ), ( {"dummy": 100, "language": "french", "power": "strength", "favorite_meal": "Spinach"}, - "simple_cond_conf/ignore", + "simple_condition/ignore", None, {"admission": {"admission": True}, "course": {"course_id": "senior"}, "email": True}, ), ( {"age": 100, "language": "french", "power": "strength", "favorite_meal": "Spinach"}, - "simple_cond_conf/wrong/ignore", + "simple_condition/wrong/ignore", None, {"admission": {"admission": True}, "course": {"course_id": "senior"}, "email": True}, ), @@ -71,25 +71,25 @@ { "text": "super hero super hero", }, - "simple_cond_conf/whitespace", + "simple_condition/whitespace", None, {"whitespace": "OK"}, ), ( - {"text": "SUPER HERO", "streetNumber": 15, "streetName": "rue des Es", "postalCode": 89000}, - "simple_cond_conf/uppercase", + {"text": "SUPER HERO", "streetNumber": 15, "streetName": "rue des Es", "PostalCode": 89000}, + "simple_condition/uppercase", None, - {"uppercase": "OK", "camelCase": "OK"}, + {"uppercase": "OK", "camelcase": "OK"}, ), ( - {"text": "SUPER HERO", "streetNumber": 0, "streetName": "", "postalCode": 0}, - "simple_cond_conf/uppercase", + {"text": "SUPER HERO", "streetNumber": 0, "streetName": "rue des Es", "PostalCode": 0}, + "simple_condition/uppercase", set(), - {"uppercase": "OK", "camelCase": None}, + {"uppercase": "OK", "camelcase": "KO"}, ), ( {"age": 100, "power": "strength"}, - "simple_cond_conf/ignored_rules", + "simple_condition/ignored_rules", {"IGNORED_RULE_1", "IGNORED_RULE_2"}, {"admission": {"admission": False}}, ), @@ -174,7 +174,7 @@ def test_simple_condition(input_data, config_dir, ignored_rules, good_results, b ) def test_simple_condition_verbose(input_data, good_results, base_config_path): """Unit test of the method RulesEngine.apply_rules()""" - config_path = os.path.join(base_config_path, "simple_cond_conf/default") + config_path = os.path.join(base_config_path, "simple_condition/default") eng = RulesEngine(config_path=config_path) res = eng.apply_rules(input_data=input_data, verbose=True) assert res == good_results @@ -190,7 +190,7 @@ def test_simple_condition_verbose(input_data, good_results, base_config_path): "power": "strength", "favorite_meal": "Spinach", }, - "simple_cond_conf/default", + "simple_condition/default", ConditionExecutionError, ), ( @@ -200,7 +200,7 @@ def test_simple_condition_verbose(input_data, good_results, base_config_path): "power": "strength", "favorite_meal": "Spinach", }, - "simple_cond_conf/raise", + "simple_condition/raise", ConditionExecutionError, ), ( @@ -210,7 +210,7 @@ def test_simple_condition_verbose(input_data, good_results, base_config_path): "power": "strength", "favorite_meal": "Spinach", }, - "simple_cond_conf/wrong/dummy", + "simple_condition/wrong/dummy", RuleExecutionError, ), ( @@ -220,7 +220,7 @@ def test_simple_condition_verbose(input_data, good_results, base_config_path): "power": "strength", "favorite_meal": "Spinach", }, - "simple_cond_conf/wrong/raise", + "simple_condition/wrong/raise", ConditionExecutionError, ), ], @@ -244,7 +244,7 @@ def test_error_apply_rules_missing_input_key(input_data, config_dir, expected_er "b": 0.7, "threshold": 0.89, }, - "simple_cond_conf/math", + "simple_condition/math", { "add": "greater than threshold", "sub": "less or equal than threshold", From 3fcaaf1c9c3347b2c238385019bdbe036de4985e Mon Sep 17 00:00:00 2001 From: develop-cs <43383361+develop-cs@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:18:23 +0200 Subject: [PATCH 2/2] docs: update changelog Signed-off-by: develop-cs <43383361+develop-cs@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85fd54e..21c91ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), * *Simple condition:* an error occurs (#31) when the field is of type `camelCase` or `PascalCase` (e.g., `input.streetNumber`, `input.StreetNumber`). +### Documentation + +* Fixes of code in the [A Simple Example](https://maif.github.io/arta/a_simple_example/) page. + ## [0.8.0] - July, 2024 ### Features