Skip to content

Commit 12e8b9e

Browse files
authored
Merge pull request #19 from nens/shapely-support
add shapely support
2 parents e2e2d02 + 2ea1daa commit 12e8b9e

File tree

17 files changed

+472
-170
lines changed

17 files changed

+472
-170
lines changed

.github/workflows/lint.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010

1111
- name: Set up Python
12-
uses: actions/setup-python@v2
12+
uses: actions/setup-python@v4
1313
with:
14-
python-version: 3.8
14+
python-version: "3.10"
1515

16-
- name: Run black, flake8 and isort
17-
uses: pre-commit/[email protected]
16+
- name: Get changed files
17+
id: changed_files
18+
uses: tj-actions/changed-files@bab30c2299617f6615ec02a68b9a40d10bd21366 # v45.0.5
19+
with:
20+
files_ignore: "**/migrations/*"
21+
22+
- name: Run pre-commit checks
23+
uses: pre-commit/action@576ff52938d158a24ac7e009dfa94b1455e7df99 # v3.0.1
24+
with:
25+
extra_args: --files ${{ steps.changed_files.outputs.all_changed_files }}

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.10'
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install build
26+
27+
- name: Build package
28+
run: |
29+
python -m build
30+
31+
- name: Upload Github release
32+
uses: softprops/action-gh-release@v2
33+
with:
34+
files: dist/*
35+
body: "Release for ${{ github.ref }}"
36+
37+
- name: Test install built package
38+
run: |
39+
pip install dist/*.whl
40+
41+
- name: Publish package to PyPI
42+
uses: pypa/gh-action-pypi-publish@release/v1
43+
with:
44+
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}

.github/workflows/test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ jobs:
2929
fail-fast: false
3030
matrix:
3131
include:
32-
- display_name: "2020"
33-
python: 3.9
34-
os: ubuntu-22.04
35-
pins: ""
3632
- display_name: "2021"
3733
python: '3.10'
3834
os: ubuntu-22.04
@@ -64,8 +60,8 @@ jobs:
6460
- name: Install python dependencies
6561
shell: bash
6662
run: |
67-
pip install --disable-pip-version-check --upgrade pip setuptools wheel
68-
pip install -e .[numpy,test] ${{ matrix.pins }} ipython pytest pytest-asyncio flake8
63+
pip install --disable-pip-version-check --upgrade pip
64+
pip install -e .[numpy,shapely,test] ${{ matrix.pins }}
6965
pip list
7066
7167
- name: Run tests

.pre-commit-config.yaml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
default_language_version:
22
python: python3
33
repos:
4-
- repo: https://github.com/pycqa/isort
5-
rev: '5.13.2'
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: v0.7.3
66
hooks:
7-
- id: isort
8-
exclude: 'settings'
9-
- repo: https://github.com/psf/black
10-
rev: '23.12.0'
11-
hooks:
12-
- id: black
13-
exclude: 'migrations*|urls*|settings*|setup.py'
14-
- repo: https://github.com/pycqa/flake8
15-
rev: '6.1.0'
16-
hooks:
17-
- id: flake8
18-
# NB The "exclude" setting in setup.cfg is ignored by pre-commit
19-
exclude: 'migrations*|urls*|settings*'
7+
- id: ruff
8+
args: [ --fix ]
9+
- id: ruff # isort
10+
args: ["check", "--select", "I", "--fix"]
11+
- id: ruff-format

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM python:3.8
1+
FROM python:3.10
22

33
LABEL maintainer='jelle.prins <[email protected]>'
4-
LABEL py_version='3.8'
4+
LABEL py_version='3.10'
55

66
# Change the date to force rebuilding the whole image.
7-
ENV REFRESHED_AT 2023-12-19
7+
ENV REFRESHED_AT 2025-04-11
88

99
WORKDIR /code
1010
COPY requirements.txt /code/

HISTORY.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
0.2.1 (unreleased)
22
------------------
33

4-
- Nothing changed yet.
4+
- Add Shapely Geometry support.
55

66

77
0.2.0 (2024-01-02)

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Overview
2323
Features
2424
--------
2525
- Asyncio RPC client/server
26-
- Msgpack serialization with option to use own dataclasses (Python 3.8)
26+
- Msgpack serialization with option to use own dataclasses (Python 3.10)
2727
- Redis communication layer
2828
- Other serialization methods and communication layers can be added
2929

@@ -40,4 +40,4 @@ The examples can be run from this directory, for the dataclass example
4040

4141
Testing
4242
-------
43-
>>> docker-compose run pytest --cov=asyncio_rpc --cov-report=html
43+
>>> docker compose run asyncio_rpc pytest --cov=asyncio_rpc --cov-report=html

asyncio_rpc/commlayers/redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import redis.asyncio as async_redis
55

6-
from ..models import RPCBase, RPCResult, RPCStack, SERIALIZABLE_MODELS
6+
from ..models import SERIALIZABLE_MODELS, RPCBase, RPCResult, RPCStack
77
from .base import AbstractRPCCommLayer
88

99
RESULT_EXPIRE_TIME = 300 # seconds

asyncio_rpc/serialization/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from abc import ABC, abstractmethod
2+
from typing import Any
3+
4+
5+
class AbstractHandler(ABC):
6+
ext_type: int = None # Unique int
7+
obj_type: Any = None # Unique object type
8+
9+
@classmethod
10+
@abstractmethod
11+
def packb(cls, instance: Any) -> bytes:
12+
"""
13+
Pack the instance into bytes
14+
"""
15+
16+
@classmethod
17+
@abstractmethod
18+
def unpackb(cls, data: bytes) -> Any:
19+
"""
20+
Unpack the data back into an instance
21+
"""

asyncio_rpc/serialization/msgpack.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import dataclasses
2-
from abc import ABC, abstractmethod
32
from datetime import datetime
43
from io import BytesIO
54
from typing import Any
@@ -8,6 +7,8 @@
87
from lz4.frame import compress as lz4_compress
98
from lz4.frame import decompress as lz4_decompress
109

10+
from asyncio_rpc.serialization.base import AbstractHandler
11+
1112
try:
1213
import numpy as np
1314
except ImportError:
@@ -49,25 +50,6 @@ def register(obj_def):
4950
REGISTRY["ext_types"][obj_def.ext_type] = obj_def
5051

5152

52-
class AbstractHandler(ABC):
53-
ext_type: int = None # Unique int
54-
obj_type: Any = None # Unique object type
55-
56-
@classmethod
57-
@abstractmethod
58-
def packb(cls, instance: Any) -> bytes:
59-
"""
60-
Pack the instance into bytes
61-
"""
62-
63-
@classmethod
64-
@abstractmethod
65-
def unpackb(cls, data: bytes) -> Any:
66-
"""
67-
Unpack the data back into an instance
68-
"""
69-
70-
7153
if np is not None:
7254

7355
class NumpyArrayHandler(AbstractHandler):
@@ -202,11 +184,6 @@ def unpackb(cls, data):
202184
return slice(*loadb(data))
203185

204186

205-
# Register custom handlers
206-
register(DatetimeHandler)
207-
register(SliceHandler)
208-
209-
210187
def default(obj: Any):
211188
"""
212189
Serialize (dumpb) hook for obj types that msgpack does not
@@ -277,3 +254,33 @@ def loadb(
277254
raw=raw,
278255
strict_map_key=strict_map_key,
279256
)
257+
258+
259+
# Register custom handlers
260+
register(DatetimeHandler)
261+
register(SliceHandler)
262+
263+
264+
try:
265+
from asyncio_rpc.serialization.shapely_models import (
266+
GeometryCollectionHandler,
267+
LinearRingHandler,
268+
LineStringHandler,
269+
MultiLineStringHandler,
270+
MultiPointHandler,
271+
MultiPolygonHandler,
272+
PointHandler,
273+
PolygonHandler,
274+
)
275+
276+
register(PointHandler)
277+
register(LineStringHandler)
278+
register(LinearRingHandler)
279+
register(PolygonHandler)
280+
register(MultiPointHandler)
281+
register(MultiLineStringHandler)
282+
register(MultiPolygonHandler)
283+
register(GeometryCollectionHandler)
284+
except ImportError:
285+
# Shapely is not installed, skip shapely handlers
286+
pass

0 commit comments

Comments
 (0)