Skip to content

Commit

Permalink
Merge pull request #32 from yoyowallet/CLE-1611_upgrade_to_django42_p…
Browse files Browse the repository at this point in the history
…ython311_poetry

CLE-1611 upgrade to python311 and poetry
  • Loading branch information
DelboyJay authored May 2, 2023
2 parents f827cb5 + 4d0ba95 commit 15cc110
Show file tree
Hide file tree
Showing 41 changed files with 2,328 additions and 1,266 deletions.
14 changes: 8 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ version: 2

jobs:
build:
resource_class: small
docker:
- image: circleci/python:2.7
- image: cimg/python:3.11
steps:
- checkout
- run:
name: Install Dependencies
command: |
sudo pip install virtualenv
virtualenv venv
. venv/bin/activate
make deps
make clean
poetry install --no-ansi --no-interaction
- run:
name: Run Tests
command: |
. venv/bin/activate
make coverage
- store_artifacts:
path: htmlcov
- store_test_results:
path: ./test-results
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
# Taken from https://black.readthedocs.io/en/stable/compatible_configs.html#flake8

extend-ignore = E203,E501,W503,B904,B905,B907
select = B,C,E,F,W,T4,B9

# Note on line length:
# We use flake8-bugbear's B950 instead of flake8's E501. It considers "max-line-length"
# but only triggers when the value has been exceeded by more than 10%.
max-line-length = 88

max-complexity = 18
32 changes: 32 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
tests:
# https://help.github.com/articles/virtual-environments-for-github-actions
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Python 3.12 is not working yet at time of writing this.
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry install -v --no-root --with dev
- name: Test with tox
run: poetry run tox -vv
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.py[cod]
.DS_Store

# C extensions
*.so
Expand All @@ -24,7 +25,8 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
.pytest_cache
test-results/

# Translations
*.mo
Expand All @@ -37,6 +39,8 @@ nosetests.xml
# Vim
*.sw[po]
.idea/

# Virtual environments
venv*/
tests/__pycache__/
.cache/
business-rules.iml
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
args: [--config, .flake8]
additional_dependencies: [flake8-bugbear]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: forbid-new-submodules
- id: mixed-line-ending
args: [--fix=lf]
# Cannot use for now due to our factories.py files
# - id: name-tests-test
# args: [--django]
- id: no-commit-to-branch
args: [--branch=master]
- id: trailing-whitespace
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

26 changes: 26 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
History
=========

## 1.1.1

Release date: 2022-3-18

- Fix package description and long description

## 1.1.0

Release date: 2022-3-18

- Add support for Python 3.5-3.7

## 1.0.1

Release date: 2016-3-16

- Fixes a packaging bug preventing 1.0.0 from being installed on some platforms.

## 1.0.0

Release date: 2016-3-16

- Removes caching layer on rule decorator
14 changes: 0 additions & 14 deletions HISTORY.rst

This file was deleted.

20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
business-rules
==============

[![Build Status](https://travis-ci.org/venmo/business-rules.svg?branch=master)](https://travis-ci.org/venmo/business-rules)

As a software system grows in complexity and usage, it can become burdensome if
every change to the logic/behavior of the system also requires you to write and
deploy new code. The goal of this business rules engine is to provide a simple
Expand All @@ -14,10 +12,6 @@ marketing logic around when certain customers or items are eligible for a
discount or to automate emails after users enter a certain state or go through
a particular sequence of events.

<p align="center">
<img src="http://cdn.memegenerator.net/instances/400x/36514579.jpg" />
</p>

## Usage

### 1. Define Your set of variables
Expand Down Expand Up @@ -443,7 +437,15 @@ A variable can return the following types of values:
Open up a pull request, making sure to add tests for any new functionality. To set up the dev environment (assuming you're using [virtualenvwrapper](http://docs.python-guide.org/en/latest/dev/virtualenvs/#virtualenvwrapper)):

```bash
$ mkvirtualenv business-rules
$ pip install -r dev-requirements.txt
$ nosetests
$ python -m virtualenv venv
$ source ./venv/bin/activate
$ pip install -r dev-requirements.txt -e .
$ pytest
```

Alternatively, you can also use Tox:

```bash
$ pip install "tox<4"
$ tox -p auto --skip-missing-interpreters
```
4 changes: 2 additions & 2 deletions business_rules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__version__ = '1.5.0'
__version__ = "1.1.1"

from .engine import run_all, check_conditions_recursively
from .engine import check_conditions_recursively, run_all
from .utils import export_rule_data, validate_rule_data

# Appease pyflakes by "using" these exports
Expand Down
40 changes: 24 additions & 16 deletions business_rules/actions.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from __future__ import absolute_import
import inspect
from dataclasses import dataclass
from typing import Optional

from .utils import fn_name_to_pretty_label, get_valid_fields


class BaseActions(object):
""" Classes that hold a collection of actions to use with the rules
"""Classes that hold a collection of actions to use with the rules
engine should inherit from this.
"""

@classmethod
def get_all_actions(cls):
methods = inspect.getmembers(cls)
return [{
'name': m[0],
'label': m[1].label,
'params': m[1].params
} for m in methods if getattr(m[1], 'is_rule_action', False)]
return [
{'name': m[0], 'label': m[1].label, 'params': m[1].params}
for m in methods
if getattr(m[1], 'is_rule_action', False)
]


def _validate_action_parameters(func, params):
Expand All @@ -40,12 +41,18 @@ def _validate_action_parameters(func, params):
for param in params:
param_name, field_type = param['name'], param['fieldType']
if param_name not in func.__code__.co_varnames:
raise AssertionError("Unknown parameter name {0} specified for action {1}".format(
param_name, func.__name__))
raise AssertionError(
"Unknown parameter name {0} specified for action {1}".format(
param_name, func.__name__
)
)

if field_type not in valid_fields:
raise AssertionError("Unknown field type {0} specified for action {1} param {2}".format(
field_type, func.__name__, param_name))
raise AssertionError(
"Unknown field type {0} specified for action {1} param {2}".format(
field_type, func.__name__, param_name
)
)


def rule_action(label=None, params=None):
Expand Down Expand Up @@ -76,8 +83,9 @@ def wrapper(func):
label=fn_name_to_pretty_label(key),
name=key,
fieldType=getattr(value, "field_type", value),
defaultValue=getattr(value, "default_value", None)
) for key, value in params.items()
defaultValue=getattr(value, "default_value", None),
)
for key, value in params.items()
]

_validate_action_parameters(func, params_)
Expand All @@ -91,7 +99,7 @@ def wrapper(func):
return wrapper


@dataclass
class ActionParam:
def __init__(self, field_type, default_value=None):
self.field_type = field_type
self.default_value = default_value
field_type: type
default_value: Optional[int]
Loading

0 comments on commit 15cc110

Please sign in to comment.