Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion typedb/localstack_typedb/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shlex

from localstack.config import is_env_not_false
from localstack_typedb.utils.docker import ProxiedDockerContainerExtension
from localstack_extensions.utils import ProxiedDockerContainerExtension
from rolo import Request
from werkzeug.datastructures import Headers

Expand Down
Empty file.
4 changes: 1 addition & 3 deletions typedb/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ authors = [
keywords = ["LocalStack", "TypeDB"]
classifiers = []
dependencies = [
"httpx",
"h2",
"priority",
"localstack-extensions-utils",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion typedb/tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
import httpx
from localstack.utils.strings import short_uid
from localstack_typedb.utils.h2_proxy import (
from localstack_extensions.utils import (
get_frames_from_http2_stream,
get_headers_from_frames,
)
Expand Down
40 changes: 40 additions & 0 deletions utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
VENV_BIN = python3 -m venv
VENV_DIR ?= .venv
VENV_ACTIVATE = $(VENV_DIR)/bin/activate
VENV_RUN = . $(VENV_ACTIVATE)

usage: ## Show usage for this Makefile
@cat Makefile | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'

venv: $(VENV_ACTIVATE)

$(VENV_ACTIVATE): pyproject.toml
test -d .venv || $(VENV_BIN) .venv
$(VENV_RUN); pip install --upgrade pip setuptools wheel build
$(VENV_RUN); pip install -e .[dev]
touch $(VENV_DIR)/bin/activate

clean: ## Clean up build artifacts and virtual environment
rm -rf .venv/
rm -rf build/
rm -rf .eggs/
rm -rf *.egg-info/

install: venv ## Install the package in development mode

dist: venv ## Create distribution package
$(VENV_RUN); python -m build

publish: clean-dist venv dist ## Publish package to PyPI
$(VENV_RUN); pip install --upgrade twine; twine upload dist/*

format: venv ## Run ruff to format and fix the code
$(VENV_RUN); python -m ruff format .; python -m ruff check --fix .

lint: venv ## Run ruff to lint the code
$(VENV_RUN); python -m ruff check --output-format=full .

clean-dist: clean
rm -rf dist/

.PHONY: clean clean-dist dist install publish usage venv format lint
40 changes: 40 additions & 0 deletions utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
LocalStack Extensions Utils
===========================

A utility library providing common functionality for building [LocalStack Extensions](https://github.com/localstack/localstack-extensions).

## Usage

To use this library in your LocalStack extension, add it to the `dependencies` in your extension's `pyproject.toml`:

```toml
[project]
dependencies = [
"localstack-extensions-utils",
]
```

Or, to install directly from the GitHub repository:

```toml
[project]
dependencies = [
"localstack-extensions-utils @ git+https://github.com/localstack/localstack-extensions.git#subdirectory=utils",
]
```

Then import the utilities in your extension code, for example:

```python
from localstack_extensions.utils import ProxiedDockerContainerExtension

...
```

## Dependencies

This library requires LocalStack to be installed as it uses various LocalStack utilities for Docker management and networking.

## License

The code in this repo is available under the Apache 2.0 license.
1 change: 1 addition & 0 deletions utils/localstack_extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# LocalStack Extensions utilities package
23 changes: 23 additions & 0 deletions utils/localstack_extensions/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from localstack_extensions.utils.docker import (
ProxiedDockerContainerExtension,
ProxyResource,
)
from localstack_extensions.utils.h2_proxy import (
TcpForwarder,
apply_http2_patches_for_grpc_support,
get_headers_from_data_stream,
get_headers_from_frames,
get_frames_from_http2_stream,
ProxyRequestMatcher,
)

__all__ = [
"ProxiedDockerContainerExtension",
"ProxyResource",
"TcpForwarder",
"apply_http2_patches_for_grpc_support",
"get_headers_from_data_stream",
"get_headers_from_frames",
"get_frames_from_http2_stream",
"ProxyRequestMatcher",
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from typing import Callable
import requests

from localstack import config
from localstack.config import is_env_true
from localstack_typedb.utils.h2_proxy import (
from localstack_extensions.utils.h2_proxy import (
apply_http2_patches_for_grpc_support,
)
from localstack.utils.docker_utils import DOCKER_CLIENT
Expand All @@ -22,10 +21,6 @@
from werkzeug.datastructures import Headers

LOG = logging.getLogger(__name__)
logging.getLogger("localstack_typedb").setLevel(
logging.DEBUG if config.DEBUG else logging.INFO
)
logging.basicConfig()


class ProxiedDockerContainerExtension(Extension):
Expand Down Expand Up @@ -130,8 +125,8 @@ def start_container(self) -> None:
)
except Exception as e:
LOG.debug("Failed to start container %s: %s", self.container_name, e)
# allow running TypeDB in a local server in dev mode, if TYPEDB_DEV_MODE is enabled
if not is_env_true("TYPEDB_DEV_MODE"):
# allow running the container in a local server in dev mode
if not is_env_true(f"{self.name.upper().replace('-', '_')}_DEV_MODE"):
raise

def _ping_endpoint():
Expand Down
40 changes: 40 additions & 0 deletions utils/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[build-system]
requires = ["setuptools", "wheel", "plux>=1.3.1"]
build-backend = "setuptools.build_meta"

[project]
name = "localstack-extensions-utils"
version = "0.1.0"
description = "Utility library for LocalStack Extensions"
readme = {file = "README.md", content-type = "text/markdown; charset=UTF-8"}
requires-python = ">=3.10"
authors = [
{ name = "LocalStack Team" }
]
keywords = ["LocalStack", "Extensions", "Utils"]
classifiers = []
dependencies = [
"httpx",
"h2",
"hpack",
"hyperframe",
"priority",
"requests",
"rolo",
"twisted",
]

[project.urls]
Homepage = "https://github.com/localstack/localstack-extensions"

[project.optional-dependencies]
dev = [
"boto3",
"build",
"localstack",
"pytest",
"ruff",
]

[tool.setuptools.packages.find]
include = ["localstack_extensions*"]
Loading