sqlalchemy-postgres-point 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +1,32 @@
1
1
  """
2
- Alembic integration to automatically add imports for PointType in migration files.
2
+ Alembic integration for rendering PointType in generated migration files.
3
3
 
4
- This module hooks into Alembic's autogenerate system to automatically include
5
- the necessary import statement when PointType is detected in models.
4
+ Usage — add two lines to your alembic/env.py:
6
5
 
7
- Usage:
8
- Add this import to your alembic/env.py file:
6
+ from sqlalchemy_postgres_point.alembic_integration import render_item
9
7
 
10
- import sqlalchemy_postgres_point.alembic_integration
8
+ Then pass it to both context.configure() calls:
11
9
 
12
- Once added, `from sqlalchemy_postgres_point import PointType` will be automatically
13
- included in generated migration files.
14
- """
10
+ context.configure(
11
+ ...,
12
+ render_item=render_item,
13
+ )
15
14
 
16
- import alembic.autogenerate
17
- import alembic.operations.ops
18
- from sqlalchemy.types import UserDefinedType
15
+ Once wired up, ``from sqlalchemy_postgres_point import PointType`` will be
16
+ automatically included in generated migration files whenever PointType is used.
17
+ """
19
18
 
20
19
  from .point import PointType
21
20
 
22
21
 
23
- def render_point_type(type_, object_, autogen_context):
24
- """Render PointType in migration files with proper import."""
25
- # Add the import to the migration file
26
- autogen_context.imports.add("from sqlalchemy_postgres_point import PointType")
27
- return "PointType()"
28
-
22
+ def render_item(type_, obj, autogen_context):
23
+ """Alembic render_item hook that handles PointType columns.
29
24
 
30
- # Register the renderer for PointType
31
- alembic.autogenerate.render.renderers.dispatch_for(PointType, replace=True)(
32
- render_point_type
33
- )
34
-
35
-
36
- # Also register for UserDefinedType as a fallback if the class doesn't match exactly
37
- @alembic.autogenerate.render.renderers.dispatch_for(UserDefinedType, replace=True)
38
- def render_user_defined_type(type_, object_, autogen_context):
39
- if type(object_).__name__ == "PointType":
40
- return render_point_type(type_, object_, autogen_context)
41
- return False
42
-
43
-
44
- @alembic.autogenerate.comparators.dispatch_for("schema")
45
- def compare_point_types(
46
- autogen_context: alembic.autogenerate.api.AutogenContext,
47
- upgrade_ops: alembic.operations.ops.UpgradeOps,
48
- schema_names,
49
- ):
25
+ Returns "PointType()" and registers the import when the rendered item is a
26
+ PointType instance. Returns False for everything else so Alembic falls back
27
+ to its default rendering.
50
28
  """
51
- Hook into Alembic's schema comparison to detect PointType usage.
52
-
53
- This ensures the import is added even if PointType is used in existing
54
- columns that might not trigger the render hook directly.
55
- """
56
- pass
29
+ if type_ == "type" and isinstance(obj, PointType):
30
+ autogen_context.imports.add("from sqlalchemy_postgres_point import PointType")
31
+ return "PointType()"
32
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sqlalchemy-postgres-point
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Lightweight SQLAlchemy custom type for PostgreSQL POINT columns with tuple binding and an earth-distance comparator.
5
5
  Keywords: sqlalchemy,postgresql,point,geometry,geospatial,gis,database,types,earthdistance
6
6
  Author: Michael Bianco
@@ -15,18 +15,15 @@ Description-Content-Type: text/markdown
15
15
  ![GitHub CI Status](https://github.com/iloveitaly/sqlalchemy-postgres-point/actions/workflows/build_and_publish.yml/badge.svg)
16
16
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
17
17
 
18
- sqlalchemy-postgres-point
19
- =========================
18
+ # sqlalchemy-postgres-point
20
19
 
21
20
  Lightweight, pure-Python SQLAlchemy custom type for PostgreSQL `POINT` columns.
22
21
 
23
- Why
24
- ----
22
+ ## Why
25
23
 
26
24
  PostgreSQL has a native `POINT` type (stored internally as a pair of float8 values). SQLAlchemy does not ship a dedicated high-level type wrapper for simple geometric primitives. This package provides a very small `PointType` you can use immediately without pulling in a full spatial stack (e.g. PostGIS + GeoAlchemy2) when all you need is storing and retrieving `(longitude, latitude)` pairs.
27
25
 
28
- Features
29
- --------
26
+ ## Features
30
27
 
31
28
  * Simple `(lng, lat)` tuple binding and result conversion.
32
29
  * Safe NULL handling.
@@ -34,23 +31,13 @@ Features
34
31
  * Custom comparator exposing the PostgreSQL earth-distance `<@>` operator (returns a `Float`).
35
32
  * `cache_ok = True` for SQLAlchemy 2.x compilation caching.
36
33
 
37
- Installation
38
- ------------
39
-
40
- Using `uv` (recommended):
34
+ ## Installation
41
35
 
42
36
  ```bash
43
37
  uv add sqlalchemy-postgres-point
44
38
  ```
45
39
 
46
- Or with pip:
47
-
48
- ```bash
49
- pip install sqlalchemy-postgres-point
50
- ```
51
-
52
- Usage
53
- -----
40
+ ## Usage
54
41
 
55
42
  ```python
56
43
  from sqlalchemy import Column, Integer
@@ -119,81 +106,55 @@ DROP EXTENSION IF EXISTS cube;
119
106
  """)
120
107
  ```
121
108
 
122
- **Integration Steps:**
109
+ #### Integration Steps
123
110
 
124
111
  1. Generate a new migration: `alembic revision -m "add_postgres_extensions"`
125
112
  2. Copy the `upgrade()` and `downgrade()` functions above into your new migration file
126
113
  3. Run the migration: `alembic upgrade head`
127
114
 
128
- Returned Python Values
129
- ----------------------
115
+ ## Returned Python Values
130
116
 
131
117
  Values are loaded as a 2-tuple of floats `(lng, lat)` or `None` when NULL.
132
118
 
133
- Testing
134
- -------
135
-
136
- Run the test suite with:
137
-
138
- ```bash
139
- uv run pytest -q
140
- ```
141
-
142
119
  ## Alembic Integration
143
120
 
144
- When using `PointType` in your models, you can automatically include the necessary imports in migration files by updating your `alembic/env.py` file.
145
-
146
- First, import the integration module:
121
+ To ensure generated migration files include the correct `PointType` import, pass the provided `render_item` hook to `context.configure()` in your `alembic/env.py`:
147
122
 
148
123
  ```python
149
- import sqlalchemy_postgres_point.alembic_integration
150
- ```
124
+ from sqlalchemy_postgres_point.alembic_integration import render_item
151
125
 
152
- Then, ensure your `context.configure` call includes a `render_item` hook to handle the `PointType`:
153
-
154
- ```python
155
- def render_item(type_, obj, autogen_context):
156
- if type_ == "type" and type(obj).__name__ == "PointType":
157
- return sqlalchemy_postgres_point.alembic_integration.render_point_type(obj, obj, autogen_context)
158
- return False
159
-
160
- # ... in run_migrations_online and run_migrations_offline ...
126
+ # in run_migrations_online and run_migrations_offline:
161
127
  context.configure(
162
128
  # ... other options ...
163
129
  render_item=render_item,
164
130
  )
165
131
  ```
166
132
 
167
- Once added, `from sqlalchemy_postgres_point import PointType` will be automatically included in generated migration files whenever a `PointType` column is detected.
133
+ Once wired up, `from sqlalchemy_postgres_point import PointType` will be automatically included in generated migration files whenever a `PointType` column is detected.
168
134
 
169
- Development
170
- -----------
135
+ ### Chaining `render_item`
171
136
 
172
- After cloning:
137
+ It's insane to me, but you have to chain multiple `render_item` instances you may have yourself.
173
138
 
174
- ```bash
175
- uv sync # installs runtime + dev deps
176
- uv run pytest -q
177
- ```
139
+ ```python
140
+ from sqlalchemy_postgres_point.alembic_integration import render_item as render_point
178
141
 
179
- Project Structure
180
- -----------------
142
+ def render_item(type_, obj, autogen_context):
143
+ return (
144
+ render_point(type_, obj, autogen_context)
145
+ or other_package.render_item(type_, obj, autogen_context)
146
+ or False
147
+ )
148
+ ```
181
149
 
182
- * `sqlalchemy_postgres_point/point.py` – Implementation of `PointType`.
183
- * `tests/test_point.py` – Unit tests for processors and comparator.
150
+ Or you could use something like [`some_fn`](https://funcy.readthedocs.io/en/stable/funcs.html#some_fn) to make this even cleaner.
184
151
 
185
- Limitations / Notes
186
- -------------------
152
+ ## Limitations / Notes
187
153
 
188
- * No automatic validation of longitude/latitude ranges; add your own if required.
154
+ * Coordinates are validated on both write and read: longitude must be within `[-180, 180]`, latitude within `[-90, 90]`, and non-finite values (`NaN`, `inf`) are rejected with a `ValueError`.
189
155
  * Uses simple textual representation `(lng,lat)` accepted by PostgreSQL `POINT` input parser.
190
156
  * If you need advanced spatial indexing / SRID support, look at GeoAlchemy2/PostGIS instead.
191
157
 
192
- License
193
- -------
194
-
195
- MIT (see your project's LICENSE file if added later). Contributions welcome.
196
-
197
158
  ---
198
159
 
199
160
  *This project was created from [iloveitaly/python-package-template](https://github.com/iloveitaly/python-package-template)*
@@ -0,0 +1,7 @@
1
+ sqlalchemy_postgres_point/__init__.py,sha256=BWlOd4qbAt4fM4cclR7ZrzZ-aib0f13KD3HIKmod2_s,208
2
+ sqlalchemy_postgres_point/alembic_integration.py,sha256=T7VzTFNAlsI3_HMnnpwWNWTuXisJjfTxYlo8YW6KDE4,1015
3
+ sqlalchemy_postgres_point/point.py,sha256=pb_aoNKwMOaKJ_xDvaIhfE-4VZKzyiPgOWmM6_z6xXo,2888
4
+ sqlalchemy_postgres_point/utils.py,sha256=Loc9Q-xkntEKP3WSw48rZr64aqPWdM9huBlJnGuZa_8,1340
5
+ sqlalchemy_postgres_point-0.2.1.dist-info/WHEEL,sha256=AKeAJsuKQDVE1yEMr94YEC7FtwPuFZZw2DmbXPmgtaE,81
6
+ sqlalchemy_postgres_point-0.2.1.dist-info/METADATA,sha256=cJGmSMFbUeqQsNqkph63jiuFIWnX16Zraa5vY9l_Nc8,6041
7
+ sqlalchemy_postgres_point-0.2.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.10.2
2
+ Generator: uv 0.11.10
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,7 +0,0 @@
1
- sqlalchemy_postgres_point/__init__.py,sha256=BWlOd4qbAt4fM4cclR7ZrzZ-aib0f13KD3HIKmod2_s,208
2
- sqlalchemy_postgres_point/alembic_integration.py,sha256=qaMk733hniatgGHwJXl0S5cKIsu_tno4JRvJ_MDLtPs,1840
3
- sqlalchemy_postgres_point/point.py,sha256=pb_aoNKwMOaKJ_xDvaIhfE-4VZKzyiPgOWmM6_z6xXo,2888
4
- sqlalchemy_postgres_point/utils.py,sha256=Loc9Q-xkntEKP3WSw48rZr64aqPWdM9huBlJnGuZa_8,1340
5
- sqlalchemy_postgres_point-0.2.0.dist-info/WHEEL,sha256=QnGI6l9Psotmz6XrseXTYT5jnZRJeTk4SwJP4aLtfdI,80
6
- sqlalchemy_postgres_point-0.2.0.dist-info/METADATA,sha256=4haIARMrgBsJi5JKaBp01PZ5Cuv8EnHr-ocd6XUL4hA,6367
7
- sqlalchemy_postgres_point-0.2.0.dist-info/RECORD,,