-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
1,708 additions
and
1,892 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: publish_wf | ||
|
||
on: push | ||
|
||
jobs: | ||
build-n-publish: | ||
name: Build and publish Python distributions to PyPI and TestPyPI | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Set up Python 3.6 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.6 | ||
- name: Download poetry | ||
run: | | ||
curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py -o get-poetry.py | ||
- name: Install poetry | ||
run: >- | ||
python get-poetry.py --preview --version 1.0.0a5 | ||
- name: Install pkg in dev mode | ||
run: | | ||
source $HOME/.poetry/env | ||
mkdir -p $HOME/.config/pypoetry/ | ||
poetry config repositories.testpypi https://test.pypi.org/simple | ||
poetry config settings.virtualenvs.create false | ||
poetry install | ||
- name: format code | ||
run: | | ||
autopep8 petri | ||
isort -rc --atomic petri | ||
black --config tox.ini petri | ||
docformatter --in-place --recursive --wrap-summaries 0 --blank petri | ||
autopep8 tests | ||
black --config tox.ini tests | ||
isort -rc --atomic tests | ||
- name: lint code | ||
run: | | ||
flake8 --config=tox.ini petri | ||
pylint --rcfile=tox.ini petri | ||
mypy --config-file=tox.ini -p petri | ||
bandit --ini=tox.ini --quiet --recursive petri | ||
flake8 --config=tox.ini tests | ||
pylint --rcfile=tox.ini --disable=C011,C0114,C0116,R0913,W0212,C0415,W0621,W0611 tests | ||
mypy --config-file=tox.ini -p tests | ||
bandit --ini=tox.ini --quiet --recursive tests | ||
- name: test code | ||
run: | | ||
source $HOME/.poetry/env | ||
poetry add tests/fixtures/a_pkg | ||
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter | ||
chmod +x ./cc-test-reporter | ||
./cc-test-reporter before-build | ||
pytest tests/unit | ||
coverage xml | ||
./cc-test-reporter after-build | ||
poetry remove a-pkg | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.code_climate_id }} | ||
- name: Build a binary wheel and a source tarball | ||
run: | | ||
source $HOME/.poetry/env | ||
poetry build | ||
- name: Publish to test PyPI | ||
run: | | ||
source $HOME/.poetry/env | ||
poetry publish --repository testpypi --username __token__ --password $password | ||
env: | ||
password: ${{ secrets.test_pypi_gh_action_push_pkg }} | ||
repo: testpypi | ||
- name: Publish to PyPI | ||
if: contains( github.ref, 'tag' ) | ||
run: | | ||
source $HOME/.poetry/env | ||
poetry publish --username __token__ --password $password | ||
env: | ||
password: ${{ secrets.pypi_github }} | ||
# # - name: Publish distribution to Test PyPI | ||
# # env: | ||
# # test_pypi_password: ${{ secrets.test_pypi_password }} | ||
# # run: | ||
# # poetry publish --repository https://test.pypi.org/legacy/ --username pwoolvett | ||
# # - name: Publish distribution to PyPI | ||
# # if: startsWith(github.event.ref, 'refs/tags') | ||
# # with: | ||
# # username: pwoolvett | ||
# # password: ${{ secrets.pypi_password }} | ||
# # run: | ||
# # poetry publish \ | ||
# # --username ${{ username }} \ | ||
# # --password ${{ password }} |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,113 @@ | ||
.. image:: https://travis-ci.org/pwoolvett/petri.svg?branch=master | ||
:target: https://travis-ci.org/pwoolvett/petri | ||
:alt: Build Status | ||
===== | ||
PETRI | ||
===== | ||
|
||
petri: free your python code from 12-factor boilerplate. | ||
-------------------------------------------------------- | ||
|
||
.. list-table:: | ||
:widths: 50 50 | ||
:header-rows: 0 | ||
|
||
* - Python Version | ||
- .. image:: https://img.shields.io/pypi/pyversions/petri | ||
:target: https://www.python.org/downloads/ | ||
:alt: Python Version | ||
* - Code Style | ||
- .. image:: https://img.shields.io/badge/code%20style-black-000000.svg | ||
:target: https://github.com/ambv/black | ||
:alt: Code Style | ||
* - Release | ||
- .. image:: https://img.shields.io/pypi/v/petri | ||
:target: https://pypi.org/project/petri/ | ||
:alt: PyPI | ||
* - Build Status | ||
- .. image:: https://github.com/pwoolvett/petri/workflows/publish_wf/badge.svg | ||
:target: https://github.com/pwoolvett/petri/actions | ||
:alt: Build Status | ||
* - Docs | ||
- .. image:: https://readthedocs.org/projects/petri/badge/?version=latest | ||
:target: https://petri.readthedocs.io/en/latest/?badge=latest | ||
:alt: Documentation Status | ||
* - Maintainability | ||
- .. image:: https://api.codeclimate.com/v1/badges/4a883c99f3705d3390ee/maintainability | ||
:target: https://codeclimate.com/github/pwoolvett/petri/maintainability | ||
:alt: Maintainability | ||
* - License | ||
- .. image:: https://img.shields.io/pypi/l/petri | ||
:alt: PyPI - License | ||
* - Coverage | ||
- .. image:: https://api.codeclimate.com/v1/badges/4a883c99f3705d3390ee/test_coverage | ||
:target: https://codeclimate.com/github/pwoolvett/petri/test_coverage | ||
:alt: Test Coverage | ||
* - Downloads | ||
- .. image:: https://img.shields.io/pypi/dm/petri | ||
:alt: PyPI - Downloads | ||
* - Deps | ||
- .. image:: https://img.shields.io/librariesio/github/pwoolvett/petri | ||
:alt: Libraries.io dependency status for GitHub repo | ||
|
||
.. image:: https://readthedocs.org/projects/petri/badge/?version=latest | ||
:target: https://petri.readthedocs.io/en/latest/?badge=latest | ||
:alt: Documentation Status | ||
|
||
.. image:: https://api.codeclimate.com/v1/badges/f0f976249fae332a0bab/test_coverage | ||
:target: https://codeclimate.com/github/pwoolvett/petri/test_coverage | ||
:alt: Test Coverage | ||
|
||
|
||
.. image:: https://api.codeclimate.com/v1/badges/f0f976249fae332a0bab/maintainability | ||
:target: https://codeclimate.com/github/pwoolvett/petri/maintainability | ||
:alt: Maintainability | ||
|
||
.. image:: https://img.shields.io/badge/python%20version-3.6.7-275479.svg | ||
:target: https://img.shields.io/badge/python%20version-3.6.7-275479.svg | ||
:alt: Python Version | ||
|
||
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg | ||
:target: https://img.shields.io/badge/code%20style-black-000000.svg | ||
:alt: Code Style | ||
|
||
------------ | ||
|
||
Summary | ||
------- | ||
Avoid boilerplate python code. | ||
|
||
Importing petri automagically equips your script/pacakage with: | ||
|
||
* settings using pydantic. | ||
* dotenv file handling using python-dotenv. | ||
* logging config using logzero&autologging. | ||
* project metadata from a pyproject.toml file. | ||
* environment (prod/dev/test) handling via ENV environment variable. | ||
|
||
Screenshots | ||
----------- | ||
Importing petri equips your app/pacakage with: | ||
|
||
.. image:: static/screenshots/api.png | ||
* Dotenv file handling using python-dotenv. | ||
* Package metadata (for installed packages), using importlib_metadata. | ||
* Settings using pydantic. | ||
* Logging config using structlog. | ||
* Environment switching (prod/dev/test) handling via ENV environment variable. | ||
|
||
Install | ||
------- | ||
|
||
Code Example | ||
------------ | ||
Install using `poetry` or `pip`: | ||
|
||
* see tests/data folder | ||
- Poetry:: | ||
|
||
poetry add petri | ||
|
||
Requirements | ||
------------ | ||
- pip:: | ||
|
||
- Usage requirements | ||
pip install petri | ||
|
||
+ python>=3.6 | ||
Usage | ||
----- | ||
|
||
- Development requirements | ||
- [OPTIONAL] Define an environment variable named `env_file`, to feed | ||
additional envs. Its value must be the path to a valid, existing file. | ||
|
||
+ tox | ||
+ poetry (recommended) | ||
- Define dev/prod/test settings: | ||
|
||
.. include:: examples/a_pkg/a_pkg/settings.py | ||
|
||
Installation | ||
------------ | ||
IMPORTANT: Make sure to set | ||
`Config.env_prefix=[package_name].upper().replace('-' ,'_')+'_'`. | ||
In this example, a package named `a-pkg` turns into `A_PKG_` | ||
|
||
- pip install petri | ||
- Select which class of setting to use, by doing one of the folowing: | ||
|
||
Testing | ||
------- | ||
|
||
- run `tox -e venv` to create an appropiate virtualenv | ||
- `tox` to run the full test suite | ||
+ Set the envvar `[package_name].replace("-", "_").upper() + "_CONFIG"` to | ||
a defined settings class (eg: `A_PKG_CONFIG=a_pkg.settings:Production`), or | ||
|
||
+ Use the `default_config` kwarg when instantiating `petri.Petri` (See Below) | ||
|
||
Contribute | ||
---------- | ||
Of course, you can use both. Petri will attempt to load said env, and if not | ||
found, default to the defined kwarg. | ||
|
||
- Development | ||
|
||
+ Make sure to pass tox tests (including those with `--runslow`). | ||
+ For tests design, you can use use ´@pytest.mark.incremental´ and ´@pytest.mark.slow´. See "catalogo_db/tests/conftest.py" | ||
+ If the requirements change, make sure to re-build all images | ||
- Instantiate `petri.Petri` form your package's `__init__.py`, like so: | ||
|
||
- Versioning | ||
|
||
+ Use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/pwoolvett/petri/tags). | ||
.. include:: examples/a_pkg/a_pkg/__init__.py | ||
|
||
Support | ||
------- | ||
This allows petri to: | ||
|
||
If you are having issues, please file an issue in github. | ||
- Load `env_file`'s contents, if defined. | ||
- Provide your package's metadata (version, author, etc), available in | ||
`pkg.meta` (lazy-loaded to avoid reading metadata files unnecessarily). | ||
- Activate and instantiate a settings class, according to environment var and | ||
default, available in `pkg.settings` (https://pydantic-docs.helpmanual.io/#id5) | ||
- Configure and expose a logger, available in `pkg.log`, which uses | ||
configuration defined in your settings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
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 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. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
username:{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g= |
Oops, something went wrong.