Skip to content

Commit

Permalink
feat(build): use poetry and organise modules (#408)
Browse files Browse the repository at this point in the history
# Changes

Fixes #204 
- We do not publish `testcontainers-*` packages any more as it's a
maintenance nightmare on PyPI
- example: in case of loss of access to the PyPI package, it's a messy
and long procedure to reclaim it
- Instead the project root is now a collection of modules, see
`pyproject.toml`
- All published under `testcontainers` which will allow the previous
`testcontainers[extra1, extra2]` format to be used (replacing the
`/meta` package mechanism)
- Removes old config files like `.coveragerc` and `setup.cfg` and
integrates them into `pyproject.toml` - more grooming incoming in future
PRs (like the move to `ruff` which is a more performant
formatter/linter)

---------

Co-authored-by: Balint Bartha <totallyzen@users.noreply.github.com>
Co-authored-by: Dave Ankin <daveankin@gmail.com>
  • Loading branch information
3 people committed Feb 13, 2024
1 parent 348f83d commit 6c69583
Show file tree
Hide file tree
Showing 110 changed files with 3,354 additions and 687 deletions.
12 changes: 0 additions & 12 deletions .coveragerc

This file was deleted.

76 changes: 76 additions & 0 deletions .github/workflows/ci-community.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contrinuous Integration for community modules

name: modules

on:
push:
branches: [main]
paths:
- "modules/**"
pull_request:
branches: [main]
paths:
- "modules/**"

permissions:
actions: write # needed for self-cancellation

jobs:
test:
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
module:
- arangodb
- azurite
- clickhouse
- elasticsearch
- google
- kafka
- keycloak
- localstack
- minio
- mongodb
- mssql
- mysql
- neo4j
- nginx
- opensearch
- oracle
- postgres
- rabbitmq
- redis
- selenium
- k3s
runs-on: ubuntu-latest
steps:
- name: Get changed files
id: changes-for-module
uses: tj-actions/changed-files@v42
with:
files: |
modules/${{ matrix.module }}/**
- name: Exit early, nothing to do
if: ${{ steps.changes-for-module.outputs.any_changed == 'false' }}
run: |
# cancel and wait for run to end
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout contents
uses: actions/checkout@v4
- name: Setup Poetry
run: pipx install poetry
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: poetry
- name: Install Python dependencies
run: poetry install -E ${{ matrix.module }}
- name: Run linter
run: make modules/${{ matrix.module }}/lint
- name: Run tests
run: make modules/${{ matrix.module }}/tests
34 changes: 34 additions & 0 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Contrinuous Integration for the core package

name: core

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
strategy:
matrix:
os: [ ubuntu ]
python-version: ["3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- name: Setup Poetry
run: pipx install poetry
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry
- name: Install Python dependencies
run: poetry install
- name: Run linter
run: make core/lint
- name: Run twine check
run: poetry build && poetry run twine check dist/*.tar.gz
- name: Run tests
run: make core/tests
18 changes: 9 additions & 9 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: testcontainers documentation
name: docs

on:
push:
branches: [main]
Expand All @@ -10,15 +11,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup python 3.10
uses: actions/setup-python@v4
- name: Setup Poetry
run: pipx install poetry
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip
cache-dependency-path: requirements/ubuntu-latest-3.10.txt
python-version: "3.11"
cache: poetry
- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install -r requirements/ubuntu-latest-3.10.txt
run: poetry install --all-extras
- name: Build documentation
run: make docs
91 changes: 0 additions & 91 deletions .github/workflows/main.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/triage-label.yml.disabled
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
name: Automatically add triage labels to new issues and pull requests
on:
issues:
types:
Expand Down
47 changes: 24 additions & 23 deletions README.rst → INDEX.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ testcontainers-python facilitates the use of Docker containers for functional an
.. toctree::

core/README
arangodb/README
azurite/README
clickhouse/README
elasticsearch/README
google/README
kafka/README
keycloak/README
localstack/README
minio/README
mongodb/README
mssql/README
mysql/README
neo4j/README
nginx/README
opensearch/README
oracle/README
postgres/README
rabbitmq/README
redis/README
selenium/README
k3s/README
modules/arangodb/README
modules/azurite/README
modules/clickhouse/README
modules/elasticsearch/README
modules/google/README
modules/kafka/README
modules/keycloak/README
modules/localstack/README
modules/minio/README
modules/mongodb/README
modules/mssql/README
modules/mysql/README
modules/neo4j/README
modules/nginx/README
modules/opensearch/README
modules/oracle/README
modules/postgres/README
modules/rabbitmq/README
modules/redis/README
modules/selenium/README
modules/k3s/README

Getting Started
---------------
Expand All @@ -47,8 +47,9 @@ Getting Started

>>> with PostgresContainer("postgres:9.5") as postgres:
... engine = sqlalchemy.create_engine(postgres.get_connection_url())
... result = engine.execute("select version()")
... version, = result.fetchone()
... with engine.begin() as connection:
... result = connection.execute(sqlalchemy.text("select version()"))
... version, = result.fetchone()
>>> version
'PostgreSQL 9.5...'

Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PYTHON_VERSIONS = 3.7 3.8 3.9 3.10 3.11
PYTHON_VERSIONS = 3.9 3.10 3.11
PYTHON_VERSION ?= 3.10
IMAGE = testcontainers-python:${PYTHON_VERSION}
RUN = docker run --rm -it
# Get all directories that contain a setup.py and get the directory name.
PACKAGES = $(subst /,,$(dir $(wildcard */setup.py)))
PACKAGES = core $(addprefix modules/,$(notdir $(wildcard modules/*)))

# All */dist folders for each of the packages.
DISTRIBUTIONS = $(addsuffix /dist,${PACKAGES})
Expand All @@ -25,12 +25,12 @@ ${DISTRIBUTIONS} : %/dist : %/setup.py
# Targets to run the test suite for each package.
tests : ${TESTS}
${TESTS} : %/tests :
pytest -svx --cov-report=term-missing --cov=testcontainers.$* --tb=short --strict-markers $*/tests
poetry run pytest -v --cov=testcontainers.$* $*/tests

# Targets to lint the code.
lint : ${LINT}
${LINT} : %/lint :
flake8 $*
poetry run flake8 $*

# Targets to publish packages.
upload : ${UPLOAD}
Expand All @@ -42,7 +42,7 @@ ${UPLOAD} : %/upload :
fi

# Targets to build docker images
image: requirements/ubunut-latest-${PYTHON_VERSION}.txt
image: requirements/ubuntu-latest-${PYTHON_VERSION}.txt
docker build --build-arg version=${PYTHON_VERSION} -t ${IMAGE} .

# Targets to run tests in docker containers
Expand All @@ -54,13 +54,13 @@ ${TESTS_DIND} : %/tests-dind : image

# Target to build the documentation
docs :
sphinx-build -nW . docs/_build
poetry run sphinx-build -nW . docs/_build

doctest : ${DOCTESTS}
sphinx-build -b doctest . docs/_build
poetry run sphinx-build -b doctest . docs/_build

${DOCTESTS} : %/doctest :
sphinx-build -b doctest -c doctests $* docs/_build
poetry run sphinx-build -b doctest -c doctests $* docs/_build

# Remove any generated files.
clean :
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Testcontainers Python

`testcontainers-python` facilitates the use of Docker containers for functional and integration testing.

For more information, see [the docs][readthedocs].

[readthedocs]: https://testcontainers-python.readthedocs.io/en/latest/

## Getting Started

```pycon
>>> from testcontainers.postgres import PostgresContainer
>>> import sqlalchemy

>>> with PostgresContainer("postgres:9.5") as postgres:
... engine = sqlalchemy.create_engine(postgres.get_connection_url())
... with engine.begin() as connection:
... result = connection.execute(sqlalchemy.text("select version()"))
... version, = result.fetchone()
>>> version
'PostgreSQL 9.5...'
```

The snippet above will spin up a postgres database in a container. The `get_connection_url()` convenience method returns a `sqlalchemy` compatible url we use to connect to the database and retrieve the database version.
Loading

0 comments on commit 6c69583

Please sign in to comment.