sqlalchemy-postgres-point 0.1.1__py3-none-any.whl → 0.2.0__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.
@@ -0,0 +1,56 @@
1
+ """
2
+ Alembic integration to automatically add imports for PointType in migration files.
3
+
4
+ This module hooks into Alembic's autogenerate system to automatically include
5
+ the necessary import statement when PointType is detected in models.
6
+
7
+ Usage:
8
+ Add this import to your alembic/env.py file:
9
+
10
+ import sqlalchemy_postgres_point.alembic_integration
11
+
12
+ Once added, `from sqlalchemy_postgres_point import PointType` will be automatically
13
+ included in generated migration files.
14
+ """
15
+
16
+ import alembic.autogenerate
17
+ import alembic.operations.ops
18
+ from sqlalchemy.types import UserDefinedType
19
+
20
+ from .point import PointType
21
+
22
+
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
+
29
+
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
+ ):
50
+ """
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sqlalchemy-postgres-point
3
- Version: 0.1.1
3
+ Version: 0.2.0
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
@@ -139,6 +139,33 @@ Run the test suite with:
139
139
  uv run pytest -q
140
140
  ```
141
141
 
142
+ ## Alembic Integration
143
+
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:
147
+
148
+ ```python
149
+ import sqlalchemy_postgres_point.alembic_integration
150
+ ```
151
+
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 ...
161
+ context.configure(
162
+ # ... other options ...
163
+ render_item=render_item,
164
+ )
165
+ ```
166
+
167
+ Once added, `from sqlalchemy_postgres_point import PointType` will be automatically included in generated migration files whenever a `PointType` column is detected.
168
+
142
169
  Development
143
170
  -----------
144
171
 
@@ -0,0 +1,7 @@
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,,
@@ -1,6 +0,0 @@
1
- sqlalchemy_postgres_point/__init__.py,sha256=BWlOd4qbAt4fM4cclR7ZrzZ-aib0f13KD3HIKmod2_s,208
2
- sqlalchemy_postgres_point/point.py,sha256=pb_aoNKwMOaKJ_xDvaIhfE-4VZKzyiPgOWmM6_z6xXo,2888
3
- sqlalchemy_postgres_point/utils.py,sha256=Loc9Q-xkntEKP3WSw48rZr64aqPWdM9huBlJnGuZa_8,1340
4
- sqlalchemy_postgres_point-0.1.1.dist-info/WHEEL,sha256=QnGI6l9Psotmz6XrseXTYT5jnZRJeTk4SwJP4aLtfdI,80
5
- sqlalchemy_postgres_point-0.1.1.dist-info/METADATA,sha256=X09nA3dHVTKB-wh3aratxcrxjdhtwnPJgHegIwzU7eA,5431
6
- sqlalchemy_postgres_point-0.1.1.dist-info/RECORD,,