diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2f8a0fd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Release to PyPI + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build twine + + - name: Build package + run: python -m build + + - name: Publish to PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + run: twine upload dist/* diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..bb6e669 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,36 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e ".[dev]" + + - name: Lint with ruff + run: ruff check . + + - name: Check formatting with black + run: black --check . + + - name: Run tests + run: pytest tests/ -v diff --git a/.gitignore b/.gitignore index 8cd0668..c956e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ localstack_utils.egg-info .ruff_cache dist +*.env diff --git a/localstack_utils/container.py b/localstack_utils/container.py index 61ca26c..3bd2890 100644 --- a/localstack_utils/container.py +++ b/localstack_utils/container.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging import re import docker @@ -69,4 +71,4 @@ def wait_for_ready(container, pattern): attempts += 1 if attempts >= MAX_LOG_COLLECTION_ATTEMPTS: - raise "Could not find token: " + pattern.toString() + "in logs" + raise RuntimeError(f"Could not find token: {pattern.pattern} in logs") diff --git a/localstack_utils/localstack.py b/localstack_utils/localstack.py index 0422877..dd4985d 100644 --- a/localstack_utils/localstack.py +++ b/localstack_utils/localstack.py @@ -1,5 +1,4 @@ import re -import sys import docker import logging from localstack_utils.container import Container @@ -41,14 +40,13 @@ def startup(self, docker_configuration): try: self.localstack_container = Container.create_localstack_container( - docker_configuration.pull_new_image, - docker_configuration.image_name, - docker_configuration.image_tag, - docker_configuration.gateway_listen, - docker_configuration.environment_variables, - docker_configuration.port_mappings, - docker_configuration.pro, - docker_configuration.auto_remove_container, + pull_new_image=docker_configuration.pull_new_image, + image_name=docker_configuration.image_name, + image_tag=docker_configuration.image_tag, + gateway_listen=docker_configuration.gateway_listen, + auto_remove=docker_configuration.auto_remove_container, + environment_variables=docker_configuration.environment_variables, + bind_ports=docker_configuration.port_mappings, ) self.setup_logger() @@ -57,10 +55,10 @@ def startup(self, docker_configuration): except docker.errors.APIError: if not docker_configuration.ignore_docker_runerrors: - raise "Unable to start docker" + raise RuntimeError("Unable to start docker") except Exception: - raise sys.exc_info() + raise def stop(self): self.localstack_container.stop() diff --git a/tests/test_kinesis.py b/tests/test_kinesis.py index 06f2382..89eaaef 100644 --- a/tests/test_kinesis.py +++ b/tests/test_kinesis.py @@ -6,7 +6,7 @@ class TestKinesis(unittest.TestCase): def setUp(self): - startup_localstack() + startup_localstack(image_name="localstack/localstack") def tearDown(self): stop_localstack() @@ -16,6 +16,7 @@ def test_create_stream(self): kinesis = boto3.client( service_name="kinesis", aws_access_key_id="test", + region_name="us-east-1", aws_secret_access_key="test", endpoint_url="http://localhost:4566", )