libres 1.1.2__tar.gz → 1.3.0__tar.gz

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.
Files changed (66) hide show
  1. {libres-1.1.2 → libres-1.3.0}/HISTORY.rst +29 -0
  2. {libres-1.1.2/src/libres.egg-info → libres-1.3.0}/PKG-INFO +34 -4
  3. {libres-1.1.2 → libres-1.3.0}/README.rst +1 -1
  4. {libres-1.1.2 → libres-1.3.0}/pyproject.toml +69 -63
  5. {libres-1.1.2 → libres-1.3.0}/src/libres/__init__.py +2 -2
  6. {libres-1.1.2 → libres-1.3.0}/src/libres/context/core.py +5 -5
  7. {libres-1.1.2 → libres-1.3.0}/src/libres/context/registry.py +2 -2
  8. libres-1.3.0/src/libres/db/__init__.py +7 -0
  9. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/allocation.py +4 -4
  10. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/blocker.py +1 -1
  11. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/reservation.py +1 -1
  12. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/reserved_slot.py +3 -0
  13. {libres-1.1.2 → libres-1.3.0}/src/libres/db/scheduler.py +40 -51
  14. {libres-1.1.2 → libres-1.3.0/src/libres.egg-info}/PKG-INFO +34 -4
  15. {libres-1.1.2 → libres-1.3.0}/src/libres.egg-info/requires.txt +1 -0
  16. {libres-1.1.2 → libres-1.3.0}/tests/test_allocation.py +2 -0
  17. {libres-1.1.2 → libres-1.3.0}/tests/test_scheduler.py +75 -0
  18. libres-1.1.2/src/libres/db/__init__.py +0 -7
  19. {libres-1.1.2 → libres-1.3.0}/LICENSE +0 -0
  20. {libres-1.1.2 → libres-1.3.0}/MANIFEST.in +0 -0
  21. {libres-1.1.2 → libres-1.3.0}/docs/Makefile +0 -0
  22. {libres-1.1.2 → libres-1.3.0}/docs/_static/custom.css +0 -0
  23. {libres-1.1.2 → libres-1.3.0}/docs/_static/favicon.ico +0 -0
  24. {libres-1.1.2 → libres-1.3.0}/docs/_static/logo.svg +0 -0
  25. {libres-1.1.2 → libres-1.3.0}/docs/api.rst +0 -0
  26. {libres-1.1.2 → libres-1.3.0}/docs/concepts.rst +0 -0
  27. {libres-1.1.2 → libres-1.3.0}/docs/conf.py +0 -0
  28. {libres-1.1.2 → libres-1.3.0}/docs/customizations.rst +0 -0
  29. {libres-1.1.2 → libres-1.3.0}/docs/faq.rst +0 -0
  30. {libres-1.1.2 → libres-1.3.0}/docs/index.rst +0 -0
  31. {libres-1.1.2 → libres-1.3.0}/docs/requirements.txt +0 -0
  32. {libres-1.1.2 → libres-1.3.0}/docs/under_the_hood.rst +0 -0
  33. {libres-1.1.2 → libres-1.3.0}/setup.cfg +0 -0
  34. {libres-1.1.2 → libres-1.3.0}/setup.py +0 -0
  35. {libres-1.1.2 → libres-1.3.0}/src/libres/.gitignore +0 -0
  36. {libres-1.1.2 → libres-1.3.0}/src/libres/context/__init__.py +0 -0
  37. {libres-1.1.2 → libres-1.3.0}/src/libres/context/exposure.py +0 -0
  38. {libres-1.1.2 → libres-1.3.0}/src/libres/context/session.py +0 -0
  39. {libres-1.1.2 → libres-1.3.0}/src/libres/context/settings.py +0 -0
  40. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/__init__.py +0 -0
  41. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/base.py +0 -0
  42. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/other.py +0 -0
  43. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/timespan.py +0 -0
  44. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/timestamp.py +0 -0
  45. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/types/__init__.py +0 -0
  46. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/types/json_type.py +0 -0
  47. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/types/utcdatetime.py +0 -0
  48. {libres-1.1.2 → libres-1.3.0}/src/libres/db/models/types/uuid_type.py +0 -0
  49. {libres-1.1.2 → libres-1.3.0}/src/libres/db/queries.py +0 -0
  50. {libres-1.1.2 → libres-1.3.0}/src/libres/modules/__init__.py +0 -0
  51. {libres-1.1.2 → libres-1.3.0}/src/libres/modules/errors.py +0 -0
  52. {libres-1.1.2 → libres-1.3.0}/src/libres/modules/events.py +0 -0
  53. {libres-1.1.2 → libres-1.3.0}/src/libres/modules/rasterizer.py +0 -0
  54. {libres-1.1.2 → libres-1.3.0}/src/libres/modules/utils.py +0 -0
  55. {libres-1.1.2 → libres-1.3.0}/src/libres/py.typed +0 -0
  56. {libres-1.1.2 → libres-1.3.0}/src/libres.egg-info/SOURCES.txt +0 -0
  57. {libres-1.1.2 → libres-1.3.0}/src/libres.egg-info/dependency_links.txt +0 -0
  58. {libres-1.1.2 → libres-1.3.0}/src/libres.egg-info/top_level.txt +0 -0
  59. {libres-1.1.2 → libres-1.3.0}/tests/test_registry.py +0 -0
  60. {libres-1.1.2 → libres-1.3.0}/tests/test_reservation.py +0 -0
  61. {libres-1.1.2 → libres-1.3.0}/tests/test_reserved_slot.py +0 -0
  62. {libres-1.1.2 → libres-1.3.0}/tests/test_scheduler_blockers.py +0 -0
  63. {libres-1.1.2 → libres-1.3.0}/tests/test_session.py +0 -0
  64. {libres-1.1.2 → libres-1.3.0}/tests/test_test.py +0 -0
  65. {libres-1.1.2 → libres-1.3.0}/tests/test_types.py +0 -0
  66. {libres-1.1.2 → libres-1.3.0}/tests/test_utils.py +0 -0
@@ -1,6 +1,35 @@
1
1
  Changelog
2
2
  ---------
3
3
 
4
+ 1.3.0 (15.10.2026)
5
+ ~~~~~~~~~~~~~~~~~~~
6
+
7
+ - Adds Python 3.15 support
8
+ [Daverball]
9
+
10
+ - Drops Python 3.10 support
11
+ [Daverball]
12
+
13
+ - Fixes `ZeroDivisionError` in `Scheduler.availability` if there
14
+ are blocking resources, but there are no allocations in the
15
+ specified time period.
16
+ [Daverball]
17
+
18
+ 1.2.0 (13.08.2026)
19
+ ~~~~~~~~~~~~~~~~~~~
20
+
21
+ - Records the owning reservation/blocker id on each reserved slot
22
+
23
+ ReservedSlot gains a ``source_id`` column holding the id of its owning
24
+ reservation or blocker (see ``source_type``). A slot can now be attributed to
25
+ its exact object directly, instead of inferring it from the allocation and
26
+ time range. This fixes ``reserved_slots_by_reservation`` dropping the slot on
27
+ non-partly_available allocations (where the slot spans the whole allocation
28
+ and is wider than a narrower reservation), which left orphaned slots behind on
29
+ removal. Consumers must add the column and backfill it (see the onegov
30
+ ``add_source_id_to_reserved_slots`` upgrade).
31
+ [Tschuppi81]
32
+
4
33
  1.1.2 (16.06.2026)
5
34
  ~~~~~~~~~~~~~~~~~~~
6
35
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libres
3
- Version: 1.1.2
3
+ Version: 1.3.0
4
4
  Summary: A library to reserve things
5
5
  Author-email: Denis Krienbühl <denis@href.ch>
6
6
  Maintainer-email: Seantis GmbH <info@seantis.ch>
@@ -12,16 +12,17 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
19
18
  Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
20
  Classifier: Programming Language :: Python :: Implementation :: CPython
21
21
  Classifier: Programming Language :: Python :: Implementation :: PyPy
22
- Requires-Python: >=3.10
22
+ Requires-Python: >=3.11
23
23
  Description-Content-Type: text/x-rst
24
24
  License-File: LICENSE
25
+ Requires-Dist: jsonpickle<5
25
26
  Requires-Dist: python-dateutil
26
27
  Requires-Dist: pytz
27
28
  Requires-Dist: sedate>=1.0.0
@@ -32,7 +33,7 @@ Libres
32
33
  ======
33
34
 
34
35
  Libres is a reservations management library to reserve things like tables at
35
- a restaurant or tickets at an event. It works with Python 3.10+
36
+ a restaurant or tickets at an event. It works with Python 3.11+
36
37
  and requires Postgresql 9.2+.
37
38
 
38
39
  `Documentation <http://libres.readthedocs.org/en/latest/>`_ | `Source <http://github.com/seantis/libres/>`_ | `Bugs <http://github.com/seantis/libres/issues>`_
@@ -116,6 +117,35 @@ After this, create a new release on Github.
116
117
  Changelog
117
118
  ---------
118
119
 
120
+ 1.3.0 (15.10.2026)
121
+ ~~~~~~~~~~~~~~~~~~~
122
+
123
+ - Adds Python 3.15 support
124
+ [Daverball]
125
+
126
+ - Drops Python 3.10 support
127
+ [Daverball]
128
+
129
+ - Fixes `ZeroDivisionError` in `Scheduler.availability` if there
130
+ are blocking resources, but there are no allocations in the
131
+ specified time period.
132
+ [Daverball]
133
+
134
+ 1.2.0 (13.08.2026)
135
+ ~~~~~~~~~~~~~~~~~~~
136
+
137
+ - Records the owning reservation/blocker id on each reserved slot
138
+
139
+ ReservedSlot gains a ``source_id`` column holding the id of its owning
140
+ reservation or blocker (see ``source_type``). A slot can now be attributed to
141
+ its exact object directly, instead of inferring it from the allocation and
142
+ time range. This fixes ``reserved_slots_by_reservation`` dropping the slot on
143
+ non-partly_available allocations (where the slot spans the whole allocation
144
+ and is wider than a narrower reservation), which left orphaned slots behind on
145
+ removal. Consumers must add the column and backfill it (see the onegov
146
+ ``add_source_id_to_reserved_slots`` upgrade).
147
+ [Tschuppi81]
148
+
119
149
  1.1.2 (16.06.2026)
120
150
  ~~~~~~~~~~~~~~~~~~~
121
151
 
@@ -2,7 +2,7 @@ Libres
2
2
  ======
3
3
 
4
4
  Libres is a reservations management library to reserve things like tables at
5
- a restaurant or tickets at an event. It works with Python 3.10+
5
+ a restaurant or tickets at an event. It works with Python 3.11+
6
6
  and requires Postgresql 9.2+.
7
7
 
8
8
  `Documentation <http://libres.readthedocs.org/en/latest/>`_ | `Source <http://github.com/seantis/libres/>`_ | `Bugs <http://github.com/seantis/libres/issues>`_
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
  name = "libres"
7
7
  dynamic = ["version", "readme"]
8
8
  description = "A library to reserve things"
9
- requires-python = ">=3.10"
9
+ requires-python = ">=3.11"
10
10
  authors = [
11
11
  { name = "Denis Krienbühl", email = "denis@href.ch" },
12
12
  ]
@@ -22,15 +22,17 @@ classifiers = [
22
22
  "Operating System :: OS Independent",
23
23
  "Programming Language :: Python",
24
24
  "Programming Language :: Python :: 3",
25
- "Programming Language :: Python :: 3.10",
26
25
  "Programming Language :: Python :: 3.11",
27
26
  "Programming Language :: Python :: 3.12",
28
27
  "Programming Language :: Python :: 3.13",
29
28
  "Programming Language :: Python :: 3.14",
29
+ "Programming Language :: Python :: 3.15",
30
30
  "Programming Language :: Python :: Implementation :: CPython",
31
31
  "Programming Language :: Python :: Implementation :: PyPy",
32
32
  ]
33
33
  dependencies = [
34
+ # FIXME: Remove this pin after upgrading to SQLAlchemy 2.1
35
+ "jsonpickle < 5",
34
36
  "python-dateutil",
35
37
  "pytz",
36
38
  "sedate >= 1.0.0",
@@ -94,13 +96,17 @@ dev = [
94
96
  [tool.pytest.ini_options]
95
97
  log_level = "INFO"
96
98
  testpaths = ["tests"]
99
+ filterwarnings = [
100
+ # FIXME: Remove after upgrading to SQLAlchemy 2.1
101
+ '''ignore:keys will default to True in jsonpickle 5\.0\.0:DeprecationWarning''',
102
+ ]
97
103
 
98
104
  [tool.coverage.run]
99
105
  branch = true
100
106
  source = ["src"]
101
107
 
102
108
  [tool.bumpversion]
103
- current_version = "1.1.2"
109
+ current_version = "1.3.0"
104
110
  commit = true
105
111
  message = "Release {new_version}"
106
112
  tag = true
@@ -124,7 +130,7 @@ replace = """
124
130
  """
125
131
 
126
132
  [tool.mypy]
127
- python_version = "3.10"
133
+ python_version = "3.11"
128
134
  namespace_packages = true
129
135
  explicit_package_bases = true
130
136
  strict = true
@@ -192,26 +198,19 @@ include = [
192
198
  ]
193
199
  line-length = 79
194
200
  indent-width = 4
195
- target-version = "py310"
201
+ target-version = "py311"
196
202
 
197
203
  [tool.ruff.lint]
198
204
  select = [
199
205
  "B0",
200
- "B904",
201
- "B909",
202
206
  "C4",
203
- "COM818",
204
207
  "D2",
205
- "D301",
206
208
  "D4",
207
209
  "E",
208
210
  "F",
209
- "FLY002",
210
- "I002",
211
211
  "ISC",
212
212
  "N",
213
213
  "PERF",
214
- "PGH004",
215
214
  "PIE",
216
215
  "PT",
217
216
  "PYI",
@@ -220,48 +219,55 @@ select = [
220
219
  "SIM",
221
220
  "SLOT",
222
221
  "UP",
223
- "W"
222
+ "W",
223
+ "blanket-noqa",
224
+ "escape-sequence-in-docstring",
225
+ "loop-iterator-mutation",
226
+ "missing-required-import",
227
+ "raise-without-from-inside-except",
228
+ "static-join-to-f-string",
229
+ "trailing-comma-on-bare-tuple",
224
230
  ]
225
231
  ignore = [
226
- "B007",
227
- "C420",
228
- "D200",
229
- "D201",
230
- "D202",
231
- "D204",
232
- "D205",
233
- "D209",
234
- "D210",
235
- "D211",
236
- "D400",
237
- "D401",
238
- "D412",
239
- "E226",
240
- "E402",
241
- "E711",
242
- "E712",
243
- "E741",
244
- "N818",
245
- "PYI019",
246
- "PYI041",
247
- "RUF012",
248
- "RUF013",
249
- "RUF021",
250
- "RUF022",
251
- "RUF023",
252
- "RUF031",
253
- "RUF052",
254
- "RUF056",
255
- "SIM103",
256
- "SIM105",
257
- "SIM108",
258
- "SIM110",
259
- "SIM118",
260
- "SIM210",
261
- "SIM910",
262
- "UP009",
263
- "UP012",
264
- "UP032",
232
+ "ambiguous-variable-name",
233
+ "blank-line-after-function",
234
+ "blank-line-before-class",
235
+ "blank-line-before-function",
236
+ "blank-lines-between-header-and-content",
237
+ "custom-type-var-for-self",
238
+ "dict-get-with-none-default",
239
+ "error-suffix-on-exception-name",
240
+ "f-string",
241
+ "falsy-dict-get-fallback",
242
+ "if-else-block-instead-of-if-exp",
243
+ "if-expr-with-true-false",
244
+ "implicit-optional",
245
+ "in-dict-keys",
246
+ "incorrect-blank-line-after-class",
247
+ "incorrectly-parenthesized-tuple-in-subscript",
248
+ "missing-blank-line-after-summary",
249
+ "missing-trailing-period",
250
+ "missing-whitespace-around-arithmetic-operator",
251
+ "module-import-not-at-top-of-file",
252
+ "mutable-class-default",
253
+ "needless-bool",
254
+ "new-line-after-last-paragraph",
255
+ "non-imperative-mood",
256
+ "none-comparison",
257
+ "parenthesize-chained-operators",
258
+ "reimplemented-builtin",
259
+ "redundant-numeric-union",
260
+ "suppressible-exception",
261
+ "surrounding-whitespace",
262
+ "true-false-comparison",
263
+ "unnecessary-dict-comprehension-for-iterable",
264
+ "unnecessary-encode-utf8",
265
+ "unnecessary-multiline-docstring",
266
+ "unsorted-dunder-all",
267
+ "unsorted-dunder-slots",
268
+ "unused-loop-control-variable",
269
+ "used-dummy-variable",
270
+ "utf8-encoding-declaration",
265
271
  ]
266
272
  unfixable = []
267
273
  external = ["TC"]
@@ -273,7 +279,6 @@ preview = true
273
279
  "tests/**/*.py" = [
274
280
  "C4",
275
281
  "D",
276
- "FLY002",
277
282
  "ISC",
278
283
  "N",
279
284
  "Q",
@@ -284,6 +289,7 @@ preview = true
284
289
  "RUF",
285
290
  "SIM",
286
291
  "UP",
292
+ "static-join-to-f-string",
287
293
  ]
288
294
 
289
295
  [tool.ruff.lint.isort]
@@ -326,11 +332,11 @@ docstring-code-line-length = "dynamic"
326
332
  [tool.tox]
327
333
  requires = ["tox>=4.21"]
328
334
  envlist = [
329
- "3.10",
330
335
  "3.11",
331
336
  "3.12",
332
337
  "3.13",
333
338
  "3.14",
339
+ "3.15",
334
340
  "flake8",
335
341
  "ruff",
336
342
  "bandit",
@@ -339,11 +345,11 @@ envlist = [
339
345
  ]
340
346
 
341
347
  [tool.tox.gh.python]
342
- "3.10" = ["3.10"]
343
- "3.11" = ["3.11", "flake8", "bandit", "ruff", "mypy"]
344
- "3.12" = ["3.12"]
348
+ "3.11" = ["3.11"]
349
+ "3.12" = ["3.12", "flake8", "bandit", "ruff", "mypy"]
345
350
  "3.13" = ["3.13"]
346
351
  "3.14" = ["3.14"]
352
+ "3.15" = ["3.15"]
347
353
 
348
354
  [tool.tox.env_run_base]
349
355
  use_develop = true
@@ -359,37 +365,37 @@ commands = [
359
365
  ],
360
366
  ]
361
367
  [tool.tox.env.ruff]
362
- base_python = ["python3.11"]
368
+ base_python = ["python3.12"]
363
369
  skip_install = true
364
370
  dependency_groups = ["ruff"]
365
371
  commands = [["ruff", "check"]]
366
372
 
367
373
  [tool.tox.env.flake8]
368
- base_python = ["python3.11"]
374
+ base_python = ["python3.12"]
369
375
  skip_install = true
370
376
  dependency_groups = ["flake8"]
371
377
  commands = [["flake8", "src{/}", "tests{/}"]]
372
378
 
373
379
  [tool.tox.env.bandit]
374
- base_python = ["python3.11"]
380
+ base_python = ["python3.12"]
375
381
  skip_install = true
376
382
  dependency_groups = ["bandit"]
377
383
  commands = [["bandit", "-q", "-c", "pyproject.toml", "-r", "src"]]
378
384
 
379
385
  [tool.tox.env.mypy]
380
- base_python = ["python3.11"]
386
+ base_python = ["python3.12"]
381
387
  skip_install = true
382
388
  dependency_groups = ["mypy"]
383
389
  commands = [
384
- ["mypy", "-p", "libres", "--python-version", "3.10"],
385
390
  ["mypy", "-p", "libres", "--python-version", "3.11"],
386
391
  ["mypy", "-p", "libres", "--python-version", "3.12"],
387
392
  ["mypy", "-p", "libres", "--python-version", "3.13"],
388
393
  ["mypy", "-p", "libres", "--python-version", "3.14"],
394
+ ["mypy", "-p", "libres", "--python-version", "3.15"],
389
395
  ]
390
396
 
391
397
  [tool.tox.env.report]
392
- base_python = ["python3.11"]
398
+ base_python = ["python3.12"]
393
399
  skip_install = true
394
400
  ignore_errors = true
395
401
  ignore_outcome = true
@@ -3,9 +3,9 @@ from __future__ import annotations
3
3
  from libres.context.registry import create_default_registry
4
4
  from libres.db import new_scheduler
5
5
 
6
- registry = create_default_registry() # noqa: RUF067
6
+ registry = create_default_registry() # ruff: ignore[non-empty-init-module]
7
7
 
8
- __version__ = '1.1.2'
8
+ __version__ = '1.3.0'
9
9
  __all__ = (
10
10
  'new_scheduler',
11
11
  'registry'
@@ -14,7 +14,7 @@ from typing import Literal
14
14
  from typing import TYPE_CHECKING
15
15
  if TYPE_CHECKING:
16
16
  from collections.abc import Callable
17
- from collections.abc import Iterator
17
+ from collections.abc import Generator
18
18
  from sqlalchemy.orm import Session
19
19
  from sqlalchemy.orm.session import SessionTransaction
20
20
  from typing import TypeAlias
@@ -30,8 +30,8 @@ class _Marker(enum.Enum):
30
30
  required = enum.auto()
31
31
 
32
32
 
33
- missing_t: TypeAlias = Literal[_Marker.missing] # noqa: PYI042
34
- required_t: TypeAlias = Literal[_Marker.required] # noqa: PYI042
33
+ missing_t: TypeAlias = Literal[_Marker.missing] # ruff: ignore[snake-case-type-alias]
34
+ required_t: TypeAlias = Literal[_Marker.required] # ruff: ignore[snake-case-type-alias]
35
35
  missing: missing_t = _Marker.missing
36
36
  required: required_t = _Marker.required
37
37
 
@@ -95,7 +95,7 @@ class ContextServicesMixin:
95
95
 
96
96
  @property
97
97
  def session(self) -> Session:
98
- """ Returns the current session. """
98
+ """ The current session. """
99
99
  return self.session_provider.session() # type: ignore[no-any-return]
100
100
 
101
101
  def close(self) -> None:
@@ -164,7 +164,7 @@ class Context:
164
164
  return f"<Libres Context(name='{self.name}')>"
165
165
 
166
166
  @contextmanager
167
- def as_current_context(self) -> Iterator[None]:
167
+ def as_current_context(self) -> Generator[None]:
168
168
  with self.registry.context(self.name):
169
169
  yield
170
170
 
@@ -11,7 +11,7 @@ from libres.context.core import Context
11
11
  from typing import TYPE_CHECKING
12
12
  if TYPE_CHECKING:
13
13
  from collections.abc import Callable
14
- from collections.abc import Iterator
14
+ from collections.abc import Generator
15
15
  from uuid import UUID
16
16
 
17
17
 
@@ -143,7 +143,7 @@ class Registry:
143
143
  self.local.current_context = self.get_context(name)
144
144
 
145
145
  @contextmanager
146
- def context(self, name: str) -> Iterator[Context]:
146
+ def context(self, name: str) -> Generator[Context]:
147
147
  previous = self.current_context.name
148
148
  self.switch_context(name)
149
149
  try:
@@ -0,0 +1,7 @@
1
+ from __future__ import annotations
2
+
3
+ from libres.db.scheduler import Scheduler as new_scheduler # ruff: ignore[camelcase-imported-as-lowercase]
4
+
5
+ __all__ = (
6
+ 'new_scheduler',
7
+ )
@@ -36,7 +36,7 @@ if TYPE_CHECKING:
36
36
  from sedate.types import TzInfoOrName
37
37
  from sqlalchemy.orm import Query
38
38
  from typing import NamedTuple
39
- from typing_extensions import Self
39
+ from typing import Self
40
40
 
41
41
  from libres.db.models import ReservedSlot
42
42
  from libres.modules.rasterizer import Raster
@@ -502,7 +502,7 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
502
502
 
503
503
  @property
504
504
  def pending_reservations(self) -> Query[_ReservationIdRow]:
505
- """ Returns the pending reservations query for this allocation.
505
+ """ The pending reservations query for this allocation.
506
506
  As the pending reservations target the group and not a specific
507
507
  allocation this function returns the same value for masters and
508
508
  mirrors.
@@ -517,7 +517,7 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
517
517
  "Don't call if the allocation is detached"
518
518
  )
519
519
 
520
- Reservation = self.models.Reservation # noqa: N806
520
+ Reservation = self.models.Reservation # ruff: ignore[non-lowercase-variable-in-function]
521
521
  query: Query[_ReservationIdRow]
522
522
  query = session.query(Reservation.id) # type: ignore[assignment]
523
523
  query = query.filter(Reservation.target == self.group)
@@ -531,7 +531,7 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
531
531
 
532
532
  @property
533
533
  def availability(self) -> float:
534
- """Returns the availability in percent."""
534
+ """The availability in percent."""
535
535
 
536
536
  total = self.count_slots()
537
537
  blocked = sum(
@@ -84,7 +84,7 @@ class ReservationBlocker(TimestampMixin, ORMBase, OtherModels):
84
84
  assert session, (
85
85
  "Don't call if the blocker is detached"
86
86
  )
87
- Allocation = self.models.Allocation # noqa: N806
87
+ Allocation = self.models.Allocation # ruff: ignore[non-lowercase-variable-in-function]
88
88
  query = session.query(Allocation)
89
89
  query = query.filter(Allocation.group == self.target)
90
90
 
@@ -107,7 +107,7 @@ class Reservation(TimestampMixin, ORMBase, OtherModels):
107
107
  assert session, (
108
108
  "Don't call if the reservation is detached"
109
109
  )
110
- Allocation = self.models.Allocation # noqa: N806
110
+ Allocation = self.models.Allocation # ruff: ignore[non-lowercase-variable-in-function]
111
111
  query = session.query(Allocation)
112
112
  query = query.filter(Allocation.group == self.target)
113
113
 
@@ -68,6 +68,9 @@ class ReservedSlot(TimestampMixin, ORMBase):
68
68
 
69
69
  reservation_token: Mapped[UUID]
70
70
 
71
+ # id of the owning Reservation or ReservationBlocker (see source_type)
72
+ source_id: Mapped[int] = mapped_column(index=True)
73
+
71
74
  __table_args__ = (
72
75
  Index('reservation_resource_ix', 'reservation_token', 'resource'),
73
76
  # NOTE: GiST index for temporal queries on reserved slots
@@ -9,7 +9,7 @@ from operator import attrgetter
9
9
  from sqlalchemy import exc
10
10
  from sqlalchemy import func
11
11
  from sqlalchemy.orm import selectinload
12
- from sqlalchemy.sql import and_, not_, or_
12
+ from sqlalchemy.sql import and_, not_
13
13
  from uuid import uuid4 as new_uuid, UUID
14
14
 
15
15
  from libres.context.core import ContextServicesMixin
@@ -35,13 +35,15 @@ if TYPE_CHECKING:
35
35
  from collections.abc import Iterator
36
36
  from sedate.types import DateLike
37
37
  from sqlalchemy.orm import Query
38
+ from typing import NotRequired
38
39
  from typing import TypeAlias
39
- from typing_extensions import NotRequired, Self, TypedDict
40
+ from typing import TypedDict
41
+ from typing import Self
40
42
 
41
43
  from libres.context.core import Context
42
44
  from libres.modules.rasterizer import Raster
43
45
 
44
- _dtrange: TypeAlias = tuple[datetime, datetime] # noqa: PYI042
46
+ _dtrange: TypeAlias = tuple[datetime, datetime] # ruff: ignore[snake-case-type-alias]
45
47
 
46
48
  class _ReserveArgs1(TypedDict):
47
49
  email: str
@@ -861,6 +863,8 @@ class Scheduler(ContextServicesMixin):
861
863
  for allocation, availability, _ in allocations:
862
864
  total += availability
863
865
  count += allocation.quota
866
+ if not count:
867
+ return 0.0
864
868
  return total / count
865
869
 
866
870
  def move_allocation(
@@ -1491,6 +1495,7 @@ class Scheduler(ContextServicesMixin):
1491
1495
  slot.resource = allocation.resource
1492
1496
  slot.reservation_token = reservation.token
1493
1497
  slot.source_type = 'reservation'
1498
+ slot.source_id = reservation.id
1494
1499
 
1495
1500
  # the slots are written with the allocation
1496
1501
  allocation.reserved_slots.append(slot)
@@ -1671,7 +1676,7 @@ class Scheduler(ContextServicesMixin):
1671
1676
  existing_reservation = self.reservations_by_token(token, id).one()
1672
1677
 
1673
1678
  # if there's nothing to change, do not change
1674
- if quota is None or existing_reservation.quota == quota: # noqa: SIM102
1679
+ if quota is None or existing_reservation.quota == quota: # ruff: ignore[collapsible-if]
1675
1680
  if existing_reservation.start == new_start:
1676
1681
  ends = (new_end, new_end - timedelta(microseconds=1))
1677
1682
 
@@ -1729,7 +1734,8 @@ class Scheduler(ContextServicesMixin):
1729
1734
  dates: _dtrange | Collection[_dtrange],
1730
1735
  group: None = ...,
1731
1736
  reason: str | None = ...,
1732
- token: UUID | None = ...
1737
+ token: UUID | None = ...,
1738
+ id: int | None = ...
1733
1739
  ) -> list[ReservationBlocker]: ...
1734
1740
 
1735
1741
  @overload
@@ -1738,7 +1744,8 @@ class Scheduler(ContextServicesMixin):
1738
1744
  dates: None,
1739
1745
  group: UUID,
1740
1746
  reason: str | None = ...,
1741
- token: UUID | None = ...
1747
+ token: UUID | None = ...,
1748
+ id: int | None = ...
1742
1749
  ) -> list[ReservationBlocker]: ...
1743
1750
 
1744
1751
  @overload
@@ -1748,7 +1755,8 @@ class Scheduler(ContextServicesMixin):
1748
1755
  *,
1749
1756
  group: UUID,
1750
1757
  reason: str | None = ...,
1751
- token: UUID | None = ...
1758
+ token: UUID | None = ...,
1759
+ id: int | None = ...
1752
1760
  ) -> list[ReservationBlocker]: ...
1753
1761
 
1754
1762
  def add_blocker(
@@ -1756,7 +1764,8 @@ class Scheduler(ContextServicesMixin):
1756
1764
  dates: _dtrange | Collection[_dtrange] | None = None,
1757
1765
  group: UUID | None = None,
1758
1766
  reason: str | None = None,
1759
- token: UUID | None = None
1767
+ token: UUID | None = None,
1768
+ id: int | None = None
1760
1769
  ) -> list[ReservationBlocker]:
1761
1770
  """ Adds a blocker to one or many allocations.
1762
1771
 
@@ -1827,7 +1836,6 @@ class Scheduler(ContextServicesMixin):
1827
1836
  elif not allocation.contains(start, end):
1828
1837
  raise errors.TimerangeTooLong
1829
1838
 
1830
- # ok, we're good to go
1831
1839
  if token is None:
1832
1840
  token = new_uuid()
1833
1841
  reserved_slots = []
@@ -1836,6 +1844,7 @@ class Scheduler(ContextServicesMixin):
1836
1844
  allocation: Allocation,
1837
1845
  start: datetime,
1838
1846
  end: datetime,
1847
+ source_id: int,
1839
1848
  including_mirrors: bool = True
1840
1849
  ) -> None:
1841
1850
  for slot_start, slot_end in allocation.all_slots(start, end):
@@ -1845,6 +1854,7 @@ class Scheduler(ContextServicesMixin):
1845
1854
  slot.resource = allocation.resource
1846
1855
  slot.reservation_token = token
1847
1856
  slot.source_type = 'blocker'
1857
+ slot.source_id = source_id
1848
1858
 
1849
1859
  # the slots are written with the allocation
1850
1860
  allocation.reserved_slots.append(slot)
@@ -1859,7 +1869,7 @@ class Scheduler(ContextServicesMixin):
1859
1869
 
1860
1870
  for mirror in self.allocation_mirrors_by_master(allocation):
1861
1871
  create_reserved_slots(
1862
- mirror, start, end,
1872
+ mirror, start, end, source_id,
1863
1873
  including_mirrors=False
1864
1874
  )
1865
1875
 
@@ -1877,12 +1887,18 @@ class Scheduler(ContextServicesMixin):
1877
1887
  blocker.target_type = 'group'
1878
1888
  blocker.resource = self.resource
1879
1889
  blocker.reason = reason
1890
+ if id is not None:
1891
+ blocker.id = id
1880
1892
 
1893
+ # flush to assign the blocker id before its slots reference it
1894
+ self.session.add(blocker)
1895
+ self.session.flush()
1881
1896
  for allocation in self.allocations_by_group(group):
1882
1897
  create_reserved_slots(
1883
1898
  allocation,
1884
1899
  allocation._start,
1885
- allocation._end
1900
+ allocation._end,
1901
+ blocker.id
1886
1902
  )
1887
1903
 
1888
1904
  yield blocker
@@ -1919,8 +1935,15 @@ class Scheduler(ContextServicesMixin):
1919
1935
  blocker.target_type = 'allocation'
1920
1936
  blocker.resource = self.resource
1921
1937
  blocker.reason = reason
1922
-
1923
- create_reserved_slots(allocation, start, end)
1938
+ if id is not None:
1939
+ blocker.id = id
1940
+
1941
+ # flush to assign the id before its slots reference it
1942
+ self.session.add(blocker)
1943
+ self.session.flush()
1944
+ create_reserved_slots(
1945
+ allocation, start, end, blocker.id
1946
+ )
1924
1947
 
1925
1948
  yield blocker
1926
1949
 
@@ -1936,9 +1959,6 @@ class Scheduler(ContextServicesMixin):
1936
1959
  if not reserved_slots:
1937
1960
  raise errors.NotReservableError
1938
1961
 
1939
- for blocker in blockers:
1940
- self.session.add(blocker)
1941
-
1942
1962
  return blockers
1943
1963
 
1944
1964
  def remove_blocker(
@@ -2018,9 +2038,9 @@ class Scheduler(ContextServicesMixin):
2018
2038
  new_blocker, = self.add_blocker(
2019
2039
  dates=(new_start, new_end),
2020
2040
  reason=old_reason,
2021
- token=token
2041
+ token=token,
2042
+ id=id
2022
2043
  )
2023
- new_blocker.id = id
2024
2044
 
2025
2045
  return new_blocker
2026
2046
 
@@ -2297,24 +2317,7 @@ class Scheduler(ContextServicesMixin):
2297
2317
  if id is None:
2298
2318
  return query
2299
2319
 
2300
- # allocation_id is ambiguous when multiple reservations share a token
2301
- # on a partly_available allocation; filter by time range instead.
2302
- # start is None for group reservations — the or_ includes all their
2303
- # slots.
2304
- return (
2305
- query
2306
- .join(Reservation, and_(
2307
- Reservation.token == ReservedSlot.reservation_token,
2308
- Reservation.id == id
2309
- ))
2310
- .filter(or_(
2311
- Reservation.start.is_(None),
2312
- and_(
2313
- ReservedSlot.start >= Reservation.start,
2314
- ReservedSlot.end <= Reservation.end,
2315
- )
2316
- ))
2317
- )
2320
+ return query.filter(ReservedSlot.source_id == id)
2318
2321
 
2319
2322
  def reserved_slots_by_blocker(
2320
2323
  self,
@@ -2331,21 +2334,7 @@ class Scheduler(ContextServicesMixin):
2331
2334
  if id is None:
2332
2335
  return query
2333
2336
 
2334
- # Same rationale as reserved_slots_by_reservation.
2335
- return (
2336
- query
2337
- .join(ReservationBlocker, and_(
2338
- ReservationBlocker.token == ReservedSlot.reservation_token,
2339
- ReservationBlocker.id == id
2340
- ))
2341
- .filter(or_(
2342
- ReservationBlocker.start.is_(None),
2343
- and_(
2344
- ReservedSlot.start >= ReservationBlocker.start,
2345
- ReservedSlot.end <= ReservationBlocker.end,
2346
- )
2347
- ))
2348
- )
2337
+ return query.filter(ReservedSlot.source_id == id)
2349
2338
 
2350
2339
  def reservations_by_group(self, group: UUID) -> Query[Reservation]:
2351
2340
  tokens = self.managed_reservations().with_entities(Reservation.token)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libres
3
- Version: 1.1.2
3
+ Version: 1.3.0
4
4
  Summary: A library to reserve things
5
5
  Author-email: Denis Krienbühl <denis@href.ch>
6
6
  Maintainer-email: Seantis GmbH <info@seantis.ch>
@@ -12,16 +12,17 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
19
18
  Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
20
  Classifier: Programming Language :: Python :: Implementation :: CPython
21
21
  Classifier: Programming Language :: Python :: Implementation :: PyPy
22
- Requires-Python: >=3.10
22
+ Requires-Python: >=3.11
23
23
  Description-Content-Type: text/x-rst
24
24
  License-File: LICENSE
25
+ Requires-Dist: jsonpickle<5
25
26
  Requires-Dist: python-dateutil
26
27
  Requires-Dist: pytz
27
28
  Requires-Dist: sedate>=1.0.0
@@ -32,7 +33,7 @@ Libres
32
33
  ======
33
34
 
34
35
  Libres is a reservations management library to reserve things like tables at
35
- a restaurant or tickets at an event. It works with Python 3.10+
36
+ a restaurant or tickets at an event. It works with Python 3.11+
36
37
  and requires Postgresql 9.2+.
37
38
 
38
39
  `Documentation <http://libres.readthedocs.org/en/latest/>`_ | `Source <http://github.com/seantis/libres/>`_ | `Bugs <http://github.com/seantis/libres/issues>`_
@@ -116,6 +117,35 @@ After this, create a new release on Github.
116
117
  Changelog
117
118
  ---------
118
119
 
120
+ 1.3.0 (15.10.2026)
121
+ ~~~~~~~~~~~~~~~~~~~
122
+
123
+ - Adds Python 3.15 support
124
+ [Daverball]
125
+
126
+ - Drops Python 3.10 support
127
+ [Daverball]
128
+
129
+ - Fixes `ZeroDivisionError` in `Scheduler.availability` if there
130
+ are blocking resources, but there are no allocations in the
131
+ specified time period.
132
+ [Daverball]
133
+
134
+ 1.2.0 (13.08.2026)
135
+ ~~~~~~~~~~~~~~~~~~~
136
+
137
+ - Records the owning reservation/blocker id on each reserved slot
138
+
139
+ ReservedSlot gains a ``source_id`` column holding the id of its owning
140
+ reservation or blocker (see ``source_type``). A slot can now be attributed to
141
+ its exact object directly, instead of inferring it from the allocation and
142
+ time range. This fixes ``reserved_slots_by_reservation`` dropping the slot on
143
+ non-partly_available allocations (where the slot spans the whole allocation
144
+ and is wider than a narrower reservation), which left orphaned slots behind on
145
+ removal. Consumers must add the column and backfill it (see the onegov
146
+ ``add_source_id_to_reserved_slots`` upgrade).
147
+ [Tschuppi81]
148
+
119
149
  1.1.2 (16.06.2026)
120
150
  ~~~~~~~~~~~~~~~~~~~
121
151
 
@@ -1,3 +1,4 @@
1
+ jsonpickle<5
1
2
  python-dateutil
2
3
  pytz
3
4
  sedate>=1.0.0
@@ -255,6 +255,7 @@ def add_reservation(
255
255
  slot.allocation = allocation
256
256
  slot.reservation_token = reservation
257
257
  slot.source_type = 'reservation'
258
+ slot.source_id = 1 # synthetic slot, no real owner
258
259
  scheduler.session.add(slot)
259
260
  scheduler.session.flush()
260
261
  scheduler.session.refresh(allocation)
@@ -281,6 +282,7 @@ def add_blocker(
281
282
  slot.allocation = allocation
282
283
  slot.reservation_token = blocker
283
284
  slot.source_type = 'blocker'
285
+ slot.source_id = 1 # synthetic slot, no real owner
284
286
  scheduler.session.add(slot)
285
287
  scheduler.session.flush()
286
288
  scheduler.session.refresh(allocation)
@@ -433,6 +433,7 @@ def test_reserve_blocking_resources(
433
433
  blocked_scheduler: Scheduler
434
434
  ) -> None:
435
435
 
436
+ assert blocked_scheduler.availability() == 0.0
436
437
  assert scheduler.resource in blocked_scheduler.blocking_resources
437
438
 
438
439
  # create an allocation on the blocking scheduler
@@ -484,6 +485,7 @@ def test_reserve_blocking_resources(
484
485
  (25.0, True),
485
486
  (50.0, False),
486
487
  ]
488
+ assert blocked_scheduler.availability() == 75.0
487
489
 
488
490
  # reserving a slot that's partially blocked will fail
489
491
  with pytest.raises(errors.AlreadyReservedError):
@@ -520,6 +522,7 @@ def test_reserve_blocking_resources(
520
522
  (25.0, False),
521
523
  (75.0, True),
522
524
  ]
525
+ assert blocked_scheduler.availability() == 25.0
523
526
 
524
527
 
525
528
  def test_change_email(scheduler: Scheduler) -> None:
@@ -691,6 +694,77 @@ def test_remove_reservation_does_not_affect_sibling_reservations(
691
694
  assert remaining_count == slots_a_count
692
695
 
693
696
 
697
+ def test_remove_reservation_on_non_partly_allocation_removes_slot(
698
+ scheduler: Scheduler,
699
+ ) -> None:
700
+ """On a non-partly allocation the reserved slot spans the whole
701
+ allocation, even if the reservation was made for a narrower (but
702
+ contained) range. Matching slots by time range would then drop the slot,
703
+ leaving an orphaned ReservedSlot behind that keeps showing up on the
704
+ calendar after the reservation was removed (OGC-3388)."""
705
+ dates = (datetime(2014, 3, 7, 8, 0), datetime(2014, 3, 7, 18, 0))
706
+ scheduler.allocate(dates, partly_available=False)
707
+
708
+ # a contained sub-range is accepted on a whole-only allocation, but the
709
+ # slot still covers the entire allocation
710
+ sub = (datetime(2014, 3, 7, 9, 0), datetime(2014, 3, 7, 17, 0))
711
+ token = scheduler.reserve('user@example.org', sub)
712
+ scheduler.commit()
713
+ scheduler.approve_reservations(token)
714
+ scheduler.commit()
715
+
716
+ reservation = scheduler.reservations_by_token(token).one()
717
+ assert reservation.start is not None
718
+ assert reservation.end is not None
719
+ slot = scheduler.reserved_slots_by_reservation(token).one()
720
+ # the slot is wider than the reservation range
721
+ assert slot.start < reservation.start or slot.end > reservation.end
722
+
723
+ # the slot must still be attributed to this reservation ...
724
+ assert scheduler.reserved_slots_by_reservation(
725
+ token, reservation.id
726
+ ).count() == 1
727
+
728
+ # ... and removing the reservation must not leave an orphaned slot
729
+ scheduler.remove_reservation(token, reservation.id)
730
+ scheduler.commit()
731
+ assert scheduler.reserved_slots_by_type(token, 'reservation').count() == 0
732
+
733
+
734
+ def test_reserved_slots_store_source_id(scheduler: Scheduler) -> None:
735
+ """Every reserved slot records the id of its owning reservation/blocker
736
+ (source_id), so it can be attributed to its exact object directly."""
737
+ dates = (datetime(2014, 3, 7, 8, 0), datetime(2014, 3, 7, 18, 0))
738
+ scheduler.allocate(dates, partly_available=True)
739
+
740
+ token = scheduler.reserve(
741
+ 'user@example.org',
742
+ (datetime(2014, 3, 7, 8, 0), datetime(2014, 3, 7, 10, 0))
743
+ )
744
+ scheduler.commit()
745
+ scheduler.approve_reservations(token)
746
+ scheduler.commit()
747
+
748
+ reservation = scheduler.reservations_by_token(token).one()
749
+ slots = scheduler.reserved_slots_by_reservation(token).all()
750
+ assert slots
751
+ for slot in slots:
752
+ assert slot.source_type == 'reservation'
753
+ assert slot.source_id == reservation.id
754
+
755
+ blocker = scheduler.add_blocker(
756
+ (datetime(2014, 3, 7, 10, 0), datetime(2014, 3, 7, 12, 0))
757
+ )[0]
758
+ assert blocker.id is not None
759
+ scheduler.commit()
760
+
761
+ blocker_slots = scheduler.reserved_slots_by_blocker(blocker.token).all()
762
+ assert blocker_slots
763
+ for slot in blocker_slots:
764
+ assert slot.source_type == 'blocker'
765
+ assert slot.source_id == blocker.id
766
+
767
+
694
768
  def test_remove_blocker_does_not_affect_sibling_blockers(
695
769
  scheduler: Scheduler,
696
770
  ) -> None:
@@ -1835,6 +1909,7 @@ def test_quota_changes_advanced(scheduler: Scheduler) -> None:
1835
1909
  def test_availability(scheduler: Scheduler) -> None:
1836
1910
  start = datetime(2011, 1, 1, 15, 0)
1837
1911
  end = datetime(2011, 1, 1, 16, 0)
1912
+ assert not scheduler.availability()
1838
1913
 
1839
1914
  a = scheduler.allocate(
1840
1915
  (start, end), raster=15, partly_available=True)[0]
@@ -1,7 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from libres.db.scheduler import Scheduler as new_scheduler # noqa: N813
4
-
5
- __all__ = (
6
- 'new_scheduler',
7
- )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes