Skip to content

Commit ac82f09

Browse files
authored
Update version number and add Black lint (#65)
* Update version number * Add black lint workflow * Format code with black
1 parent 4cd54a0 commit ac82f09

31 files changed

Lines changed: 528 additions & 568 deletions

.github/workflows/black.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Lint code with Black
2+
3+
on:
4+
push:
5+
branches: [ "master", "stable-[0-9]+.[0-9]+" ]
6+
pull_request:
7+
branches: [ "master", "stable-[0-9]+.[0-9]+" ]
8+
9+
jobs:
10+
lint:
11+
name: Lint code with Black
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout sources
15+
uses: actions/checkout@v4
16+
17+
- name: Run Black
18+
uses: psf/black@stable
19+
with:
20+
version: "~= 24.0"

docs/conf.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,52 @@
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

9-
project = 'PyMEOS'
10-
copyright = '2023, Víctor Diví'
11-
author = 'Víctor Diví'
12-
release = '1.1.3'
9+
project = "PyMEOS"
10+
copyright = "2023, Víctor Diví"
11+
author = "Víctor Diví"
12+
release = "1.1.4"
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
1616
import os
1717
import sys
1818

19-
sys.path.insert(0, os.path.abspath('../pymeos_cffi'))
20-
sys.path.insert(0, os.path.abspath('../pymeos'))
19+
sys.path.insert(0, os.path.abspath("../pymeos_cffi"))
20+
sys.path.insert(0, os.path.abspath("../pymeos"))
2121

2222
extensions = [
23-
'sphinx.ext.autodoc',
24-
'sphinx.ext.napoleon',
25-
'sphinx.ext.intersphinx',
26-
'myst_nb',
23+
"sphinx.ext.autodoc",
24+
"sphinx.ext.napoleon",
25+
"sphinx.ext.intersphinx",
26+
"myst_nb",
2727
]
2828

2929
nb_execution_mode = "off"
3030

31-
templates_path = ['_templates']
32-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '_build',
33-
'**.ipynb_checkpoints']
34-
autodoc_member_order = 'bysource'
31+
templates_path = ["_templates"]
32+
exclude_patterns = [
33+
"_build",
34+
"Thumbs.db",
35+
".DS_Store",
36+
"_build",
37+
"**.ipynb_checkpoints",
38+
]
39+
autodoc_member_order = "bysource"
3540

3641
# -- Intersphinx config --------
3742
intersphinx_mapping = {
38-
'asyncpg': ('https://magicstack.github.io/asyncpg/current/', None),
39-
'psycopg': ('https://www.psycopg.org/psycopg3/docs/', None),
40-
'psycopg2': ('https://www.psycopg.org/docs/', None),
41-
'shapely': ('https://shapely.readthedocs.io/en/stable/', None),
42-
'python': ('https://docs.python.org/3', None)
43+
"asyncpg": ("https://magicstack.github.io/asyncpg/current/", None),
44+
"psycopg": ("https://www.psycopg.org/psycopg3/docs/", None),
45+
"psycopg2": ("https://www.psycopg.org/docs/", None),
46+
"shapely": ("https://shapely.readthedocs.io/en/stable/", None),
47+
"python": ("https://docs.python.org/3", None),
4348
}
4449

4550
# -- Options for HTML output -------------------------------------------------
4651
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
4752

48-
html_theme = 'sphinx_book_theme'
49-
html_static_path = ['_static']
53+
html_theme = "sphinx_book_theme"
54+
html_static_path = ["_static"]
5055

5156
import requests
5257

@@ -58,15 +63,13 @@ def download_file(url, dest_path):
5863
# Ensure folder for destination file exists
5964
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
6065

61-
with open(dest_path, 'wb') as file:
66+
with open(dest_path, "wb") as file:
6267
for chunk in response.iter_content(chunk_size=8192):
6368
file.write(chunk)
6469

6570

6671
prefix = "https://raw.githubusercontent.com/MobilityDB/PyMEOS-Examples/main/"
72+
download_file(f"{prefix}PyMEOS_Examples/AIS.ipynb", "src/examples/AIS.ipynb")
6773
download_file(
68-
f"{prefix}PyMEOS_Examples/AIS.ipynb",
69-
"src/examples/AIS.ipynb")
70-
download_file(
71-
f"{prefix}PyMEOS_Examples/BerlinMOD.ipynb",
72-
"src/examples/BerlinMOD.ipynb")
74+
f"{prefix}PyMEOS_Examples/BerlinMOD.ipynb", "src/examples/BerlinMOD.ipynb"
75+
)

pymeos/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
MeosGeoJsonOutputError,
3030
)
3131

32-
__version__ = "1.1.3"
32+
__version__ = "1.1.4"
3333
__all__ = [
3434
# initialization
3535
"pymeos_initialize",

pymeos/aggregators/aggregator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,7 @@ def _add(
244244
interval_converted = (
245245
timedelta_to_interval(interval)
246246
if isinstance(interval, timedelta)
247-
else pg_interval_in(interval, -1)
248-
if isinstance(interval, str)
249-
else None
247+
else pg_interval_in(interval, -1) if isinstance(interval, str) else None
250248
)
251249
origin_converted = (
252250
datetime_to_timestamptz(origin)

pymeos/boxes/stbox.py

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class STBox:
4141
_mobilitydb_name = "stbox"
4242

4343
def _get_box(
44-
self,
45-
other: Union[shp.BaseGeometry, STBox, Temporal, Time],
46-
allow_space_only: bool = True,
47-
allow_time_only: bool = False,
44+
self,
45+
other: Union[shp.BaseGeometry, STBox, Temporal, Time],
46+
allow_space_only: bool = True,
47+
allow_time_only: bool = False,
4848
) -> STBox:
4949
if allow_space_only and isinstance(other, shp.BaseGeometry):
5050
other_box = geo_to_stbox(geo_to_gserialized(other, self.geodetic()))
@@ -68,31 +68,31 @@ def _get_box(
6868

6969
# ------------------------- Constructors ----------------------------------
7070
def __init__(
71-
self,
72-
string: Optional[str] = None,
73-
*,
74-
xmin: Optional[Union[str, float]] = None,
75-
xmax: Optional[Union[str, float]] = None,
76-
ymin: Optional[Union[str, float]] = None,
77-
ymax: Optional[Union[str, float]] = None,
78-
zmin: Optional[Union[str, float]] = None,
79-
zmax: Optional[Union[str, float]] = None,
80-
tmin: Optional[Union[str, datetime]] = None,
81-
tmax: Optional[Union[str, datetime]] = None,
82-
tmin_inc: bool = True,
83-
tmax_inc: bool = True,
84-
geodetic: bool = False,
85-
srid: Optional[int] = None,
86-
_inner=None,
71+
self,
72+
string: Optional[str] = None,
73+
*,
74+
xmin: Optional[Union[str, float]] = None,
75+
xmax: Optional[Union[str, float]] = None,
76+
ymin: Optional[Union[str, float]] = None,
77+
ymax: Optional[Union[str, float]] = None,
78+
zmin: Optional[Union[str, float]] = None,
79+
zmax: Optional[Union[str, float]] = None,
80+
tmin: Optional[Union[str, datetime]] = None,
81+
tmax: Optional[Union[str, datetime]] = None,
82+
tmin_inc: bool = True,
83+
tmax_inc: bool = True,
84+
geodetic: bool = False,
85+
srid: Optional[int] = None,
86+
_inner=None,
8787
):
8888
assert (_inner is not None) or (string is not None) != (
89-
(
90-
xmin is not None
91-
and xmax is not None
92-
and ymin is not None
93-
and ymax is not None
94-
)
95-
or (tmin is not None and tmax is not None)
89+
(
90+
xmin is not None
91+
and xmax is not None
92+
and ymin is not None
93+
and ymax is not None
94+
)
95+
or (tmin is not None and tmax is not None)
9696
), (
9797
"Either string must be not None or at least a bound pair (xmin/max"
9898
" and ymin/max, or tmin/max) must be not None"
@@ -106,10 +106,10 @@ def __init__(
106106
tstzspan = None
107107
hast = tmin is not None and tmax is not None
108108
hasx = (
109-
xmin is not None
110-
and xmax is not None
111-
and ymin is not None
112-
and ymax is not None
109+
xmin is not None
110+
and xmax is not None
111+
and ymin is not None
112+
and ymax is not None
113113
)
114114
hasz = zmin is not None and zmax is not None
115115
if hast:
@@ -224,9 +224,9 @@ def from_time(time: Time) -> STBox:
224224

225225
@staticmethod
226226
def from_geometry_time(
227-
geometry: shp.BaseGeometry,
228-
time: Union[datetime, TsTzSpan],
229-
geodetic: bool = False,
227+
geometry: shp.BaseGeometry,
228+
time: Union[datetime, TsTzSpan],
229+
geodetic: bool = False,
230230
) -> STBox:
231231
"""
232232
Returns a `STBox` from a space and time dimension.
@@ -272,9 +272,9 @@ def from_tpoint(temporal: TPoint) -> STBox:
272272

273273
@staticmethod
274274
def from_expanding_bounding_box(
275-
value: Union[shp.BaseGeometry, TPoint, STBox],
276-
expansion: float,
277-
geodetic: Optional[bool] = False,
275+
value: Union[shp.BaseGeometry, TPoint, STBox],
276+
expansion: float,
277+
geodetic: Optional[bool] = False,
278278
) -> STBox:
279279
"""
280280
Returns a `STBox` from a `shp.BaseGeometry`, `TPoint` or `STBox` instance,
@@ -661,7 +661,7 @@ def scale_time(self, duration: timedelta) -> STBox:
661661
return self.shift_scale_time(duration=duration)
662662

663663
def shift_scale_time(
664-
self, shift: Optional[timedelta] = None, duration: Optional[timedelta] = None
664+
self, shift: Optional[timedelta] = None, duration: Optional[timedelta] = None
665665
) -> STBox:
666666
"""
667667
Returns a new `STBox` with the time dimension shifted by `shift` and
@@ -681,7 +681,7 @@ def shift_scale_time(
681681
:meth:`TsTzSpan.shift_scale`
682682
"""
683683
assert (
684-
shift is not None or duration is not None
684+
shift is not None or duration is not None
685685
), "shift and scale deltas must not be both None"
686686
result = stbox_shift_scale_time(
687687
self._inner,
@@ -792,7 +792,7 @@ def __mul__(self, other):
792792

793793
# ------------------------- Topological Operations ------------------------
794794
def is_adjacent(
795-
self, other: Union[shp.BaseGeometry, STBox, Temporal, Time]
795+
self, other: Union[shp.BaseGeometry, STBox, Temporal, Time]
796796
) -> bool:
797797
"""
798798
Returns whether ``self`` and `other` are adjacent. Two spatiotemporal
@@ -815,7 +815,7 @@ def is_adjacent(
815815
)
816816

817817
def is_contained_in(
818-
self, container: Union[shp.BaseGeometry, STBox, Temporal, Time]
818+
self, container: Union[shp.BaseGeometry, STBox, Temporal, Time]
819819
) -> bool:
820820
"""
821821
Returns whether ``self`` is contained in `container`. Note that for
@@ -1177,7 +1177,7 @@ def is_over_or_after(self, other: Union[Box, Temporal, Time]) -> bool:
11771177

11781178
# ------------------------- Distance Operations ---------------------------
11791179
def nearest_approach_distance(
1180-
self, other: Union[shp.BaseGeometry, STBox, TPoint]
1180+
self, other: Union[shp.BaseGeometry, STBox, TPoint]
11811181
) -> float:
11821182
"""
11831183
Returns the distance between the nearest points of ``self`` and `other`.
@@ -1277,11 +1277,11 @@ def quad_split(self) -> Union[List[List[STBox]], List[List[List[STBox]]]]:
12771277
]
12781278

12791279
def tile(
1280-
self,
1281-
size: Optional[float] = None,
1282-
duration: Optional[Union[timedelta, str]] = None,
1283-
origin: Optional[shp.BaseGeometry] = None,
1284-
start: Union[datetime, str, None] = None,
1280+
self,
1281+
size: Optional[float] = None,
1282+
duration: Optional[Union[timedelta, str]] = None,
1283+
origin: Optional[shp.BaseGeometry] = None,
1284+
start: Union[datetime, str, None] = None,
12851285
) -> List[STBox]:
12861286
"""
12871287
Returns a list of `STBox` instances representing the tiles of
@@ -1306,35 +1306,35 @@ def tile(
13061306
stbox_tile_list
13071307
"""
13081308
sz = size or (
1309-
max(
1310-
self.xmax() - self.xmin(),
1311-
self.ymax() - self.ymin(),
1312-
(self.zmax() - self.zmin() if self.has_z() else 0),
1313-
)
1314-
+ 1
1309+
max(
1310+
self.xmax() - self.xmin(),
1311+
self.ymax() - self.ymin(),
1312+
(self.zmax() - self.zmin() if self.has_z() else 0),
1313+
)
1314+
+ 1
13151315
)
13161316
dt = (
13171317
timedelta_to_interval(duration)
13181318
if isinstance(duration, timedelta)
1319-
else pg_interval_in(duration, -1)
1320-
if isinstance(duration, str)
1321-
else None
1319+
else pg_interval_in(duration, -1) if isinstance(duration, str) else None
13221320
)
13231321
st = (
13241322
datetime_to_timestamptz(start)
13251323
if isinstance(start, datetime)
1326-
else pg_timestamptz_in(start, -1)
1327-
if isinstance(start, str)
1328-
else pg_timestamptz_in("2000-01-03", -1)
1329-
if self.has_t()
1330-
else 0
1324+
else (
1325+
pg_timestamptz_in(start, -1)
1326+
if isinstance(start, str)
1327+
else pg_timestamptz_in("2000-01-03", -1) if self.has_t() else 0
1328+
)
13311329
)
13321330
gs = (
13331331
geo_to_gserialized(origin, self.geodetic())
13341332
if origin is not None
1335-
else pgis_geography_in("Point(0 0 0)", -1)
1336-
if self.geodetic()
1337-
else pgis_geometry_in("Point(0 0 0)", -1)
1333+
else (
1334+
pgis_geography_in("Point(0 0 0)", -1)
1335+
if self.geodetic()
1336+
else pgis_geometry_in("Point(0 0 0)", -1)
1337+
)
13381338
)
13391339
tiles, count = stbox_tile_list(self._inner, sz, sz, sz, dt, gs, st)
13401340
return [STBox(_inner=tiles + i) for i in range(count)]

pymeos/boxes/tbox.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,11 @@ def tile(
11241124
st = (
11251125
datetime_to_timestamptz(start)
11261126
if isinstance(start, datetime)
1127-
else pg_timestamptz_in(start, -1)
1128-
if isinstance(start, str)
1129-
else pg_timestamptz_in("2000-01-03", -1)
1127+
else (
1128+
pg_timestamptz_in(start, -1)
1129+
if isinstance(start, str)
1130+
else pg_timestamptz_in("2000-01-03", -1)
1131+
)
11301132
)
11311133
if self._is_float():
11321134
tiles, count = tfloatbox_tile_list(self._inner, size, dt, origin, st)

0 commit comments

Comments
 (0)