Skip to content

Commit

Permalink
add poetry for managing the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
tcassou committed Nov 3, 2023
1 parent 42cd807 commit 4052b7c
Show file tree
Hide file tree
Showing 11 changed files with 535 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = E203, E266
ignore = E203, E266, W503
max-line-length = 120
max-complexity = 18
select = B,C,E,F,W,T4,B9
164 changes: 121 additions & 43 deletions .github/workflows/lint_test_release.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,138 @@
name: Lint, Test and Release

on: [push]

jobs:

lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install Python 3.9.10
uses: actions/setup-python@v2
with:
python-version: 3.9.10
- name: Install Python Dependencies
run: |
pip install --upgrade pip setuptools
pip install pre-commit==2.9.3
- name: Lint with pre-commit
run: script -e -c "pre-commit run --all-files"
- uses: actions/checkout@v3

- name: Setup Environment
id: setup
run: |
echo "python-version=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_OUTPUT
echo "poetry-version=$(cat .tool-versions | grep -Po '(?<=poetry ).*')" >> $GITHUB_OUTPUT
if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ steps.setup.outputs.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ steps.setup.outputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/.pre-commit-config.yaml') }}

- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

- name: Run linting pre-commit hooks
run: script -e -c "poetry run pre-commit run --all-files"

test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install Python 3.9.10
uses: actions/setup-python@v2
with:
python-version: 3.9.10
- name: Install Python Dependencies
run: |
pip install --upgrade pip setuptools
pip install pytest
- name: Run Unit Tests
env:
ENV: test
run: script -e -c "python -m pytest -v example/tests"
- uses: actions/checkout@v3

- name: Setup Environment
id: setup
run: |
echo "python-version=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_OUTPUT
echo "poetry-version=$(cat .tool-versions | grep -Po '(?<=poetry ).*')" >> $GITHUB_OUTPUT
if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ steps.setup.outputs.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ steps.setup.outputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/.pre-commit-config.yaml') }}

- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

- name: Run unit tests
env:
ENV: test
run: script -e -c "poetry run python -m pytest -v example/tests"

release:
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')

steps:
- uses: actions/checkout@v2
- name: Install Python 3.8.5
uses: actions/setup-python@v2
with:
python-version: 3.8.5
- name: Install Python Dependencies
run: |
pip install --upgrade pip setuptools
pip install wheel twine
- name: Build and Publish to Pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist
twine upload dist/*
- uses: actions/checkout@v3

- name: Bump version and push tag
uses: alexeyatbluescape/github-tag-action@bugfix/semver-empty-results
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch

- name: Setup Environment
id: setup
run: |
echo "python-version=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_OUTPUT
echo "poetry-version=$(cat .tool-versions | grep -Po '(?<=poetry ).*')" >> $GITHUB_OUTPUT
if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ steps.setup.outputs.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ steps.setup.outputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/.pre-commit-config.yaml') }}

# Installing twine in a separate step to prevent circular dependencies and conflicts with cache
- name: Install pip twine
run: pip install --upgrade pip twine

- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

- name: Build and publish to Pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
poetry version $(git describe --tags --abbrev=0)
poetry build
twine upload dist/* --verbose
62 changes: 41 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
default_language_version:
python: python3.9
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
- repo: https://github.com/myint/autoflake
rev: v2.2.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: flake8
- id: debug-statements
- id: check-added-large-files
- id: pretty-format-json
- id: autoflake
name: Autoflake removes unused imports
args:
- --autofix
- --indent=2
- --no-ensure-ascii
- --no-sort-keys
- repo: https://github.com/asottile/reorder_python_imports.git
rev: v3.9.0
[
'--in-place',
'--remove-all-unused-imports',
'--ignore-init-module-imports',
]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: reorder-python-imports
- repo: https://github.com/psf/black
rev: 22.10.0
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: debug-statements
- id: check-added-large-files
- id: pretty-format-json
args:
- --autofix
- --indent=2
- --no-ensure-ascii
- --no-sort-keys
- repo: https://github.com/asottile/reorder_python_imports.git
rev: v3.10.0
hooks:
- id: reorder-python-imports
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
name: Black
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
name: Flake8
- repo: https://github.com/ubersan/pylic
rev: v3.5.0
hooks:
- id: black
language_version: python3.9
- id: pylic
args: [--allow-extra-safe-licenses]
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python 3.9.10
poetry 1.3.2
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,16 @@ Expect('MyObject').to_receive('my_method').with_args(*my_args_3, **my_kwargs_3).

Note that if a method decorated at least once with an `Expect` statement is called more or less times than the number
of Expect statements, the unit test will fail.

# Contributing
## Local Setup
We recommend [using `asdf` for managing high level dependencies](https://asdf-vm.com/).
With `asdf` installed,
1. simply run `asdf install` at the root of the repository,
2. run `poetry install` to install python dependencies.

## Running Tests
```python
poetry shell
ENV=test python -m pytest -v examples/tests/
```
4 changes: 0 additions & 4 deletions expectise/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ class EnvironmentError(Exception):
* not marking methods as mocked with the `mock_if` decorator.
"""

pass


class ExpectationError(Exception):
"""
Error describing misuses of `Expect` statements.
"""

pass
Loading

0 comments on commit 4052b7c

Please sign in to comment.