Skip to content

Commit

Permalink
Add and apply pre-commit with black, isort, pyupgrade, end-of-line-fi…
Browse files Browse the repository at this point in the history
…xer, etc.
  • Loading branch information
mwtoews committed Oct 15, 2023
1 parent ce4c8d0 commit f95e579
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 106 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

49 changes: 2 additions & 47 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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/asottile/pyupgrade
rev: v3.13.0
hooks:
- id: pyupgrade
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- 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
3 changes: 1 addition & 2 deletions DEPENDENCIES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- python 3.8+
- setuptools
- libspatialindex C library 1.8.5+:
- libspatialindex C library 1.8.5+:
https://libspatialindex.org/

2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions ci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -72,7 +72,7 @@ if(WIN32)
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
endif()
endif()

set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)

include (CheckFunctionExists)
Expand Down
4 changes: 1 addition & 3 deletions ci/install_libspatialindex.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -25,5 +25,3 @@ rmdir /Q /S bin

dir %~dp0\..\rtree\
dir %~dp0\..\rtree\lib


1 change: 0 additions & 1 deletion docs/source/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,3 @@ available as a result of this refactoring.
- Change license to LGPL.
- Moved from Pleiades to GIS-Python repo.
- Initial release.

4 changes: 2 additions & 2 deletions docs/source/class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions docs/source/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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+.
Expand All @@ -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
.. _`Rtree`: http://rtree.github.com
6 changes: 3 additions & 3 deletions docs/source/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +21,7 @@ Documentation

.. toctree::
:maxdepth: 2

install
tutorial
class
Expand Down
13 changes: 6 additions & 7 deletions docs/source/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Installation
------------------------------------------------------------------------------

\*nix
\*nix
..............................................................................

First, download and install version 1.8.5+ of the `libspatialindex`_ library from:
Expand All @@ -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::

Expand All @@ -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
Expand All @@ -43,4 +43,3 @@ is as easy as::
.. _`Rtree`: http://pypi.python.org/pypi/Rtree/

.. _`libspatialindex`: https://libspatialindex.org/

17 changes: 8 additions & 9 deletions docs/source/performance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 ::

Expand All @@ -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
...............................................................................

Expand All @@ -71,8 +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.

Loading

0 comments on commit f95e579

Please sign in to comment.