Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mm committed Jan 5, 2024
2 parents f692fbb + 5c04328 commit a26eccb
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 64 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.0
rev: 23.12.1
hooks:
- id: black
exclude: \.py-tpl$
Expand All @@ -9,17 +9,17 @@ repos:
hooks:
- id: blacken-docs
additional_dependencies:
- black==23.10.0
- black==23.12.1
files: 'docs/.*\.txt$'
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.52.0
rev: v8.56.0
hooks:
- id: eslint
8 changes: 2 additions & 6 deletions django/contrib/gis/db/backends/mysql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class MySQLGISSchemaEditor(DatabaseSchemaEditor):
sql_add_spatial_index = "CREATE SPATIAL INDEX %(index)s ON %(table)s(%(column)s)"
sql_drop_spatial_index = "DROP INDEX %(index)s ON %(table)s"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -56,11 +55,8 @@ def add_field(self, model, field):

def remove_field(self, model, field):
if isinstance(field, GeometryField) and field.spatial_index:
qn = self.connection.ops.quote_name
sql = self.sql_drop_spatial_index % {
"index": qn(self._create_spatial_index_name(model, field)),
"table": qn(model._meta.db_table),
}
index_name = self._create_spatial_index_name(model, field)
sql = self._delete_index_sql(model, index_name)
try:
self.execute(sql)
except OperationalError:
Expand Down
11 changes: 2 additions & 9 deletions django/contrib/gis/db/backends/oracle/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class OracleGISSchemaEditor(DatabaseSchemaEditor):
"CREATE INDEX %(index)s ON %(table)s(%(column)s) "
"INDEXTYPE IS MDSYS.SPATIAL_INDEX"
)
sql_drop_spatial_index = "DROP INDEX %(index)s"
sql_clear_geometry_table_metadata = (
"DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = %(table)s"
)
Expand Down Expand Up @@ -98,14 +97,8 @@ def remove_field(self, model, field):
}
)
if field.spatial_index:
self.execute(
self.sql_drop_spatial_index
% {
"index": self.quote_name(
self._create_spatial_index_name(model, field)
),
}
)
index_name = self._create_spatial_index_name(model, field)
self.execute(self._delete_index_sql(model, index_name))
super().remove_field(model, field)

def run_geometry_sql(self):
Expand Down
5 changes: 4 additions & 1 deletion django/contrib/gis/db/backends/spatialite/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):

function_names = {
"AsWKB": "St_AsBinary",
"BoundingCircle": "GEOSMinimumBoundingCircle",
"ForcePolygonCW": "ST_ForceLHR",
"FromWKB": "ST_GeomFromWKB",
"FromWKT": "ST_GeomFromText",
Expand All @@ -80,9 +81,11 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):

@cached_property
def unsupported_functions(self):
unsupported = {"BoundingCircle", "GeometryDistance", "IsEmpty", "MemSize"}
unsupported = {"GeometryDistance", "IsEmpty", "MemSize"}
if not self.geom_lib_version():
unsupported |= {"Azimuth", "GeoHash", "MakeValid"}
if self.spatial_version < (5, 1):
unsupported |= {"BoundingCircle"}
return unsupported

@cached_property
Expand Down
7 changes: 7 additions & 0 deletions django/contrib/gis/db/models/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ def as_oracle(self, compiler, connection, **extra_context):
compiler, connection, **extra_context
)

def as_sqlite(self, compiler, connection, **extra_context):
clone = self.copy()
clone.set_source_expressions([self.get_source_expressions()[0]])
return super(BoundingCircle, clone).as_sqlite(
compiler, connection, **extra_context
)


class Centroid(OracleToleranceMixin, GeomOutputGeoFunc):
arity = 1
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/contrib/gis/db-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ Function PostGIS Oracle MariaDB MySQL
:class:`AsWKB` X X X X X
:class:`AsWKT` X X X X X
:class:`Azimuth` X X (LWGEOM/RTTOPO)
:class:`BoundingCircle` X X
:class:`BoundingCircle` X X X (≥ 5.1)
:class:`Centroid` X X X X X
:class:`ClosestPoint` X X
:class:`Difference` X X X X X
Expand Down
7 changes: 6 additions & 1 deletion docs/ref/contrib/gis/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,18 @@ south = ``π``; west = ``3π/2``.

*Availability*: `PostGIS <https://postgis.net/docs/ST_MinimumBoundingCircle.html>`__,
`Oracle <https://docs.oracle.com/en/database/oracle/oracle-database/21/spatl/
SDO_GEOM-reference.html#GUID-82A61626-BB64-4793-B53D-A0DBEC91831A>`_
SDO_GEOM-reference.html#GUID-82A61626-BB64-4793-B53D-A0DBEC91831A>`_,
SpatiaLite 5.1+

Accepts a single geographic field or expression and returns the smallest circle
polygon that can fully contain the geometry.

The ``num_seg`` parameter is used only on PostGIS.

.. versionchanged:: 5.1

SpatiaLite 5.1+ support was added.

``Centroid``
============

Expand Down
3 changes: 2 additions & 1 deletion docs/releases/5.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Minor features
:mod:`django.contrib.gis`
~~~~~~~~~~~~~~~~~~~~~~~~~

* ...
* :class:`~django.contrib.gis.db.models.functions.BoundingCircle` is now
supported on SpatiaLite 5.1+.

:mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"npm": ">=1.3.0"
},
"devDependencies": {
"eslint": "^8.52.0",
"puppeteer": "^21.4.0",
"eslint": "^8.56.0",
"puppeteer": "^21.7.0",
"grunt": "^1.6.1",
"grunt-cli": "^1.4.3",
"grunt-contrib-qunit": "^8.0.1",
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ build-backend = 'setuptools.build_meta'
[tool.black]
target-version = ['py310']
force-exclude = 'tests/test_runner_apps/tagged/tests_syntax_error.py'

[tool.isort]
profile = 'black'
default_section = 'THIRDPARTY'
known_first_party = 'django'
28 changes: 0 additions & 28 deletions scripts/rpm-install.sh

This file was deleted.

9 changes: 0 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ console_scripts =
argon2 = argon2-cffi >= 19.1.0
bcrypt = bcrypt

[bdist_rpm]
doc_files = docs extras AUTHORS INSTALL LICENSE README.rst
install_script = scripts/rpm-install.sh

[flake8]
exclude = build,.git,.tox,./tests/.env
extend-ignore = E203
Expand All @@ -63,8 +59,3 @@ per-file-ignores =
django/core/cache/backends/base.py:W601
django/core/cache/backends/redis.py:W601
tests/cache/tests.py:W601

[isort]
profile = black
default_section = THIRDPARTY
known_first_party = django
7 changes: 6 additions & 1 deletion tests/gis_tests/geoapp/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ def circle_num_points(num_seg):
# num_seg is the number of segments per quarter circle.
return (4 * num_seg) + 1

expected_areas = (169, 136) if connection.ops.postgis else (171, 126)
if connection.ops.postgis:
expected_areas = (169, 136)
elif connection.ops.spatialite:
expected_areas = (168, 135)
else: # Oracle.
expected_areas = (171, 126)
qs = Country.objects.annotate(
circle=functions.BoundingCircle("mpoly")
).order_by("name")
Expand Down

0 comments on commit a26eccb

Please sign in to comment.