Skip to content

Commit

Permalink
Feature/v0.4.0 (#8)
Browse files Browse the repository at this point in the history
* Adds Switch filter
* Adds pipeline state/action enums (looking into the future)
* Updates LICENSE
* Refactors protocol namespace
* Moves StepHelper to step namespace
* Moves Pipeline and Switch to sep modules

Co-authored-by: a-e-benson
  • Loading branch information
greater-than committed Feb 6, 2021
1 parent 0e6ac18 commit 273e66a
Show file tree
Hide file tree
Showing 41 changed files with 812 additions and 437 deletions.
21 changes: 16 additions & 5 deletions HISTORY.md
@@ -1,6 +1,17 @@
# PipeLayer: Version History

## 0.3.1 - 1/31/21
## 0.4.0
* Adds Switch filter
* Adds protocols:
* `pipelayer.protocol.CompoundStep`
* `pipelayer.protocol.Filter`
* `pipelayer.protocol.Manifest`
* Moves `Step` protocol to the `piplayer.protocol` namespace
* Moves `Pipeline` into separate module
* Exposes all core classes in root `__init__.py`
* Updates LICENSE to Free BSD (previous versions still honor the MIT License)

## 0.3.1 - 2/1/21
* Adds support for classes that implement the `pipelayer.Step` protocol as steps
* `pipelayer.Step` is now a Protocol
* `pipelater.Pipeline` and `pipelayer.Filter` implement the `pipelayer.Step` protocol
Expand All @@ -17,13 +28,13 @@ BREAKING CHANGES:
* Adds support for `pipelayer.Pipeline` instances as steps
* `pipelayer.Pipeline` removes factory method, and implements a constructor that takes `steps` and `name` as args
* `pipelayer.Pipeline.run` and `pipelayer.Filter.run` method signatures updated.
* Removed `pipelayer.Settings` base class
* Removed `settings` and `log` attributes from the `pipelayer.Context` class
* Removed `pipelayer.exception.PipelineException`
* Removes `pipelayer.Settings` base class
* Removes `settings` and `log` attributes from the `pipelayer.Context` class
* Removes `pipelayer.exception.PipelineException`

## 0.2.0 - 1/22/21
* Adds support for static/module/lamba functions as well as `pipelayer.Filter` types as Pipeline Filters
* Basic signature validation for filter functions
* Adds Basic signature validation for filter functions
* context property in `pipelayer.Filter` is typed as `Union[Context]`
* Handles all exceptions raises by filters and raises a `PipelineException` with the original exception assigned to the `inner_exception` property

Expand Down
35 changes: 19 additions & 16 deletions LICENSE
@@ -1,21 +1,24 @@
The MIT License (MIT)
FreeBSD License

Copyright (c) 2021 GreaterThan, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
49 changes: 34 additions & 15 deletions README.md
Expand Up @@ -87,6 +87,7 @@ run app.py

## The Framework
* [Pipeline](#pipeline)
* [Switch](#switch)
* [Filter](#filter)
* [Context](#context)
* [Manifest](#manifest)
Expand Down Expand Up @@ -124,6 +125,12 @@ A list of:

***Properties:***

__`name: str`__<br>

__`state: Pipeline.State`__<br>

__`steps: List[Union[Step, Callable[[Any, Context], Any]]]`__<br>

__`manifest: Manifest`__<br>
An instance of [`pipelayer.Manifest`](#manifest) that is created when the run method is called.

Expand All @@ -139,44 +146,56 @@ The pipeline runner that iterates through the `steps` and pipes filter output to
<br><br>


<div id="filter"></div>
<div id="switch"></div>

### __`pipelayer.Filter`__
___`__init__(name, pre_process, post_process)`___
### __`pipelayer.Switch`__
___`__init__(expression, cases, name)`___<br>
An implementation of a Switch statement as a pipeline filter

*args:*
- `expression: Union[Step, Callable[[Any, Context], Any]]`
- `cases: Dict[Union[Step, Callable[[Any, Context], Any]]]`
- `name: Optional[str]`<br>
If not specified, the class name will be used.
- `pre_process: Optional[Callable[[Any, Context], Any]`
- `post_process: Optional[Callable[[Any, Context], Any]`


***Properties:***

__`pre_process: Optional[Callable[[Any, Context], Any]`__<br>
__`post_process: Optional[Callable[[Any, Context], Any]`__
<br><br>
__`expression: Union[Step, Callable[[Any, Context], Any]]`__<br>
__`cases: Dict[Union[Step, Callable[[Any, Context], Any]]]`__<br>
__`name: Optional[str]`__<br>
__`manifest: Manifest`__

***Methods:***

<div id="step"></div>
__`run(data, context) -> Any`__<br>
The switch runner that evaluates the specified expresssion executes the matching case.
<br><br>

### __`pipelayer.Step(Protocol)`__

***Methods:***
<div id="filter"></div>

__`run(data, context) -> Any`__<br>
### __`pipelayer.Filter`__
___`__init__(name, pre_process, post_process)`___

*args:*
- `name: Optional[str]`<br>
If not specified, the class name will be used.
- `pre_process: Optional[Callable[[Any, Context], Any]`
- `post_process: Optional[Callable[[Any, Context], Any]`

- `data: Any`
- `context: pipelayer.Context`

***Properties:***

__`pre_process: Optional[Callable[[Any, Context], Any]`__<br>
__`post_process: Optional[Callable[[Any, Context], Any]`__
<br><br>


<div id="context"></div>

### __`pipelayer.Context`__
A abstract base class for runtime app config.
A abstract base class for runtime app data.
<br><br>


Expand Down
48 changes: 12 additions & 36 deletions examples/pipelayer_microservice/scripts/_lib.ps1
Expand Up @@ -259,9 +259,13 @@ function Clean_Project {
}

function Run_Unit_Tests {
param(
[string] $markers
)
if ($markers) { $markers = "unit and $markers" } else { $markers = "unit" }
try {
Write_Banner "Run Unit Tests"
$arguments = "-m pytest -m unit --nunit-xml=.test_results/unit-test-results.xml --cov=src --cov-config=pyproject.toml"
$arguments = "-m pytest -m ""$markers"" --nunit-xml=.test_results/unit-test-results.xml --cov=src --cov-config=pyproject.toml"
Execute_Command "python" $arguments
}
catch {
Expand All @@ -272,9 +276,13 @@ function Run_Unit_Tests {
}

function Run_Integration_Tests {
param(
[string] $markers
)
if ($markers) { $markers = "integration and $markers" } else { $markers = "integration" }
try {
Write_Banner "Run Unit Tests"
$arguments = "-m pytest -m integration --nunit-xml=.test_results/integration-test-results.xml"
Write_Banner "Run Integration Tests"
$arguments = "-m pytest -m ""$markers"" --nunit-xml=.test_results/integration-test-results.xml"
Execute_Command "python" $arguments
}
catch {
Expand All @@ -284,46 +292,14 @@ function Run_Integration_Tests {
}
}

function Create_Package {
try {
Write_Banner "Create Package"
$arguments = "./setup.py sdist bdist_wheel"
Execute_Command "python" $arguments
}
catch {
Write-Host "*** Create Package Failed ***"
Write-Host "##vso[task.complete result=failed]"
throw
}
}

function Publish_Package {
param(
[string] $isPyPi = $false
)
$server = "testpypi"
if ($isPyPi) {
$server = "pypi"
}
try {
Write_Header "Publish Package"
$arguments = "upload --repository $server dist/*"
Execute_Command "twine" $arguments
}
catch {
Write-Host "*** Publish Package Failed ***"
Write-Host "##vso[task.complete result=failed]"
throw
}
}
function Run_App {
try {
Write_Banner "Run Application"
$arguments = "src/app/app.py"
Execute_Command "python" $arguments
}
catch {
Write-Host "*** Run Integration Tests Failed ***"
Write-Host "*** Run Application Tests Failed ***"
Write-Host "##vso[task.complete result=failed]"
throw
}
Expand Down
11 changes: 0 additions & 11 deletions examples/pipelayer_microservice/scripts/package.ps1

This file was deleted.

4 changes: 0 additions & 4 deletions examples/pipelayer_microservice/scripts/publish.ps1

This file was deleted.

6 changes: 5 additions & 1 deletion examples/pipelayer_microservice/scripts/test-integration.ps1
@@ -1,3 +1,7 @@
param(
[parameter(Mandatory = $false)][string] $markers
)

. .\scripts\_lib.ps1

Run_Integration_Tests
Run_Integration_Tests $markers
6 changes: 5 additions & 1 deletion examples/pipelayer_microservice/scripts/test-unit.ps1
@@ -1,3 +1,7 @@
param(
[parameter(Mandatory = $false)][string] $markers
)

. .\scripts\_lib.ps1

Run_Unit_Tests
Run_Unit_Tests $markers
4 changes: 2 additions & 2 deletions examples/pipelayer_microservice/src/requirements.txt
@@ -1,5 +1,5 @@
flask
connexion[swagger-ui]
pipelayer~=0.3.0
stringbender~=0.2.0
pipelayer
stringbender
requests
Expand Up @@ -2,7 +2,6 @@
from typing import Any

from pipelayer import Context

from service.config.app_settings import AppSettings


Expand Down
Expand Up @@ -4,15 +4,9 @@
from stringbender import camel


def to_camel(s: str) -> str:
return camel(s)


# TODO Add a json encoder to convert model fields to camelCase

class DomainModelConfig:
allow_population_by_field_name: bool = True
alias_generator: Callable = to_camel
alias_generator: Callable = camel


class DomainModel(BaseModel):
Expand Down
@@ -1,7 +1,6 @@
from typing import Union

from pipelayer.manifest import Manifest

from service.model.domain_model import DomainModel, DomainModelList


Expand Down
1 change: 0 additions & 1 deletion examples/simple_pipelayer/requirements.txt
Expand Up @@ -13,5 +13,4 @@ pytest-mock
pytest-nunit
coverage[toml]

poetry
pre-commit
14 changes: 11 additions & 3 deletions examples/simple_pipelayer/scripts/_lib.ps1
Expand Up @@ -237,9 +237,13 @@ function Clean_Project {
}

function Run_Unit_Tests {
param(
[string] $markers
)
if ($markers) { $markers = "unit and $markers" } else { $markers = "unit" }
try {
Write_Banner "Run Unit Tests"
$arguments = "-m pytest -m unit --nunit-xml=.test_results/unit-test-results.xml"
$arguments = "-m pytest -m ""$markers"" --nunit-xml=.test_results/unit-test-results.xml --cov=src --cov-config=pyproject.toml"
Execute_Command "python" $arguments
}
catch {
Expand All @@ -250,9 +254,13 @@ function Run_Unit_Tests {
}

function Run_Integration_Tests {
param(
[string] $markers
)
if ($markers) { $markers = "integration and $markers" } else { $markers = "integration" }
try {
Write_Banner "Run Unit Tests"
$arguments = "-m pytest -m integration --nunit-xml=.test_results/integration-test-results.xml"
Write_Banner "Run Integration Tests"
$arguments = "-m pytest -m ""$markers"" --nunit-xml=.test_results/integration-test-results.xml"
Execute_Command "python" $arguments
}
catch {
Expand Down
6 changes: 5 additions & 1 deletion examples/simple_pipelayer/scripts/test-integration.ps1
@@ -1,3 +1,7 @@
param(
[parameter(Mandatory = $false)][string] $markers
)

. .\scripts\_lib.ps1

Run_Integration_Tests
Run_Integration_Tests $markers
6 changes: 5 additions & 1 deletion examples/simple_pipelayer/scripts/test-unit.ps1
@@ -1,3 +1,7 @@
param(
[parameter(Mandatory = $false)][string] $markers
)

. .\scripts\_lib.ps1

Run_Unit_Tests
Run_Unit_Tests $markers
4 changes: 2 additions & 2 deletions examples/simple_pipelayer/src/requirements.txt
@@ -1,2 +1,2 @@
pipelayer~=0.3.0
stringbender~=0.2.0
pipelayer
stringbender

0 comments on commit 273e66a

Please sign in to comment.