Skip to content

Commit 73dc3db

Browse files
committed
feat: added typer entrypoint pluggability
1 parent 3e1fc49 commit 73dc3db

8 files changed

Lines changed: 187 additions & 693 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ MANIFEST
5454
# Per-project virtualenvs
5555
.venv*/
5656
.conda*/
57+
58+
eodm_plugin/

docs/plugins.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Plugins
2+
3+
`eodm` offers an option to add plugins as there is a wide array of extract, transform,
4+
load functions in EO that are possible. Below is a minimal transform example
5+
example.
6+
7+
`pyproject.toml`
8+
9+
```toml
10+
[project]
11+
name = "eodm_plugin"
12+
version = "0.0.0"
13+
dependencies = [
14+
"eodm"
15+
]
16+
17+
[project.entry-points.'eodm.plugins'] # the entry-point group is the `eodm.plugins`
18+
transform = 'plugins:app' # the plugin finds `extract`, `transform` or `load` entry points with the name `app` in the package `plugins`
19+
```
20+
21+
`eodm_plugin/plugins.py`
22+
23+
```python
24+
import typer
25+
26+
app = typer.Typer(name="plugin", no_args_is_help=True)
27+
28+
29+
@app.command()
30+
def test():
31+
print("This is a plugin")
32+
```
33+
34+
The application gets extended with the group called `plugin` (same as the typer app name)
35+
and a single command `test`:
36+
37+
```shell
38+
eodm transform plugin test
39+
```
40+
41+
The plugin should probaly work by accepting and outputting STAC items, in order to create
42+
a full pipeline.
43+
44+
## Docker
45+
46+
In addition to creating the plugin, you may need a custom docker image. In that case simply
47+
extend the existing docker image and install your plugin.
48+
49+
```Dockerfile
50+
FROM ghcr.io/geopython/eodm
51+
52+
WORKDIR /app
53+
COPY . .
54+
55+
RUN pip3 install .
56+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ site_name: eodm - EO Data Mover
33
nav:
44
- Home: index.md
55
- Examples: examples.md
6+
- Plugins: plugins.md
67
- CLI: cli.md
78
- API: api.md
89

poetry.lock

Lines changed: 95 additions & 570 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ fsspec = "^2024.3.1"
1515
s3fs = "^2024.3.1"
1616
pystac = "^1.10.0"
1717
pystac-client = "^0.7.7"
18-
odc-stac = "^0.3.9"
19-
rioxarray = "^0.15.5"
20-
rio-cogeo = "^5.3.0"
21-
rio-stac = "^0.9.0"
2218
python-dateutil = "^2.9.0.post0"
2319
lxml = "^5.3.0"
2420
geojson-pydantic = "^1.1.2"
21+
rio-stac = "^0.10.1"
22+
rasterio = "^1.4.3"
2523

2624

2725
[tool.poetry.group.dev.dependencies]
@@ -50,6 +48,7 @@ version_scheme = "semver"
5048
version_provider = "poetry"
5149
update_changelog_on_bump = true
5250
major_version_zero = true
51+
5352
[build-system]
5453
requires = ["poetry-core"]
5554
build-backend = "poetry.core.masonry.api"

src/eodm/__main__.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
1-
import pkg_resources
1+
import importlib
2+
import importlib.metadata
3+
import sys
4+
25
import typer
36
from dotenv import load_dotenv
47

58
from .cli.extract import app as extract
69
from .cli.load import app as load
710
from .cli.transform import app as transform
811

12+
if sys.version_info < (3, 10):
13+
from importlib_metadata import entry_points
14+
else:
15+
from importlib.metadata import entry_points
16+
17+
discovered_plugins = entry_points(group="eodm.plugins")
918
CLI_NAME = "eodm"
1019

1120
app = typer.Typer(name=CLI_NAME, no_args_is_help=True)
21+
22+
try:
23+
extract_plugins = discovered_plugins["extract"].load()
24+
extract.add_typer(extract_plugins)
25+
except KeyError:
26+
pass
1227
app.add_typer(extract)
28+
29+
try:
30+
transform_plugins = discovered_plugins["transform"].load()
31+
transform.add_typer(transform_plugins)
32+
except KeyError:
33+
pass
1334
app.add_typer(transform)
35+
36+
try:
37+
load_plugins = discovered_plugins["load"].load()
38+
load.add_typer(load_plugins)
39+
except KeyError:
40+
pass
1441
app.add_typer(load)
42+
1543
load_dotenv()
1644

1745

@@ -20,7 +48,7 @@ def version():
2048
"""
2149
Prints software version
2250
"""
23-
version = pkg_resources.get_distribution(CLI_NAME).version
51+
version = version = importlib.metadata.version("eodm")
2452
print(version)
2553

2654

src/eodm/cli/transform/apps/data.py

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/eodm/cli/transform/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import typer
22

3-
from .apps.data import app as data
43
from .apps.metadata import app as metadata
54

65
app = typer.Typer(
@@ -9,5 +8,4 @@
98
help="Commands for data and metadata transformations",
109
)
1110

12-
app.add_typer(data, name="data", help="Commands for data transformations")
1311
app.add_typer(metadata, name="metadata", help="Commands for metadata transformations")

0 commit comments

Comments
 (0)