Skip to content

Use Poetry for dependency management and packaging #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ serialize =

[bumpversion:file:openapi_core/__init__.py]

[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"
63 changes: 43 additions & 20 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,46 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_dev.txt
pip install -e .
- name: Build documentation
run: |
python -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs docs/_build/html -n -W
- uses: actions/upload-artifact@v2
name: Upload docs as artifact
with:
name: docs-html
path: './docs/_build/html'
if-no-files-found: error
- uses: actions/checkout@v2

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Get full Python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

- name: Bootstrap poetry
run: |
curl -sL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - -y
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v2
id: cache
with:
path: .venv
key: venv-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
run: poetry install

- name: Build documentation
run: |
poetry run python -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs docs/_build/html -n -W

- uses: actions/upload-artifact@v2
name: Upload docs as artifact
with:
name: docs-html
path: './docs/_build/html'
if-no-files-found: error
43 changes: 21 additions & 22 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@ on:
workflow_dispatch:
release:
types:
- created
- created

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build
run: python setup.py sdist bdist_wheel
- name: Publish wheel
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload dist/*.whl
- name: Publish source
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload dist/*.tar.gz || true
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Bootstrap poetry
run: |
curl -sL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - -y
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Build
run: poetry build

- name: Publish
env:
POETRY_HTTP_BASIC_PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: poetry publish
55 changes: 40 additions & 15 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,56 @@ jobs:
python-version: [3.6, 3.7, 3.8, 3.9]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_dev.txt
pip install -e .
- name: Test
run: python setup.py test
- name: Upload coverage
uses: codecov/codecov-action@v1
- uses: actions/checkout@v2

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

- name: Get full Python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

- name: Bootstrap poetry
run: |
curl -sL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - -y
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v2
id: cache
with:
path: .venv
key: venv-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
run: poetry install

- name: Test
run: poetry run pytest

- name: Upload coverage
uses: codecov/codecov-action@v1

static-checks:
name: "Static checks"
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v2

- name: "Setup Python"
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: "Run static checks"
uses: pre-commit/action@v2.0.3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ ENV/

# Jetbrains project files
.idea/

/reports/
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ matrix:
allow_failures:
- python: nightly
before_install:
- pip install codecov
- pip install 'py>=1.5.0'
- curl -sL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - -y
- export PATH=$PATH:$HOME/.local/bin
install:
- pip install -r requirements.txt
- pip install -r requirements_dev.txt
- pip install -e .
- poetry install
script:
- python setup.py test
- poetry run pytest
after_success:
- codecov
29 changes: 24 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
# Contributor Guide

Contributor Guide
=================
## Prerequisites

# Static checks
Install [Poetry](https://github.com/python-poetry/poetry) by following the [official installation instructions](https://github.com/python-poetry/poetry#installation). Optionally (but recommended), configure Poetry to create a virtual environment in a folder named `.venv` within the root directory of the project:

The project uses static checks using fantastic [pre-commit](https://pre-commit.com/). Every change is checked on CI and if it does not pass the tests it cannot be accepted. If you want to check locally then run following command to install pre-commit:
```bash
poetry config virtualenvs.in-project true
```

## Setup

To create a development environment and install the runtime and development dependencies, run:

```bash
pip install -r requiremenets_dev.txt
poetry install
```

Then enter the virtual environment created by Poetry:

```bash
poetry shell
```

## Static checks

The project uses static checks using fantastic [pre-commit](https://pre-commit.com/). Every change is checked on CI and if it does not pass the tests it cannot be accepted. If you want to check locally then run following command to install pre-commit.

To turn on pre-commit checks for commit operations in git, enter:

```bash
pre-commit install
```

To run all checks on your staged files, enter:

```bash
pre-commit run
```

To run all checks on all files, enter:

```bash
pre-commit run --all-files
```
Expand Down
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ params:
@echo "Version: ${VERSION}"

dist-build:
@python setup.py bdist_wheel
@poetry build

dist-cleanup:
@rm -rf build dist ${PACKAGE_NAME}.egg-info

dist-upload:
@twine upload dist/*.whl
@poetry publish

test-python:
@python setup.py test
@pytest

test-cache-cleanup:
@rm -rf .pytest_cache
Expand Down
Loading