Skip to content

Commit

Permalink
introduce templates/ directory and add basic template (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Luca Pivetta <36865043+Pive01@users.noreply.github.com>
  • Loading branch information
thrau and Pive01 authored Aug 16, 2024
1 parent 1e7ec82 commit 3ff9fab
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 0 deletions.
3 changes: 3 additions & 0 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Extension Template
==================

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

```console
Expand Down
10 changes: 10 additions & 0 deletions templates/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension Template
==================

This is a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template that is used when you invoke.

```console
localstack extensions dev new
```

It contains a simple python distribution config, and some boilerplate extension code.
11 changes: 11 additions & 0 deletions templates/basic/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"project_name": "My LocalStack Extension",
"project_short_description": "All the boilerplate you need to create a LocalStack extension.",
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}",
"module_name": "{{ cookiecutter.project_slug.replace('-', '_') }}",
"class_name": "{{ cookiecutter.project_name.replace('-', ' ').replace('_', ' ').title().replace(' ', '') }}",
"full_name": "Jane Doe",
"email": "jane@example.com",
"github_username": "janedoe",
"version": "0.1.0"
}
5 changes: 5 additions & 0 deletions templates/basic/{{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.venv
dist
build
**/*.egg-info
.eggs
32 changes: 32 additions & 0 deletions templates/basic/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
VENV_BIN = python3 -m venv
VENV_DIR ?= .venv
VENV_ACTIVATE = $(VENV_DIR)/bin/activate
VENV_RUN = . $(VENV_ACTIVATE)

venv: $(VENV_ACTIVATE)

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

clean:
rm -rf .venv/
rm -rf build/
rm -rf .eggs/
rm -rf *.egg-info/

install: venv
$(VENV_RUN); python -m plux entrypoints

dist: venv
$(VENV_RUN); python -m build

publish: clean-dist venv dist
$(VENV_RUN); pip install --upgrade twine; twine upload dist/*

clean-dist: clean
rm -rf dist/

.PHONY: clean clean-dist dist install publish
34 changes: 34 additions & 0 deletions templates/basic/{{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{ cookiecutter.project_name }}
===============================

{{ cookiecutter.project_short_description }}

## Install local development version

To install the extension into localstack in developer mode, you will need Python 3.10, and create a virtual environment in the extensions project.

In the newly generated project, simply run

```bash
make install
```

Then, to enable the extension for LocalStack, run

```bash
localstack extensions dev enable .
```

You can then start LocalStack with `EXTENSION_DEV_MODE=1` to load all enabled extensions:

```bash
EXTENSION_DEV_MODE=1 localstack start
```

## Install from GitHub repository

To distribute your extension, simply upload it to your github account. Your extension can then be installed via:

```bash
localstack extensions install "git+https://github.com/{{cookiecutter.github_username }}/{{ cookiecutter.project_slug }}/#egg={{ cookiecutter.project_slug }}"
```
29 changes: 29 additions & 0 deletions templates/basic/{{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools", 'wheel', 'plux>=1.3.1']
build-backend = "setuptools.build_meta"

[project]
name = "{{ cookiecutter.project_slug }}"
version = "{{ cookiecutter.version }}"
description = "LocalStack Extension: {{ cookiecutter.project_name }}"
readme = {file = "README.md", content-type = "text/markdown; charset=UTF-8"}
requires-python = ">=3.8"
license = {text = "UNLICENSED"}
authors = [
{ name = "{{ cookiecutter.full_name }}", email = "{{ cookiecutter.email }}" }
]
keywords = ["localstack", "localstack-extension", "extension"]
classifiers = []
dependencies = [
]

[project.urls]
Homepage = "https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}"

[project.optional-dependencies]
dev = [
"localstack>=0.0.0.dev"
]

[project.entry-points."localstack.extensions"]
{{ cookiecutter.module_name }} = "{{ cookiecutter.module_name }}.extension:{{ cookiecutter.class_name }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "{{ cookiecutter.module_name }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from localstack.extensions.api import Extension, http, aws

class {{ cookiecutter.class_name }}(Extension):
name = "{{ cookiecutter.project_slug }}"

def on_extension_load(self):
print("MyExtension: extension is loaded")

def on_platform_start(self):
print("MyExtension: localstack is starting")

def on_platform_ready(self):
print("MyExtension: localstack is running")

def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
pass

def update_request_handlers(self, handlers: aws.CompositeHandler):
pass

def update_response_handlers(self, handlers: aws.CompositeResponseHandler):
pass

0 comments on commit 3ff9fab

Please sign in to comment.