pydocks 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ # IMPORTANT: this permission is mandatory for trusted publishing
13
+ id-token: write
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ with:
17
+ fetch-depth: 10
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v4
20
+ with:
21
+ python-version: '3.12'
22
+ - name: Extract version from tag
23
+ run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
24
+ - name: Install uv
25
+ uses: astral-sh/setup-uv@v2
26
+ - name: Use uv with Python version
27
+ run: uv venv --python 3.12
28
+ - run: make install
29
+ - run: make build
30
+ - run: make test
31
+ - name: mint API token
32
+ id: mint-token
33
+ run: |
34
+ # retrieve the ambient OIDC token
35
+ resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
36
+ "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi")
37
+ oidc_token=$(jq -r '.value' <<< "${resp}")
38
+
39
+ # exchange the OIDC token for an API token
40
+ resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
41
+ api_token=$(jq -r '.token' <<< "${resp}")
42
+
43
+ # mask the newly minted API token, so that we don't accidentally leak it
44
+ echo "::add-mask::${api_token}"
45
+
46
+ # see the next step in the workflow for an example of using this step output
47
+ echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}"
48
+ - name: publish
49
+ # gh-action-pypi-publish uses TWINE_PASSWORD automatically
50
+ uses: pypa/gh-action-pypi-publish@release/v1
51
+ with:
52
+ password: ${{ steps.mint-token.outputs.api-token }}
53
+
@@ -0,0 +1,34 @@
1
+ name: Run Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '*'
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+ workflow_dispatch:
11
+
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ python-version: ['3.9', '3.10', '3.11', '3.12']
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Set up Python
22
+ uses: actions/setup-python@v4
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+ - name: Install uv
26
+ uses: astral-sh/setup-uv@v2
27
+ - name: Use uv with Python version
28
+ run: uv venv --python ${{ matrix.python-version }}
29
+ - name: Install dependencies
30
+ run: make install
31
+ - name: Build
32
+ run: VERSION=0.0.1 make build
33
+ - name: Run tests
34
+ run: make test
@@ -0,0 +1,164 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ /.idea/*
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py,cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ # .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ #poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
112
+ .pdm.toml
113
+ .pdm-python
114
+ .pdm-build/
115
+
116
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117
+ __pypackages__/
118
+
119
+ # Celery stuff
120
+ celerybeat-schedule
121
+ celerybeat.pid
122
+
123
+ # SageMath parsed files
124
+ *.sage.py
125
+
126
+ # Environments
127
+ .env
128
+ .venv
129
+ env/
130
+ venv/
131
+ ENV/
132
+ env.bak/
133
+ venv.bak/
134
+
135
+ # Spyder project settings
136
+ .spyderproject
137
+ .spyproject
138
+
139
+ # Rope project settings
140
+ .ropeproject
141
+
142
+ # mkdocs documentation
143
+ /site
144
+
145
+ # mypy
146
+ .mypy_cache/
147
+ .dmypy.json
148
+ dmypy.json
149
+
150
+ # Pyre type checker
151
+ .pyre/
152
+
153
+ # pytype static type analyzer
154
+ .pytype/
155
+
156
+ # Cython debug symbols
157
+ cython_debug/
158
+
159
+ # PyCharm
160
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
163
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
+ #.idea/
@@ -0,0 +1 @@
1
+ 3.12
pydocks-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 PyDocks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pydocks-0.0.1/Makefile ADDED
@@ -0,0 +1,65 @@
1
+ SHELL:=/bin/bash
2
+
3
+ # Git workflow commands
4
+ .PHONY: wip
5
+ wip:
6
+ git add .
7
+ git commit -m "WIP: Work in progress"
8
+ git push
9
+
10
+ # Install command
11
+ .PHONY: install
12
+ install:
13
+ uv sync --all-extras --dev
14
+
15
+ # Build command
16
+ .PHONY: build
17
+ build: check-version
18
+ rm -rf dist/* || true
19
+ # ls -al
20
+ ./scripts/version.sh "${VERSION}"
21
+ @cat pyproject.toml | grep version
22
+ @cat pydocks/__init__.py | grep version
23
+ uv build
24
+
25
+ .PHONY: check-version
26
+ check-version:
27
+ @if [ -z "${VERSION}" ]; then \
28
+ echo "VERSION is not set. Please set the VERSION environment variable."; \
29
+ exit 1; \
30
+ fi
31
+
32
+ # Deploy command
33
+ .PHONY: deploy
34
+ deploy:
35
+ uvx twine upload dist/*
36
+
37
+ # Install local build command
38
+ .PHONY: install-local
39
+ install-local:
40
+ pip3 install dist/*.whl
41
+
42
+ # Test command
43
+ .PHONY: test
44
+ test:
45
+ uv run pytest -v --log-cli-level=INFO
46
+
47
+ # Lint command
48
+ .PHONY: lint
49
+ lint:
50
+ uv run ruff check --fix
51
+ uv run ruff format
52
+ uv run ruff format --check
53
+
54
+ # Display all available commands
55
+ .PHONY: help
56
+ help:
57
+ @echo "Available commands:"
58
+ @echo " wip - Commit and push work in progress"
59
+ @echo " install - Install dependencies"
60
+ @echo " build - Build the project"
61
+ @echo " deploy - Deploy the project"
62
+ @echo " install-local - Install the build locally"
63
+ @echo " test - Run tests"
64
+ @echo " lint - Run linter"
65
+ @echo " help - Display this help message"
pydocks-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.3
2
+ Name: pydocks
3
+ Version: 0.0.1
4
+ Summary: Pytest fixures for running tests with Docker containers
5
+ Project-URL: homepage, https://github.com/sylvainmouquet/pydocks
6
+ Project-URL: documentation, https://github.com/sylvainmouquet/pydocks
7
+ Project-URL: repository, https://github.com/sylvainmouquet/ppydocks
8
+ Project-URL: changelog, https://github.com/sylvainmouquet/pydocks/releases
9
+ Author-email: Sylvain Mouquet <sylvain.mouquet@gmail.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: containers,docker,pydocks,pytest,test
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Framework :: Pytest
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: asyncpg>=0.29.0
26
+ Requires-Dist: uvloop>=0.20.0
27
+ Description-Content-Type: text/markdown
28
+
29
+ # PyDocks
30
+
31
+ PyDocks is a group of pytest fixures for running tests with Docker containers
32
+
33
+ ### Demonstration:
34
+
35
+ ```python
36
+ ...
37
+ ```
38
+
39
+ ## Table of Contents
40
+
41
+ - [PyDocks](#PyDocks)
42
+ - [Table of Contents](#table-of-contents)
43
+ - [Description](#description)
44
+ - [Installation](#installation)
45
+ - [Usage](#usage)
46
+ - [License](#license)
47
+ - [Contact](#contact)
48
+
49
+ ## Description
50
+
51
+ PyDocks is a Python library that provides a set of pytest fixtures for running tests with Docker containers. It simplifies the process of setting up, managing, and tearing down Docker containers during test execution.
52
+
53
+ Key features include:
54
+ - Easy integration with pytest
55
+ - Support for PostgreSQL containers
56
+ - Automatic container cleanup
57
+ - Configurable container settings
58
+ - Reusable session-scoped containers for improved test performance
59
+
60
+ PyDocks is designed to make testing with Docker containers more efficient and less error-prone, allowing developers to focus on writing tests rather than managing infrastructure.
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ # Install the dependency
66
+ pip install pydocks
67
+ uv add pydocks
68
+ poetry add pydocks
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ ```python
74
+ from pydocks import pydocks
75
+
76
+ ```
77
+
78
+
79
+ ## License
80
+
81
+ PyDocks is released under the MIT License. See the [LICENSE](LICENSE) file for more details.
82
+
83
+ ## Contact
84
+
85
+ For questions, suggestions, or issues related to ReAttempt, please open an issue on the GitHub repository.
86
+
@@ -0,0 +1,58 @@
1
+ # PyDocks
2
+
3
+ PyDocks is a group of pytest fixures for running tests with Docker containers
4
+
5
+ ### Demonstration:
6
+
7
+ ```python
8
+ ...
9
+ ```
10
+
11
+ ## Table of Contents
12
+
13
+ - [PyDocks](#PyDocks)
14
+ - [Table of Contents](#table-of-contents)
15
+ - [Description](#description)
16
+ - [Installation](#installation)
17
+ - [Usage](#usage)
18
+ - [License](#license)
19
+ - [Contact](#contact)
20
+
21
+ ## Description
22
+
23
+ PyDocks is a Python library that provides a set of pytest fixtures for running tests with Docker containers. It simplifies the process of setting up, managing, and tearing down Docker containers during test execution.
24
+
25
+ Key features include:
26
+ - Easy integration with pytest
27
+ - Support for PostgreSQL containers
28
+ - Automatic container cleanup
29
+ - Configurable container settings
30
+ - Reusable session-scoped containers for improved test performance
31
+
32
+ PyDocks is designed to make testing with Docker containers more efficient and less error-prone, allowing developers to focus on writing tests rather than managing infrastructure.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ # Install the dependency
38
+ pip install pydocks
39
+ uv add pydocks
40
+ poetry add pydocks
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from pydocks import pydocks
47
+
48
+ ```
49
+
50
+
51
+ ## License
52
+
53
+ PyDocks is released under the MIT License. See the [LICENSE](LICENSE) file for more details.
54
+
55
+ ## Contact
56
+
57
+ For questions, suggestions, or issues related to ReAttempt, please open an issue on the GitHub repository.
58
+
@@ -0,0 +1,16 @@
1
+ __version__ = "0.0.1"
2
+ __all__ = (
3
+ "__version__",
4
+ "postgresql_clean_all_containers",
5
+ "postgresql_container",
6
+ "postgresql_container_session",
7
+ "docker",
8
+ )
9
+
10
+ # pytest_plugins = ["pydocks.conftest"]
11
+ from pydocks.plugin import docker
12
+ from pydocks.postgresql import (
13
+ postgresql_clean_all_containers,
14
+ postgresql_container,
15
+ postgresql_container_session,
16
+ )
@@ -0,0 +1,16 @@
1
+ """
2
+ # https://hub.docker.com/r/nginx/tags
3
+ TEST_NGINX_DOCKER_IMAGE: str = "docker.io/nginx:1.27.1-alpine"
4
+
5
+ # https://hub.docker.com/r/hashicorp/terraform/tags
6
+ TEST_TERRAFORM_DOCKER_IMAGE: str = "docker.io/hashicorp/terraform:1.5"
7
+
8
+ # https://hub.docker.com/r/chainguard/opentofu/tags
9
+ TEST_OPENTOFU_DOCKER_IMAGE: str = "docker.io/chainguard/opentofu:latest-dev"
10
+
11
+ # https://hub.docker.com/_/redis/tags
12
+ TEST_REDIS_DOCKER_IMAGE: str = "docker.io/redis:7.4.0"
13
+
14
+ # https://hub.docker.com/r/hashicorp/vault/tags
15
+ TEST_VAULT_DOCKER_IMAGE: str = "docker.io/hashicorp/vault:1.17.3"
16
+ """
@@ -0,0 +1,63 @@
1
+ import pytest
2
+ from pathlib import Path
3
+ import os
4
+
5
+ import socket
6
+
7
+ # from asgi_lifespan import LifespanManager
8
+ import anyio
9
+ from python_on_whales import DockerClient
10
+ from reattempt import reattempt
11
+ import logging
12
+
13
+ logger = logging.getLogger("pydocks")
14
+ logger.addHandler(logging.NullHandler())
15
+
16
+
17
+ @pytest.fixture(scope="session", autouse=True)
18
+ def docker():
19
+ if "DOCKER_SOCK" in os.environ:
20
+ yield DockerClient(host=os.environ["DOCKER_SOCK"])
21
+ elif "CI" in os.environ:
22
+ # Github Actions, GitLab CI, ...
23
+ yield DockerClient()
24
+ else:
25
+ # local with colima
26
+ home: str = str(Path.home())
27
+ yield DockerClient(host=f"unix://{home}/.colima/default/docker.sock")
28
+
29
+
30
+ @reattempt(max_retries=30, min_time=0.1, max_time=0.5)
31
+ async def socket_test_connection(host, port):
32
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
33
+ s.connect((host, port))
34
+ await anyio.wait_socket_writable(s)
35
+
36
+
37
+ async def clean_containers(docker: DockerClient, name: str):
38
+ containers = docker.ps(all=True, filters={"name": f"^{name}"})
39
+
40
+ for container in containers:
41
+ if container.state.running:
42
+ docker.kill(container)
43
+ logger.info(f"remove container {container.name}")
44
+ docker.remove(container)
45
+
46
+
47
+ async def wait_and_run_container(docker, container, name: str):
48
+ logger.debug(f"start {name}")
49
+ try:
50
+ yield container
51
+ finally:
52
+ logger.debug(f"kill container {name} and remove the docker container")
53
+ if container.state.status == "running":
54
+ logger.debug(f"container {name} is running")
55
+ docker.kill(container.id)
56
+ logger.debug(f"killed container {name}")
57
+ else:
58
+ logger.debug(f"container {name} is not running")
59
+
60
+ # keep the container id, to keep the docker images
61
+ # docker has a garbage collector, when all docker container are deleted the
62
+ # image related is deleted
63
+ # docker.remove(container.id)