From 0493cf6fe69061a24c51f32f8ca8949ca9614f2d Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Mon, 16 Oct 2023 09:39:00 +1300 Subject: [PATCH 1/3] Fix end-of-file --- DEPENDENCIES.txt | 1 - ci/install_libspatialindex.bat | 2 -- docs/source/changes.txt | 1 - docs/source/history.txt | 2 +- docs/source/install.txt | 1 - docs/source/performance.txt | 1 - tests/rungrind.dist | 1 - 7 files changed, 1 insertion(+), 8 deletions(-) diff --git a/DEPENDENCIES.txt b/DEPENDENCIES.txt index 0b1c4402..4f006967 100644 --- a/DEPENDENCIES.txt +++ b/DEPENDENCIES.txt @@ -2,4 +2,3 @@ - setuptools - libspatialindex C library 1.8.5+: https://libspatialindex.org/ - diff --git a/ci/install_libspatialindex.bat b/ci/install_libspatialindex.bat index 33ab8c34..71aedf49 100755 --- a/ci/install_libspatialindex.bat +++ b/ci/install_libspatialindex.bat @@ -25,5 +25,3 @@ rmdir /Q /S bin dir %~dp0\..\rtree\ dir %~dp0\..\rtree\lib - - diff --git a/docs/source/changes.txt b/docs/source/changes.txt index c0c680eb..f24c4d58 100644 --- a/docs/source/changes.txt +++ b/docs/source/changes.txt @@ -122,4 +122,3 @@ available as a result of this refactoring. - Change license to LGPL. - Moved from Pleiades to GIS-Python repo. - Initial release. - diff --git a/docs/source/history.txt b/docs/source/history.txt index 33443db5..b1628f10 100644 --- a/docs/source/history.txt +++ b/docs/source/history.txt @@ -44,4 +44,4 @@ and can now evolve separately. Rtree is pure Python as of 0.6.0+. .. _`R-trees`: http://en.wikipedia.org/wiki/R-tree .. _`ctypes`: http://docs.python.org/library/ctypes.html .. _`libspatialindex`: https://libspatialindex.org/ -.. _`Rtree`: http://rtree.github.com \ No newline at end of file +.. _`Rtree`: http://rtree.github.com diff --git a/docs/source/install.txt b/docs/source/install.txt index 518a0b01..94e57505 100644 --- a/docs/source/install.txt +++ b/docs/source/install.txt @@ -43,4 +43,3 @@ is as easy as:: .. _`Rtree`: http://pypi.python.org/pypi/Rtree/ .. _`libspatialindex`: https://libspatialindex.org/ - diff --git a/docs/source/performance.txt b/docs/source/performance.txt index ba5029ad..71ca9504 100644 --- a/docs/source/performance.txt +++ b/docs/source/performance.txt @@ -75,4 +75,3 @@ Use the correct query method Use :py:meth:`~rtree.index.Index.count` if you only need a count and :py:meth:`~rtree.index.Index.intersection` if you only need the ids. Otherwise, lots of data may potentially be copied. - diff --git a/tests/rungrind.dist b/tests/rungrind.dist index c1d7d4ef..b397f017 100644 --- a/tests/rungrind.dist +++ b/tests/rungrind.dist @@ -1,3 +1,2 @@ #!/bin/sh valgrind --tool=memcheck --leak-check=yes --suppressions=/home/sean/Projects/valgrind-python.supp python test_doctests.py - From a218a97ca33afbeb18109dda77d8a7363d29465f Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Mon, 16 Oct 2023 09:40:10 +1300 Subject: [PATCH 2/3] Remove trailing whitespace --- DEPENDENCIES.txt | 2 +- LICENSE.txt | 2 +- ci/CMakeLists.txt | 4 ++-- ci/install_libspatialindex.bat | 2 +- docs/source/class.txt | 4 ++-- docs/source/history.txt | 8 +++---- docs/source/index.txt | 6 ++--- docs/source/install.txt | 12 +++++----- docs/source/performance.txt | 16 ++++++------- docs/source/tutorial.txt | 42 +++++++++++++++++----------------- 10 files changed, 49 insertions(+), 49 deletions(-) diff --git a/DEPENDENCIES.txt b/DEPENDENCIES.txt index 4f006967..55bd4490 100644 --- a/DEPENDENCIES.txt +++ b/DEPENDENCIES.txt @@ -1,4 +1,4 @@ - python 3.8+ - setuptools -- libspatialindex C library 1.8.5+: +- libspatialindex C library 1.8.5+: https://libspatialindex.org/ diff --git a/LICENSE.txt b/LICENSE.txt index ef65d8a1..90e40d42 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018: Sean C. Gillies, Howard Butler and contributors +Copyright (c) 2018: Sean C. Gillies, Howard Butler and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/ci/CMakeLists.txt b/ci/CMakeLists.txt index 0a21d64f..aec6a080 100644 --- a/ci/CMakeLists.txt +++ b/ci/CMakeLists.txt @@ -23,7 +23,7 @@ mark_as_advanced(CMAKE_VERBOSE_MAKEFILE) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH}) # Make string comparison in cmake behave like you'd expect -cmake_policy(SET CMP0054 NEW) +cmake_policy(SET CMP0054 NEW) if (WIN32) if(${CMAKE_VERSION} VERSION_GREATER "3.14.5") @@ -72,7 +72,7 @@ if(WIN32) endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) endif() endif() - + set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) include (CheckFunctionExists) diff --git a/ci/install_libspatialindex.bat b/ci/install_libspatialindex.bat index 71aedf49..c08d3677 100755 --- a/ci/install_libspatialindex.bat +++ b/ci/install_libspatialindex.bat @@ -2,7 +2,7 @@ python -c "import sys; print(sys.version)" set SIDX_VERSION=1.9.3 -curl -OL "https://github.com/libspatialindex/libspatialindex/archive/%SIDX_VERSION%.zip" +curl -OL "https://github.com/libspatialindex/libspatialindex/archive/%SIDX_VERSION%.zip" tar xvf "%SIDX_VERSION%.zip" diff --git a/docs/source/class.txt b/docs/source/class.txt index 89bc281b..ebe20e3a 100644 --- a/docs/source/class.txt +++ b/docs/source/class.txt @@ -5,9 +5,9 @@ Class Documentation .. autoclass:: rtree.index.Index :members: __init__, insert, intersection, nearest, delete, bounds, count, close, dumps, loads - + .. autoclass:: rtree.index.Property - :members: + :members: .. autoclass:: rtree.index.Item :members: __init__, bbox, object diff --git a/docs/source/history.txt b/docs/source/history.txt index b1628f10..9a286296 100644 --- a/docs/source/history.txt +++ b/docs/source/history.txt @@ -24,11 +24,11 @@ of new features and much more flexibility. See :ref:`changes` for more detail. .. note:: A significant bug in the 1.6.1+ `libspatialindex`_ C API was found where it was using unsigned integers for index entry IDs instead of signed - integers. Because `Rtree`_ appeared to be the only significant user of the - C API at this time, it was corrected immediately. You should update - immediately and re-insert data into new indexes if this is an important + integers. Because `Rtree`_ appeared to be the only significant user of the + C API at this time, it was corrected immediately. You should update + immediately and re-insert data into new indexes if this is an important consideration for your application. - + Rtree 0.5.0 included a C library that is now the C API for libspatialindex and is part of that source tree. The code bases are independent from each other and can now evolve separately. Rtree is pure Python as of 0.6.0+. diff --git a/docs/source/index.txt b/docs/source/index.txt index 116955d1..1f771ee5 100644 --- a/docs/source/index.txt +++ b/docs/source/index.txt @@ -3,8 +3,8 @@ Rtree: Spatial indexing for Python ------------------------------------------------------------------------------ -`Rtree`_ is a `ctypes`_ Python wrapper of `libspatialindex`_ that provides a -number of advanced spatial indexing features for the spatially curious Python +`Rtree`_ is a `ctypes`_ Python wrapper of `libspatialindex`_ that provides a +number of advanced spatial indexing features for the spatially curious Python user. These features include: * Nearest neighbor search @@ -21,7 +21,7 @@ Documentation .. toctree:: :maxdepth: 2 - + install tutorial class diff --git a/docs/source/install.txt b/docs/source/install.txt index 94e57505..377f6703 100644 --- a/docs/source/install.txt +++ b/docs/source/install.txt @@ -3,7 +3,7 @@ Installation ------------------------------------------------------------------------------ -\*nix +\*nix .............................................................................. First, download and install version 1.8.5+ of the `libspatialindex`_ library from: @@ -14,8 +14,8 @@ The library is a GNU-style build, so it is a matter of:: $ ./configure; make; make install -You may need to run the ``ldconfig`` command after installing the library to -ensure that applications can find it at startup time. +You may need to run the ``ldconfig`` command after installing the library to +ensure that applications can find it at startup time. At this point you can get Rtree 0.7.0 via easy_install:: @@ -29,11 +29,11 @@ You can build and test in place like:: $ python setup.py test -Windows +Windows .............................................................................. -The Windows DLLs of `libspatialindex`_ are pre-compiled in -windows installers that are available from `PyPI`_. Installation on Windows +The Windows DLLs of `libspatialindex`_ are pre-compiled in +windows installers that are available from `PyPI`_. Installation on Windows is as easy as:: c:\python2x\scripts\easy_install.exe Rtree diff --git a/docs/source/performance.txt b/docs/source/performance.txt index 71ca9504..44d4a99e 100644 --- a/docs/source/performance.txt +++ b/docs/source/performance.txt @@ -3,7 +3,7 @@ Performance ------------------------------------------------------------------------------ -See the `tests/benchmarks.py`_ file for a comparison of various query methods +See the `tests/benchmarks.py`_ file for a comparison of various query methods and how much acceleration can be obtained from using Rtree. .. _tests/benchmarks.py: https://raw.github.com/Rtree/Rtree/master/tests/benchmarks.py @@ -12,19 +12,19 @@ There are a few simple things that will improve performance. Use stream loading .............................................................................. - + This will substantially (orders of magnitude in many cases) improve performance over :py:meth:`~rtree.index.Index.insert` by allowing the data to -be pre-sorted +be pre-sorted -:: +:: >>> def generator_function(somedata): ... for i, obj in enumerate(somedata): ... yield (i, (obj.xmin, obj.ymin, obj.xmax, obj.ymax), obj) >>> r = index.Index(generator_function(somedata)) -After bulk loading the index, you can then insert additional records into +After bulk loading the index, you can then insert additional records into the index using :py:meth:`~rtree.index.Index.insert` Override :py:data:`~rtree.index.Index.dumps` to use the highest pickle protocol @@ -42,7 +42,7 @@ Override :py:data:`~rtree.index.Index.dumps` to use the highest pickle protocol Use objects='raw' ............................................................................... -In any :py:meth:`~rtree.index.Index.intersection` or +In any :py:meth:`~rtree.index.Index.intersection` or :py:meth:`~rtree.index.Index.nearest` or query, use objects='raw' keyword argument :: @@ -61,7 +61,7 @@ Adjust :py:class:`rtree.index.Property` appropriate to your index. * Increase the :py:data:`~rtree.index.Property.fill_factor` to something near 0.9. Smaller fill factors mean more splitting, which means more nodes. This may be bad or good depending on your usage. - + Limit dimensionality to the amount you need ............................................................................... @@ -71,7 +71,7 @@ point comparisons for each query, search, and insert operation of the index. Use the correct query method ............................................................................... - + Use :py:meth:`~rtree.index.Index.count` if you only need a count and :py:meth:`~rtree.index.Index.intersection` if you only need the ids. Otherwise, lots of data may potentially be copied. diff --git a/docs/source/tutorial.txt b/docs/source/tutorial.txt index 4829b960..45f4c489 100644 --- a/docs/source/tutorial.txt +++ b/docs/source/tutorial.txt @@ -3,21 +3,21 @@ Tutorial ------------------------------------------------------------------------------ -This tutorial demonstrates how to take advantage of :ref:`Rtree ` for -querying data that have a spatial component that can be modeled as bounding +This tutorial demonstrates how to take advantage of :ref:`Rtree ` for +querying data that have a spatial component that can be modeled as bounding boxes. Creating an index .............................................................................. -The following section describes the basic instantiation and usage of +The following section describes the basic instantiation and usage of :ref:`Rtree `. Import ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -After :ref:`installing ` :ref:`Rtree `, you should be able to +After :ref:`installing ` :ref:`Rtree `, you should be able to open up a Python prompt and issue the following:: >>> from rtree import index @@ -30,21 +30,21 @@ with the index. Construct an instance ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -After importing the index module, construct an index with the default +After importing the index module, construct an index with the default construction:: >>> idx = index.Index() .. note:: - While the default construction is useful in many cases, if you want to - manipulate how the index is constructed you will need pass in a - :py:class:`rtree.index.Property` instance when creating the index. + While the default construction is useful in many cases, if you want to + manipulate how the index is constructed you will need pass in a + :py:class:`rtree.index.Property` instance when creating the index. Create a bounding box ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -After instantiating the index, create a bounding box that we can +After instantiating the index, create a bounding box that we can insert into the index:: >>> left, bottom, right, top = (0.0, 0.0, 1.0, 1.0) @@ -67,16 +67,16 @@ Insert an entry into the index:: .. note:: - Entries that are inserted into the index are not unique in either the - sense of the `id` or of the bounding box that is inserted with index - entries. If you need to maintain uniqueness, you need to manage that before + Entries that are inserted into the index are not unique in either the + sense of the `id` or of the bounding box that is inserted with index + entries. If you need to maintain uniqueness, you need to manage that before inserting entries into the Rtree. .. note:: Inserting a point, i.e. where left == right && top == bottom, will essentially insert a single point entry into the index instead of copying - extra coordinates and inserting them. There is no shortcut to explicitly + extra coordinates and inserting them. There is no shortcut to explicitly insert a single point, however. Query the index @@ -95,7 +95,7 @@ Given a query window, return ids that are contained within the window:: >>> list(idx.intersection((1.0, 1.0, 2.0, 2.0))) [0] -Given a query window that is beyond the bounds of data we have in the +Given a query window that is beyond the bounds of data we have in the index:: >>> list(idx.intersection((1.0000001, 1.0000001, 2.0, 2.0))) @@ -106,7 +106,7 @@ Nearest Neighbors The following finds the 1 nearest item to the given bounds. If multiple items are of equal distance to the bounds, both are returned:: - + >>> idx.insert(1, (left, bottom, right, top)) >>> list(idx.nearest((1.0000001, 1.0000001, 2.0, 2.0), 1)) [0, 1] @@ -138,10 +138,10 @@ to intersection:: Serializing your index to a file .............................................................................. -One of :ref:`Rtree `'s most useful properties is the ability to -serialize Rtree indexes to disk. These include the clustered indexes +One of :ref:`Rtree `'s most useful properties is the ability to +serialize Rtree indexes to disk. These include the clustered indexes described :ref:`here `:: - + >>> file_idx = index.Rtree('rtree') >>> file_idx.insert(1, (left, bottom, right, top)) >>> file_idx.insert(2, (left - 1.0, bottom - 1.0, right + 1.0, top + 1.0)) @@ -191,7 +191,7 @@ stored on disk as the files ``3d_index.data`` and ``3d_index.index``:: >>> p = index.Property() >>> p.dimension = 3 >>> p.dat_extension = 'data' - >>> p.idx_extension = 'index' + >>> p.idx_extension = 'index' >>> idx3d = index.Index('3d_index',properties=p) >>> idx3d.insert(1, (0, 60, 23.0, 0, 60, 42.0)) >>> idx3d.intersection( (-1, 62, 22, -1, 62, 43)) @@ -200,9 +200,9 @@ stored on disk as the files ``3d_index.data`` and ``3d_index.index``:: ZODB and Custom Storages .............................................................................. -https://mail.zope.org/pipermail/zodb-dev/2010-June/013491.html contains a custom +https://mail.zope.org/pipermail/zodb-dev/2010-June/013491.html contains a custom storage backend for `ZODB`_ .. _ZODB: http://www.zodb.org/ -.. _`libspatialindex`: https://libspatialindex.org/ +.. _`libspatialindex`: https://libspatialindex.org/ From 3fe35447a973d131bafda27fe96e9f5e9725abf4 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Mon, 16 Oct 2023 09:44:01 +1300 Subject: [PATCH 3/3] Add pre-commit, replace GHA workflows, remove flake8 config --- .flake8 | 2 -- .github/workflows/build.yml | 49 ++----------------------------------- .pre-commit-config.yaml | 19 ++++++++++++++ 3 files changed, 21 insertions(+), 49 deletions(-) delete mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 2bcd70e3..00000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max-line-length = 88 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d13438ee..e43b3413 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,57 +15,12 @@ on: - cron: '0 6 * * 1' jobs: - black: - name: black + pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - name: Setup - run: pip install black - - name: Lint with black - run: black --check --diff . - - flake8: - name: flake8 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - name: Setup - run: pip install flake8 - - name: Lint with flake8 - run: flake8 - - isort: - name: isort - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - name: Setup - run: pip install isort[colors] - - name: Lint with isort - run: isort --check --diff . - - mypy: - name: mypy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - name: Setup - run: pip install mypy pytest - - name: Lint with mypy - run: mypy . + - uses: pre-commit/action@v3.0.0 conda: name: Conda ${{ matrix.python-version }} - ${{ matrix.os }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..dc6f78b0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.291 + hooks: + - id: ruff + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.5.1 + hooks: + - id: mypy