Skip to content
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

Move from pip-tools -> poetry #87

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
43 changes: 29 additions & 14 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,41 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
# Check-out repo and set-up python
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12.5
- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.12.5
- name: Install Python dependencies
run: |
python3 -m venv venv
source ./venv/bin/activate
pip install -U pip
pip install -r ./requirements.txt
python-version: 3.12
# Install & configure poetry
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
# Load cached venv if cache exists
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Install dependencies if cache does not exist
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
# Run tests on skeleton code;
# NOTE: there are nothing to test yet, unless we add some hooks, just check that it runs
- name: Run tests on hooks
run: poetry run inv test.hooks
# Build a project from skeleton with a default name - awesome, and run tests on it
- name: Build project from skeleton and run tests
run: |
source ./venv/bin/activate
inv test.hooks
- name: Run tests on building project
run: |
source ./venv/bin/activate
cookiecutter --no-input --overwrite-if-exists --output-dir build .
poetry run cookiecutter --no-input --overwrite-if-exists --output-dir build .
cd build/awesome
cp ./api/.env.example ./api/.env
make api-test
22 changes: 0 additions & 22 deletions contrib/docker/docker-compose-local.yml

This file was deleted.

707 changes: 707 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.poetry]
name = "backend-skeleton"
version = "0.1.0"
description = ""
authors = ["DS <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
cookiecutter = "^2.6.0"
pytest = "^8.3.3"
pytest-cov = "^5.0.0"
invoke = "^2.2.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["tests.py", "test_*.py", "*_tests.py"]
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

8 changes: 0 additions & 8 deletions requirements.in

This file was deleted.

597 changes: 0 additions & 597 deletions requirements.txt

This file was deleted.

48 changes: 1 addition & 47 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,11 @@
import os
from shutil import rmtree

from invoke import Collection, task


def path(*args):
current_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(current_dir, *args)


@task()
def compose_up(ctx, daemon=False):
with ctx.cd(path("contrib", "docker")):
command = "docker-compose --file docker-compose-local.yml --project-name=awesome up"
if daemon:
command = f"{command} -d"
ctx.run(command, pty=True, replace_env=False)


@task()
def compose_down(ctx, volumes=False):
with ctx.cd(path("contrib", "docker")):
command = "docker-compose --file docker-compose-local.yml --project-name=awesome down"
if volumes:
command = f"{command} -v"
ctx.run(command, pty=True, replace_env=False)


@task()
def pip_compile(ctx):
command = (
"pip-compile --upgrade --generate-hashes --allow-unsafe "
"-o ./requirements.txt ./requirements.in"
)
ctx.run(command, pty=True)


@task()
def pip_sync(ctx):
ctx.run("pip-sync ./requirements.txt", pty=True)


@task()
def test_hooks(ctx):
ctx.run("pytest -s --cov=hooks --cov-report=html", pty=True, replace_env=False)


compose_collection = Collection("compose")
compose_collection.add_task(compose_up, name="up")
compose_collection.add_task(compose_down, name="down")
pip_collection = Collection("pip")
pip_collection.add_task(pip_compile, name="compile")
pip_collection.add_task(pip_sync, name="sync")
test_collection = Collection("test")
test_collection.add_task(test_hooks, name="hooks")
namespace = Collection(compose_collection, pip_collection, test_collection, )
namespace = Collection(test_collection)