Skip to content

Commit 6c69583

Browse files
feat(build): use poetry and organise modules (#408)
# 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 <[email protected]> Co-authored-by: Dave Ankin <[email protected]>
1 parent 348f83d commit 6c69583

File tree

110 files changed

+3354
-687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+3354
-687
lines changed

.coveragerc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/ci-community.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contrinuous Integration for community modules
2+
3+
name: modules
4+
5+
on:
6+
push:
7+
branches: [main]
8+
paths:
9+
- "modules/**"
10+
pull_request:
11+
branches: [main]
12+
paths:
13+
- "modules/**"
14+
15+
permissions:
16+
actions: write # needed for self-cancellation
17+
18+
jobs:
19+
test:
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
python-version: ["3.11"]
24+
module:
25+
- arangodb
26+
- azurite
27+
- clickhouse
28+
- elasticsearch
29+
- google
30+
- kafka
31+
- keycloak
32+
- localstack
33+
- minio
34+
- mongodb
35+
- mssql
36+
- mysql
37+
- neo4j
38+
- nginx
39+
- opensearch
40+
- oracle
41+
- postgres
42+
- rabbitmq
43+
- redis
44+
- selenium
45+
- k3s
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Get changed files
49+
id: changes-for-module
50+
uses: tj-actions/changed-files@v42
51+
with:
52+
files: |
53+
modules/${{ matrix.module }}/**
54+
- name: Exit early, nothing to do
55+
if: ${{ steps.changes-for-module.outputs.any_changed == 'false' }}
56+
run: |
57+
# cancel and wait for run to end
58+
gh run cancel ${{ github.run_id }}
59+
gh run watch ${{ github.run_id }}
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
- name: Checkout contents
63+
uses: actions/checkout@v4
64+
- name: Setup Poetry
65+
run: pipx install poetry
66+
- name: Setup python ${{ matrix.python-version }}
67+
uses: actions/setup-python@v4
68+
with:
69+
python-version: ${{ matrix.python-version }}
70+
cache: poetry
71+
- name: Install Python dependencies
72+
run: poetry install -E ${{ matrix.module }}
73+
- name: Run linter
74+
run: make modules/${{ matrix.module }}/lint
75+
- name: Run tests
76+
run: make modules/${{ matrix.module }}/tests

.github/workflows/ci-core.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Contrinuous Integration for the core package
2+
3+
name: core
4+
5+
on:
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
11+
jobs:
12+
test:
13+
strategy:
14+
matrix:
15+
os: [ ubuntu ]
16+
python-version: ["3.9", "3.10", "3.11"]
17+
runs-on: ${{ matrix.os }}-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Setup Poetry
21+
run: pipx install poetry
22+
- name: Setup python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
cache: poetry
27+
- name: Install Python dependencies
28+
run: poetry install
29+
- name: Run linter
30+
run: make core/lint
31+
- name: Run twine check
32+
run: poetry build && poetry run twine check dist/*.tar.gz
33+
- name: Run tests
34+
run: make core/tests

.github/workflows/docs.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: testcontainers documentation
1+
name: docs
2+
23
on:
34
push:
45
branches: [main]
@@ -10,15 +11,14 @@ jobs:
1011
runs-on: ubuntu-latest
1112
steps:
1213
- uses: actions/checkout@v3
13-
- name: Setup python 3.10
14-
uses: actions/setup-python@v4
14+
- name: Setup Poetry
15+
run: pipx install poetry
16+
- name: Setup python
17+
uses: actions/setup-python@v5
1518
with:
16-
python-version: "3.10"
17-
cache: pip
18-
cache-dependency-path: requirements/ubuntu-latest-3.10.txt
19+
python-version: "3.11"
20+
cache: poetry
1921
- name: Install Python dependencies
20-
run: |
21-
pip install --upgrade pip
22-
pip install -r requirements/ubuntu-latest-3.10.txt
22+
run: poetry install --all-extras
2323
- name: Build documentation
2424
run: make docs

.github/workflows/main.yml

Lines changed: 0 additions & 91 deletions
This file was deleted.

.github/workflows/triage-label.yml.disabled

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
name: Automatically add triage labels to new issues and pull requests
21
on:
32
issues:
43
types:

README.rst renamed to INDEX.rst

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ testcontainers-python facilitates the use of Docker containers for functional an
1515
.. toctree::
1616

1717
core/README
18-
arangodb/README
19-
azurite/README
20-
clickhouse/README
21-
elasticsearch/README
22-
google/README
23-
kafka/README
24-
keycloak/README
25-
localstack/README
26-
minio/README
27-
mongodb/README
28-
mssql/README
29-
mysql/README
30-
neo4j/README
31-
nginx/README
32-
opensearch/README
33-
oracle/README
34-
postgres/README
35-
rabbitmq/README
36-
redis/README
37-
selenium/README
38-
k3s/README
18+
modules/arangodb/README
19+
modules/azurite/README
20+
modules/clickhouse/README
21+
modules/elasticsearch/README
22+
modules/google/README
23+
modules/kafka/README
24+
modules/keycloak/README
25+
modules/localstack/README
26+
modules/minio/README
27+
modules/mongodb/README
28+
modules/mssql/README
29+
modules/mysql/README
30+
modules/neo4j/README
31+
modules/nginx/README
32+
modules/opensearch/README
33+
modules/oracle/README
34+
modules/postgres/README
35+
modules/rabbitmq/README
36+
modules/redis/README
37+
modules/selenium/README
38+
modules/k3s/README
3939

4040
Getting Started
4141
---------------
@@ -47,8 +47,9 @@ Getting Started
4747

4848
>>> with PostgresContainer("postgres:9.5") as postgres:
4949
... engine = sqlalchemy.create_engine(postgres.get_connection_url())
50-
... result = engine.execute("select version()")
51-
... version, = result.fetchone()
50+
... with engine.begin() as connection:
51+
... result = connection.execute(sqlalchemy.text("select version()"))
52+
... version, = result.fetchone()
5253
>>> version
5354
'PostgreSQL 9.5...'
5455

MANIFEST.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

Makefile

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

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

3030
# Targets to lint the code.
3131
lint : ${LINT}
3232
${LINT} : %/lint :
33-
flake8 $*
33+
poetry run flake8 $*
3434

3535
# Targets to publish packages.
3636
upload : ${UPLOAD}
@@ -42,7 +42,7 @@ ${UPLOAD} : %/upload :
4242
fi
4343

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

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

5555
# Target to build the documentation
5656
docs :
57-
sphinx-build -nW . docs/_build
57+
poetry run sphinx-build -nW . docs/_build
5858

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

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

6565
# Remove any generated files.
6666
clean :

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Testcontainers Python
2+
3+
`testcontainers-python` facilitates the use of Docker containers for functional and integration testing.
4+
5+
For more information, see [the docs][readthedocs].
6+
7+
[readthedocs]: https://testcontainers-python.readthedocs.io/en/latest/
8+
9+
## Getting Started
10+
11+
```pycon
12+
>>> from testcontainers.postgres import PostgresContainer
13+
>>> import sqlalchemy
14+
15+
>>> with PostgresContainer("postgres:9.5") as postgres:
16+
... engine = sqlalchemy.create_engine(postgres.get_connection_url())
17+
... with engine.begin() as connection:
18+
... result = connection.execute(sqlalchemy.text("select version()"))
19+
... version, = result.fetchone()
20+
>>> version
21+
'PostgreSQL 9.5...'
22+
```
23+
24+
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.

0 commit comments

Comments
 (0)