8000 introduce templates/ directory and add basic template (#78) · localstack/localstack-extensions@3ff9fab · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ff9fab

Browse files
thrauPive01
andauthored
introduce templates/ directory and add basic template (#78)
Co-authored-by: Luca Pivetta <36865043+Pive01@users.noreply.github.com>
1 parent 1e7ec82 commit 3ff9fab

File tree

9 files changed

+147
-0
lines changed

9 files changed

+147
-0
lines changed

template/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Extension Template
22
==================
33

4+
> [!NOTE]
5+
> This template is used for localstack CLI versions <= 3.6.0. For later version see https://github.com/localstack/localstack-extensions/tree/main/templates
6+
47
This is a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template that is used when you invoke.
58

69
```console

templates/basic/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Extension Template
2+
==================
3+
4+
This is a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template that is used when you invoke.
5+
6+
```console
7+
localstack extensions dev new
8+
```
9+
10+
It contains a simple python distribution config, and some boilerplate extension code.

templates/basic/cookiecutter.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"project_name": "My LocalStack Extension",
3+
"project_short_description": "All the boilerplate you need to create a LocalStack extension.",
4+
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}",
5+
"module_name": "{{ cookiecutter.project_slug.replace('-', '_') }}",
6+
"class_name": "{{ cookiecutter.project_name.replace('-', ' ').replace('_', ' ').title().replace(' ', '') }}",
7+
"full_name": "Jane Doe",
8+
"email": "jane@example.com",
9+
"github_username": "janedoe",
10+
"version": "0.1.0"
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.venv
2+
dist
3+
build
4+
**/*.egg-info
5+
.eggs
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
VENV_BIN = python3 -m venv
2+
VENV_DIR ?= .venv
3+
VENV_ACTIVATE = $(VENV_DIR)/bin/activate
4+
VENV_RUN = . $(VENV_ACTIVATE)
5+
6+
venv: $(VENV_ACTIVATE)
7+
8+
$(VENV_ACTIVATE): pyproject.toml
9+
test -d .venv || $(VENV_BIN) .venv
10+
$(VENV_RUN); pip install --upgrade pip setuptools plux
11+
$(VENV_RUN); pip install -e .[dev]
12+
touch $(VENV_DIR)/bin/activate
13+
14+
clean:
15+
rm -rf .venv/
16+
rm -rf build/
17+
rm -rf .eggs/
18+
rm -rf *.egg-info/
19+
20+
install: venv
21+
$(VENV_RUN); python -m plux entrypoints
22+
23+
dist: venv
24+
$(VENV_RUN); python -m build
25+
26+
publish: clean-dist venv dist
27+
$(VENV_RUN); pip install --upgrade twine; twine upload dist/*
28+
29+
clean-dist: clean
30+
rm -rf dist/
31+
32+
.PHONY: clean clean-dist dist install publish
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{ cookiecutter.project_name }}
2+
===============================
3+
4+
{{ cookiecutter.project_short_description }}
5+
6+
## Install local development version
7+
8+
To install the extension into localstack in developer mode, you will need Python 3.10, and create a virtual environment in the extensions project.
9+
10+
In the newly generated project, simply run
11+
12+
```bash
13+
make install
14+
```
15+
16+
Then, to enable the extension for LocalStack, run
17+
18+
```bash
19+
localstack ext 9E12 ensions dev enable .
20+
```
21+
22+
You can then start LocalStack with `EXTENSION_DEV_MODE=1` to load all enabled extensions:
23+
24+
```bash
25+
EXTENSION_DEV_MODE=1 localstack start
26+
```
27+
28+
## Install from GitHub repository
29+
30+
To distribute your extension, simply upload it to your github account. Your extension can then be installed via:
31+
32+
```bash
33+
localstack extensions install "git+https://github.com/{{cookiecutter.github_username }}/{{ cookiecutter.project_slug }}/#egg={{ cookiecutter.project_slug }}"
34+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[build-system]
2+
requires = ["setuptools", 'wheel', 'plux>=1.3.1']
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "{{ cookiecutter.project_slug }}"
7+
version = "{{ cookiecutter.version }}"
8+
description = "LocalStack Extension: {{ cookiecutter.project_name }}"
9< F438 /td>+
readme = {file = "README.md", content-type = "text/markdown; charset=UTF-8"}
10+
requires-python = ">=3.8"
11+
license = {text = "UNLICENSED"}
12+
authors = [
13+
{ name = "{{ cookiecutter.full_name }}", email = "{{ cookiecutter.email }}" }
14+
]
15+
keywords = ["localstack", "localstack-extension", "extension"]
16+
classifiers = []
17+
dependencies = [
18+
]
19+
20+
[project.urls]
21+
Homepage = "https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}"
22+
23+
[project.optional-dependencies]
24+
dev = [
25+
"localstack>=0.0.0.dev"
26+
]
27+
28+
[project.entry-points."localstack.extensions"]
29+
{{ cookiecutter.module_name }} = "{{ cookiecutter.module_name }}.extension:{{ cookiecutter.class_name }}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "{{ cookiecutter.module_name }}"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from localstack.extensions.api import Extension, http, aws
2+
3+
class {{ cookiecutter.class_name }}(Extension):
4+
name = "{{ cookiecutter.project_slug }}"
5+
6+
def on_extension_load(self):
7+
print("MyExtension: extension is loaded")
8+
9+
def on_platform_start(self):
10+
print("MyExtension: localstack is starting")
11+
12+
def on_platform_ready(self):
13+
print("MyExtension: localstack is running")
14+
15+
def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
16+
pass
17+
18+
def update_request_handlers(self, handlers: aws.CompositeHandler):
19+
pass
20+
21+
def update_response_handlers(self, handlers: aws.CompositeResponseHandler):
22+
pass

0 commit comments

Comments
 (0)
0