Skip to content

Commit 2ba1876

Browse files
Merge pull request #290 from tillahoffmann/packages
Experiment with namespace packages.
2 parents 8ab1024 + 617bb24 commit 2ba1876

File tree

148 files changed

+1328
-877
lines changed

Some content is hidden

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

148 files changed

+1328
-877
lines changed
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
You have implemented a new container and would like to contribute it? Great! Here are the necessary steps:
1+
You have implemented a new container and would like to contribute it? Great! Here are the necessary steps.
22

3-
- [ ] You have added the new container as a module in the `testcontainers` directory (such as `testcontainers/my_fancy_container.py`).
4-
- [ ] You have added any new python dependencies in the `extras_require` section of `setup.py`.
5-
- [ ] You have added the `extra_requires` key to `requirements.in`.
6-
- [ ] You have updated all python requirements by running `make requirements` from the root directory.
7-
- [ ] You have added tests for the new container in the `tests` directory, e.g. `tests/test_my_fancy_container.py`.
8-
- [ ] You have added the name of the container (such as `my_fancy_container`) to the `test-components` matrix in `.github/workflows/main.yml` to ensure the tests are run.
9-
- [ ] You have rebased your development branch on `master` (or merged `master` into your development branch).
3+
- [ ] Create a new feature directory and populate it with the package structure [described in the documentation](https://testcontainers-python.readthedocs.io/en/latest/#package-structure). Copying one of the existing features is likely the best way to get started.
4+
- [ ] Implement the new feature (typically in `__init__.py`) and corresponding tests.
5+
- [ ] Add a line `-e file:[feature name]` to `requirements.in` and run `make requirements`. This command will find any new requirements and generate lock files to ensure reproducible builds (see the [pip-tools documentation](https://pip-tools.readthedocs.io/en/latest/) for details). Then run `pip install -r requirements/[your python version].txt` to install the new requirements.
6+
- [ ] Update the feature `README.rst` and add it to the table of contents (`toctree` directive) in the top-level `README.rst`.
7+
- [ ] Add a line `[feature name]` to the list of components in the GitHub Action workflow in `.github/workflows/main.yml` to run tests, build, and publish your package when pushed to the `master` branch.
8+
- [ ] Rebase your development branch on `master` (or merge `master` into your development branch).

.github/workflows/docs.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: testcontainers documentation
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Setup python 3.10
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: "3.10"
17+
cache: pip
18+
cache-dependency-path: requirements/3.10.txt
19+
- name: Install Python dependencies
20+
run: |
21+
pip install --upgrade pip
22+
pip install -r requirements/3.10.txt
23+
- name: Build documentation
24+
run: make docs

.github/workflows/main.yml

Lines changed: 50 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,11 @@
1-
name: testcontainers-python
1+
name: testcontainers packages
22
on:
33
push:
4-
branches: [ master ]
4+
branches: [master]
55
pull_request:
6-
branches: [ master ]
6+
branches: [master]
77

88
jobs:
9-
sphinx:
10-
strategy:
11-
fail-fast: false
12-
matrix:
13-
python-version:
14-
- "3.7"
15-
- "3.8"
16-
- "3.9"
17-
- "3.10"
18-
runs-on: ubuntu-latest
19-
steps:
20-
- uses: actions/checkout@v2
21-
- name: Setup python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v2
23-
with:
24-
python-version: ${{ matrix.python-version }}
25-
- name: Cache Python dependencies
26-
uses: actions/cache@v2
27-
with:
28-
path: ~/.cache/pip
29-
key: ${{ runner.os }}-pip-${{ hashFiles(format('requirements/{0}.txt', matrix.python-version)) }}
30-
restore-keys: |
31-
${{ runner.os }}-pip-
32-
${{ runner.os }}-
33-
- name: Install Python dependencies
34-
run: |
35-
python -m pip install --upgrade pip
36-
pip install wheel
37-
pip install -r requirements/${{ matrix.python-version }}.txt
38-
- name: Build documentation
39-
run: sphinx-build -nW docs docs/_build/html
40-
- name: Run doctests
41-
run: sphinx-build -b doctest docs docs/_build/html
42-
439
build:
4410
strategy:
4511
fail-fast: false
@@ -49,46 +15,45 @@ jobs:
4915
- "3.8"
5016
- "3.9"
5117
- "3.10"
52-
test-component:
18+
component:
19+
- arangodb
20+
- azurite
21+
- clickhouse
22+
- compose
5323
- core
54-
- clickhouse.py
55-
- elasticsearch.py
56-
- google.py
57-
- kafka.py
58-
- localstack.py
59-
- minio.py
60-
- mongodb.py
61-
- neo4j.py
62-
- nginx.py
63-
- rabbitmq.py
64-
- redis.py
65-
- selenium.py
66-
- webdriver.py
67-
- keycloak.py
68-
- arangodb.py
69-
- azurite.py
70-
- opensearch.py
24+
- elasticsearch
25+
- google
26+
- kafka
27+
- keycloak
28+
- localstack
29+
- meta
30+
- minio
31+
- mongodb
32+
- mssql
33+
- mysql
34+
- neo4j
35+
- nginx
36+
- opensearch
37+
- oracle
38+
- postgres
39+
- rabbitmq
40+
- redis
41+
- selenium
7142
runs-on: ubuntu-latest
7243
steps:
73-
- uses: actions/checkout@v2
44+
- uses: actions/checkout@v3
7445
- name: Setup python ${{ matrix.python-version }}
75-
uses: actions/setup-python@v2
46+
uses: actions/setup-python@v4
7647
with:
7748
python-version: ${{ matrix.python-version }}
78-
- name: Cache Python dependencies
79-
uses: actions/cache@v2
80-
with:
81-
path: ~/.cache/pip
82-
key: ${{ runner.os }}-pip-${{ hashFiles(format('requirements/{0}.txt', matrix.python-version)) }}
83-
restore-keys: |
84-
${{ runner.os }}-pip-
85-
${{ runner.os }}-
49+
cache: pip
50+
cache-dependency-path: ${{ format('requirements/{0}.txt', matrix.python-version) }}
8651
- name: Install Python dependencies
8752
run: |
88-
python -m pip install --upgrade pip
89-
pip install wheel
53+
pip install --upgrade pip
9054
pip install -r requirements/${{ matrix.python-version }}.txt
9155
- name: Run docker diagnostics
56+
if: matrix.component == 'core'
9257
run: |
9358
echo "Build minimal container for docker-in-docker diagnostics"
9459
docker build -f Dockerfile.diagnostics -t testcontainers-python .
@@ -99,12 +64,22 @@ jobs:
9964
echo "Container diagnostics with host network"
10065
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --network=host testcontainers-python python diagnostics.py
10166
- name: Lint the code
102-
run: flake8
67+
run: make ${{ matrix.component }}/lint
10368
- name: Run tests
104-
run: |
105-
py.test -svx --cov-config .coveragerc --cov-report html:skip-covered --cov-report term:skip-covered --cov=testcontainers --tb=short tests/test_${{ matrix.test-component }}
106-
codecov
107-
- name: Build package and check it
108-
run: |
109-
python setup.py bdist_wheel
110-
twine check dist/*
69+
if: matrix.component != 'meta'
70+
run: make ${{ matrix.component }}/tests
71+
- name: Run doctests
72+
if: matrix.component != 'meta'
73+
run: make ${{ matrix.component }}/doctest
74+
- name: Build the package
75+
run: make ${{ matrix.component }}/dist
76+
- name: Upload the package to pypi
77+
if: >
78+
github.event_name == 'push'
79+
&& github.ref == 'refs/heads/master'
80+
&& github.repository_owner == 'testcontainers'
81+
&& matrix.python-version == '3.10'
82+
env:
83+
TWINE_USERNAME: __token__
84+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
85+
run: make ${{ matrix.component }}/upload

.github/workflows/pypi-release.yml

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ venv
7171

7272
.DS_Store
7373
.python-version
74+
.env

.readthedocs.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
# .readthedocs.yml
2-
# Read the Docs configuration file
3-
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
1+
# Read the Docs configuration file (see https://docs.readthedocs.io/en/stable/config-file/v2.html
2+
# for details).
43

5-
# Required
64
version: 2
75

8-
# Build documentation in the docs/ directory with Sphinx
9-
sphinx:
10-
configuration: docs/conf.py
11-
12-
# Optionally build your docs in additional formats such as PDF and ePub
13-
formats: all
14-
15-
# Optionally set the version of Python and requirements required to build your docs
16-
python:
17-
version: 3.7
18-
install:
19-
- requirements: requirements/3.7.txt
6+
build:
7+
os: ubuntu-22.04
8+
tools:
9+
python: "3.10"

Dockerfile.diagnostics

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ ARG version=3.8
22
FROM python:${version}
33

44
WORKDIR /workspace
5-
COPY setup.py README.rst ./
6-
RUN pip install -e .
7-
COPY . .
5+
COPY core core
6+
RUN pip install --no-cache-dir -e core
7+
COPY diagnostics.py .

Makefile

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,81 @@
11
PYTHON_VERSIONS = 3.7 3.8 3.9 3.10
2+
PYTHON_VERSION ?= 3.10
3+
IMAGE = testcontainers-python:${PYTHON_VERSION}
24
REQUIREMENTS = $(addprefix requirements/,${PYTHON_VERSIONS:=.txt})
3-
TESTS = $(addprefix tests/,${PYTHON_VERSIONS})
4-
IMAGES = $(addprefix image/,${PYTHON_VERSIONS})
55
RUN = docker run --rm -it
6+
# Get all directories that contain a setup.py and get the directory name.
7+
PACKAGES = $(subst /,,$(dir $(wildcard */setup.py)))
8+
9+
# All */dist folders for each of the packages.
10+
DISTRIBUTIONS = $(addsuffix /dist,${PACKAGES})
11+
UPLOAD = $(addsuffix /upload,${PACKAGES})
12+
# All */tests folders for each of the test suites.
13+
TESTS = $(addsuffix /tests,$(filter-out meta,${PACKAGES}))
14+
TESTS_DIND = $(addsuffix -dind,${TESTS})
15+
DOCTESTS = $(addsuffix /doctest,$(filter-out meta,${PACKAGES}))
16+
# All linting targets.
17+
LINT = $(addsuffix /lint,${PACKAGES})
18+
19+
# Targets to build a distribution for each package.
20+
dist: ${DISTRIBUTIONS}
21+
${DISTRIBUTIONS} : %/dist : %/setup.py
22+
cd $* \
23+
&& python setup.py bdist_wheel \
24+
&& twine check dist/*
25+
26+
# Targets to run the test suite for each package.
27+
tests : ${TESTS}
28+
${TESTS} : %/tests :
29+
pytest -svx --cov-report=term-missing --cov=testcontainers.$* --tb=short $*/tests
30+
31+
# Targets to lint the code.
32+
lint : ${LINT}
33+
${LINT} : %/lint :
34+
flake8 $*
35+
36+
# Targets to publish packages.
37+
upload : ${UPLOAD}
38+
${UPLOAD} : %/upload :
39+
if [ ${TWINE_REPOSITORY}-$* = testpypi-meta ]; then \
40+
echo "Cannot upload meta package to testpypi because of missing permissions."; \
41+
else \
42+
twine upload --non-interactive --skip-existing $*/dist/*; \
43+
fi
644

7-
.PHONY : docs
45+
# Targets to build docker images
46+
image: requirements/${PYTHON_VERSION}.txt
47+
docker build --build-arg version=${PYTHON_VERSION} -t ${IMAGE} .
848

9-
# Default target
49+
# Targets to run tests in docker containers
50+
tests-dind : ${TESTS_DIND}
1051

11-
default : tests/3.8
52+
${TESTS_DIND} : %/tests-dind : image
53+
${RUN} -v /var/run/docker.sock:/var/run/docker.sock ${IMAGE} \
54+
bash -c "make $*/lint $*/tests"
1255

56+
# Target to build the documentation
57+
docs :
58+
sphinx-build -nW . docs/_build
1359

14-
# Targets to build requirement files
60+
doctest : ${DOCTESTS}
61+
sphinx-build -b doctest . docs/_build
1562

16-
requirements : ${REQUIREMENTS}
63+
${DOCTESTS} : %/doctest :
64+
sphinx-build -b doctest -c doctests $* docs/_build
1765

18-
${REQUIREMENTS} : requirements/%.txt : requirements.in setup.py
66+
# Targets to build requirement files
67+
requirements : ${REQUIREMENTS}
68+
${REQUIREMENTS} : requirements/%.txt : requirements.in */setup.py
1969
mkdir -p $(dir $@)
2070
${RUN} -w /workspace -v `pwd`:/workspace --platform=linux/amd64 python:$* bash -c \
2171
"pip install pip-tools && pip-compile --resolver=backtracking -v --upgrade -o $@ $<"
2272

73+
# Remove any generated files.
74+
clean :
75+
rm -rf docs/_build
76+
rm -rf */build
77+
rm -rf */dist
78+
rm -rf */*.egg-info
2379

24-
# Targets to build docker images
25-
26-
images : ${IMAGES}
27-
28-
${IMAGES} : image/% : requirements/%.txt
29-
docker build --build-arg version=$* -t testcontainers-python:$* .
30-
31-
32-
# Targets to run tests in docker containers
33-
34-
tests : ${TESTS}
35-
36-
${TESTS} : tests/% : image/%
37-
${RUN} -v /var/run/docker.sock:/var/run/docker.sock testcontainers-python:$* \
38-
bash -c "flake8 && pytest -v ${ARGS}"
39-
40-
# Target to build the documentation
41-
42-
docs :
43-
sphinx-build -nW docs docs/_build/html
80+
# Targets that do not generate file-level artifacts.
81+
.PHONY : clean dists ${DISTRIBUTIONS} docs doctests image tests ${TESTS}

0 commit comments

Comments
 (0)