libres 0.10.2__tar.gz → 1.0.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 (70) hide show
  1. {libres-0.10.2 → libres-1.0.0}/HISTORY.rst +15 -0
  2. {libres-0.10.2/src/libres.egg-info → libres-1.0.0}/PKG-INFO +28 -38
  3. {libres-0.10.2 → libres-1.0.0}/README.rst +1 -1
  4. {libres-0.10.2 → libres-1.0.0}/pyproject.toml +121 -17
  5. libres-1.0.0/setup.cfg +4 -0
  6. libres-1.0.0/setup.py +3 -0
  7. {libres-0.10.2 → libres-1.0.0}/src/libres/__init__.py +1 -1
  8. {libres-0.10.2 → libres-1.0.0}/src/libres/context/core.py +1 -1
  9. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/allocation.py +76 -43
  10. libres-1.0.0/src/libres/db/models/base.py +22 -0
  11. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/blocker.py +25 -39
  12. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/reservation.py +39 -64
  13. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/reserved_slot.py +19 -29
  14. libres-1.0.0/src/libres/db/models/timestamp.py +31 -0
  15. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/types/json_type.py +3 -7
  16. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/types/utcdatetime.py +2 -6
  17. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/types/uuid_type.py +2 -6
  18. {libres-0.10.2 → libres-1.0.0}/src/libres/db/queries.py +3 -3
  19. {libres-0.10.2 → libres-1.0.0}/src/libres/db/scheduler.py +8 -8
  20. {libres-0.10.2 → libres-1.0.0}/src/libres/modules/errors.py +9 -2
  21. {libres-0.10.2 → libres-1.0.0}/src/libres/modules/rasterizer.py +2 -2
  22. {libres-0.10.2 → libres-1.0.0}/src/libres/modules/utils.py +1 -1
  23. {libres-0.10.2 → libres-1.0.0/src/libres.egg-info}/PKG-INFO +28 -38
  24. {libres-0.10.2 → libres-1.0.0}/src/libres.egg-info/SOURCES.txt +1 -2
  25. libres-1.0.0/src/libres.egg-info/requires.txt +4 -0
  26. {libres-0.10.2 → libres-1.0.0}/tests/test_allocation.py +15 -13
  27. {libres-0.10.2 → libres-1.0.0}/tests/test_reservation.py +6 -2
  28. {libres-0.10.2 → libres-1.0.0}/tests/test_reserved_slot.py +6 -4
  29. {libres-0.10.2 → libres-1.0.0}/tests/test_scheduler.py +1 -2
  30. {libres-0.10.2 → libres-1.0.0}/tests/test_scheduler_blockers.py +1 -1
  31. libres-0.10.2/setup.cfg +0 -82
  32. libres-0.10.2/src/libres/db/models/base.py +0 -11
  33. libres-0.10.2/src/libres/db/models/timestamp.py +0 -51
  34. libres-0.10.2/src/libres.egg-info/not-zip-safe +0 -1
  35. libres-0.10.2/src/libres.egg-info/requires.txt +0 -31
  36. {libres-0.10.2 → libres-1.0.0}/LICENSE +0 -0
  37. {libres-0.10.2 → libres-1.0.0}/MANIFEST.in +0 -0
  38. {libres-0.10.2 → libres-1.0.0}/docs/Makefile +0 -0
  39. {libres-0.10.2 → libres-1.0.0}/docs/_static/custom.css +0 -0
  40. {libres-0.10.2 → libres-1.0.0}/docs/_static/favicon.ico +0 -0
  41. {libres-0.10.2 → libres-1.0.0}/docs/_static/logo.svg +0 -0
  42. {libres-0.10.2 → libres-1.0.0}/docs/api.rst +0 -0
  43. {libres-0.10.2 → libres-1.0.0}/docs/concepts.rst +0 -0
  44. {libres-0.10.2 → libres-1.0.0}/docs/conf.py +0 -0
  45. {libres-0.10.2 → libres-1.0.0}/docs/customizations.rst +0 -0
  46. {libres-0.10.2 → libres-1.0.0}/docs/faq.rst +0 -0
  47. {libres-0.10.2 → libres-1.0.0}/docs/index.rst +0 -0
  48. {libres-0.10.2 → libres-1.0.0}/docs/requirements.txt +0 -0
  49. {libres-0.10.2 → libres-1.0.0}/docs/under_the_hood.rst +0 -0
  50. {libres-0.10.2 → libres-1.0.0}/src/libres/.gitignore +0 -0
  51. {libres-0.10.2 → libres-1.0.0}/src/libres/context/__init__.py +0 -0
  52. {libres-0.10.2 → libres-1.0.0}/src/libres/context/exposure.py +0 -0
  53. {libres-0.10.2 → libres-1.0.0}/src/libres/context/registry.py +0 -0
  54. {libres-0.10.2 → libres-1.0.0}/src/libres/context/session.py +0 -0
  55. {libres-0.10.2 → libres-1.0.0}/src/libres/context/settings.py +0 -0
  56. {libres-0.10.2 → libres-1.0.0}/src/libres/db/__init__.py +0 -0
  57. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/__init__.py +0 -0
  58. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/other.py +0 -0
  59. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/timespan.py +0 -0
  60. {libres-0.10.2 → libres-1.0.0}/src/libres/db/models/types/__init__.py +0 -0
  61. {libres-0.10.2 → libres-1.0.0}/src/libres/modules/__init__.py +0 -0
  62. {libres-0.10.2 → libres-1.0.0}/src/libres/modules/events.py +0 -0
  63. {libres-0.10.2 → libres-1.0.0}/src/libres/py.typed +0 -0
  64. {libres-0.10.2 → libres-1.0.0}/src/libres.egg-info/dependency_links.txt +0 -0
  65. {libres-0.10.2 → libres-1.0.0}/src/libres.egg-info/top_level.txt +0 -0
  66. {libres-0.10.2 → libres-1.0.0}/tests/test_registry.py +0 -0
  67. {libres-0.10.2 → libres-1.0.0}/tests/test_session.py +0 -0
  68. {libres-0.10.2 → libres-1.0.0}/tests/test_test.py +0 -0
  69. {libres-0.10.2 → libres-1.0.0}/tests/test_types.py +0 -0
  70. {libres-0.10.2 → libres-1.0.0}/tests/test_utils.py +0 -0
@@ -1,6 +1,21 @@
1
1
  Changelog
2
2
  ---------
3
3
 
4
+ 1.0.0 (10.02.2026)
5
+ ~~~~~~~~~~~~~~~~~~~
6
+
7
+ - Adds support for Python 3.14
8
+ [Daverball]
9
+
10
+ - Adds support for SQLAlchemy 2.0
11
+ [Daverball]
12
+
13
+ - Drops support for Python 3.9
14
+ [Daverball]
15
+
16
+ - Drops support for SQLAlchemy 1.4
17
+ [Daverball]
18
+
4
19
  0.10.2 (05.02.2026)
5
20
  ~~~~~~~~~~~~~~~~~~~
6
21
 
@@ -1,63 +1,38 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libres
3
- Version: 0.10.2
3
+ Version: 1.0.0
4
4
  Summary: A library to reserve things
5
- Home-page: http://github.com/seantis/libres/
6
- Author: Denis Krienbühl
7
- Author-email: denis@href.ch
8
- Maintainer: Seantis GmbH
9
- Maintainer-email: info@seantis.ch
10
- License: BSD
11
- Classifier: Development Status :: 4 - Beta
5
+ Author-email: Denis Krienbühl <denis@href.ch>
6
+ Maintainer-email: Seantis GmbH <info@seantis.ch>
7
+ License-Expression: MIT
8
+ Project-URL: Repository, http://github.com/seantis/libres
9
+ Classifier: Framework :: Pytest
10
+ Classifier: Development Status :: 5 - Production/Stable
12
11
  Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: BSD License
14
12
  Classifier: Operating System :: OS Independent
15
13
  Classifier: Programming Language :: Python
16
14
  Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.9
18
15
  Classifier: Programming Language :: Python :: 3.10
19
16
  Classifier: Programming Language :: Python :: 3.11
20
17
  Classifier: Programming Language :: Python :: 3.12
21
18
  Classifier: Programming Language :: Python :: 3.13
22
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
- Requires-Python: >=3.9
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: Implementation :: CPython
21
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
22
+ Requires-Python: >=3.10
24
23
  Description-Content-Type: text/x-rst
25
24
  License-File: LICENSE
26
25
  Requires-Dist: python-dateutil
27
- Requires-Dist: psycopg2-binary
28
26
  Requires-Dist: pytz
29
27
  Requires-Dist: sedate>=1.0.0
30
- Requires-Dist: SQLAlchemy<2,>=0.9
31
- Provides-Extra: dev
32
- Requires-Dist: bandit[toml]; extra == "dev"
33
- Requires-Dist: bump-my-version; extra == "dev"
34
- Requires-Dist: flake8; extra == "dev"
35
- Requires-Dist: flake8-type-checking; extra == "dev"
36
- Requires-Dist: pre-commit; extra == "dev"
37
- Requires-Dist: pre-commit-uv; extra == "dev"
38
- Requires-Dist: ruff; extra == "dev"
39
- Requires-Dist: uv; extra == "dev"
40
- Requires-Dist: tox; extra == "dev"
41
- Requires-Dist: tox-uv; extra == "dev"
42
- Provides-Extra: test
43
- Requires-Dist: jsonpickle; extra == "test"
44
- Requires-Dist: pytest; extra == "test"
45
- Requires-Dist: pytest-codecov[git]; extra == "test"
46
- Requires-Dist: testing.postgresql; extra == "test"
47
- Provides-Extra: mypy
48
- Requires-Dist: mypy; extra == "mypy"
49
- Requires-Dist: sqlalchemy-stubs; extra == "mypy"
50
- Requires-Dist: types-psycopg2; extra == "mypy"
51
- Requires-Dist: types-python-dateutil; extra == "mypy"
52
- Requires-Dist: types-pytz; extra == "mypy"
53
- Requires-Dist: typing-extensions; extra == "mypy"
28
+ Requires-Dist: SQLAlchemy<2.1.0,>=2.0.0
54
29
  Dynamic: license-file
55
30
 
56
31
  Libres
57
32
  ======
58
33
 
59
34
  Libres is a reservations management library to reserve things like tables at
60
- a restaurant or tickets at an event. It works with Python 3.9+
35
+ a restaurant or tickets at an event. It works with Python 3.10+
61
36
  and requires Postgresql 9.2+.
62
37
 
63
38
  `Documentation <http://libres.readthedocs.org/en/latest/>`_ | `Source <http://github.com/seantis/libres/>`_ | `Bugs <http://github.com/seantis/libres/issues>`_
@@ -142,6 +117,21 @@ After this, create a new release on Github.
142
117
  Changelog
143
118
  ---------
144
119
 
120
+ 1.0.0 (10.02.2026)
121
+ ~~~~~~~~~~~~~~~~~~~
122
+
123
+ - Adds support for Python 3.14
124
+ [Daverball]
125
+
126
+ - Adds support for SQLAlchemy 2.0
127
+ [Daverball]
128
+
129
+ - Drops support for Python 3.9
130
+ [Daverball]
131
+
132
+ - Drops support for SQLAlchemy 1.4
133
+ [Daverball]
134
+
145
135
  0.10.2 (05.02.2026)
146
136
  ~~~~~~~~~~~~~~~~~~~
147
137
 
@@ -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.9+
5
+ a restaurant or tickets at an event. It works with Python 3.10+
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>`_
@@ -2,6 +2,96 @@
2
2
  requires = ["setuptools>=42", "wheel"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
+ [project]
6
+ name = "libres"
7
+ dynamic = ["version", "readme"]
8
+ description = "A library to reserve things"
9
+ requires-python = ">=3.10"
10
+ authors = [
11
+ { name = "Denis Krienbühl", email = "denis@href.ch" },
12
+ ]
13
+ maintainers = [
14
+ { name = "Seantis GmbH", email = "info@seantis.ch" },
15
+ ]
16
+ license = "MIT"
17
+ license-files = ["LICENSE"]
18
+ classifiers = [
19
+ "Framework :: Pytest",
20
+ "Development Status :: 5 - Production/Stable",
21
+ "Intended Audience :: Developers",
22
+ "Operating System :: OS Independent",
23
+ "Programming Language :: Python",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: 3.14",
30
+ "Programming Language :: Python :: Implementation :: CPython",
31
+ "Programming Language :: Python :: Implementation :: PyPy",
32
+ ]
33
+ dependencies = [
34
+ "python-dateutil",
35
+ "pytz",
36
+ "sedate >= 1.0.0",
37
+ "SQLAlchemy >= 2.0.0, < 2.1.0",
38
+ ]
39
+
40
+ [project.urls]
41
+ Repository = "http://github.com/seantis/libres"
42
+
43
+ [tool.setuptools.package-data]
44
+ libres = ["py.typed"]
45
+
46
+ [tool.setuptools.dynamic]
47
+ version = {attr = "libres.__version__"}
48
+ readme = {file = ["README.rst", "HISTORY.rst"]}
49
+
50
+ [dependency-groups]
51
+ ruff = [
52
+ "ruff",
53
+ ]
54
+ flake8 = [
55
+ "flake8",
56
+ "flake8-pyproject",
57
+ "flake8-type-checking",
58
+ ]
59
+ bandit = [
60
+ "bandit[toml]",
61
+ ]
62
+ mypy = [
63
+ "mypy",
64
+ "types-python-dateutil",
65
+ "types-pytz",
66
+ "typing-extensions",
67
+ ]
68
+ lint = [
69
+ {include-group = "flake8"},
70
+ {include-group = "ruff"},
71
+ {include-group = "bandit"},
72
+ {include-group = "mypy"},
73
+ ]
74
+ test = [
75
+ "jsonpickle",
76
+ "psycopg2-binary",
77
+ "pytest",
78
+ "pytest-codecov[git]",
79
+ "testing.postgresql",
80
+ ]
81
+ tox = [
82
+ "tox>=4.22",
83
+ "tox-uv",
84
+ ]
85
+ dev = [
86
+ "bump-my-version",
87
+ "pre-commit",
88
+ "pre-commit-uv",
89
+ "uv",
90
+ {include-group = "tox"},
91
+ {include-group = "test"},
92
+ {include-group = "lint"},
93
+ ]
94
+
5
95
  [tool.pytest.ini_options]
6
96
  log_level = "INFO"
7
97
  testpaths = ["tests"]
@@ -11,7 +101,7 @@ branch = true
11
101
  source = ["src"]
12
102
 
13
103
  [tool.bumpversion]
14
- current_version = "0.10.2"
104
+ current_version = "1.0.0"
15
105
  commit = true
16
106
  message = "Release {new_version}"
17
107
  tag = true
@@ -35,20 +125,36 @@ replace = """
35
125
  """
36
126
 
37
127
  [tool.mypy]
38
- python_version = "3.9"
128
+ python_version = "3.10"
39
129
  namespace_packages = true
40
130
  explicit_package_bases = true
41
131
  strict = true
42
132
  warn_unreachable = true
43
- # FIXME: remove this exclusion when upgrading to SQlAlchemy 2.0
44
- untyped_calls_exclude = "sqlalchemy"
45
- plugins = "sqlmypy"
46
133
  mypy_path = "$MYPY_CONFIG_FILE_DIR/src"
47
134
 
48
135
  [tool.bandit]
49
136
  exclude_dirs = ["tests"]
50
137
  skips = ["B101"]
51
138
 
139
+ [tool.flake8]
140
+ select = ["TC0" , "TC1"]
141
+ per_file_ignores = [
142
+ "*.pyi: TC",
143
+ "tests/**.py: TC",
144
+ ]
145
+ exclude=[
146
+ ".venv",
147
+ "venv",
148
+ ".git",
149
+ ".tox",
150
+ "dist",
151
+ "docs",
152
+ "*lib/python*",
153
+ "*egg",
154
+ "build"
155
+ ]
156
+ type-checking-sqlalchemy-enabled = true
157
+
52
158
  [tool.ruff]
53
159
  exclude = [
54
160
  ".bzr",
@@ -87,7 +193,7 @@ include = [
87
193
  ]
88
194
  line-length = 79
89
195
  indent-width = 4
90
- target-version = "py39"
196
+ target-version = "py310"
91
197
 
92
198
  [tool.ruff.lint]
93
199
  select = [
@@ -221,11 +327,11 @@ docstring-code-line-length = "dynamic"
221
327
  [tool.tox]
222
328
  requires = ["tox>=4.21"]
223
329
  envlist = [
224
- "3.9",
225
330
  "3.10",
226
331
  "3.11",
227
332
  "3.12",
228
333
  "3.13",
334
+ "3.14",
229
335
  "flake8",
230
336
  "ruff",
231
337
  "bandit",
@@ -234,16 +340,17 @@ envlist = [
234
340
  ]
235
341
 
236
342
  [tool.tox.gh.python]
237
- "3.9" = ["3.9"]
238
343
  "3.10" = ["3.10"]
239
344
  "3.11" = ["3.11", "flake8", "bandit", "ruff", "mypy"]
240
345
  "3.12" = ["3.12"]
241
346
  "3.13" = ["3.13"]
347
+ "3.14" = ["3.14"]
242
348
 
243
349
  [tool.tox.env_run_base]
244
350
  use_develop = true
245
351
  set_env = { COVERAGE_FILE = ".coverage.{envname}" }
246
- deps = ["-e{toxinidir}[test]"]
352
+ deps = ["-e{toxinidir}"]
353
+ dependency_groups = ["test"]
247
354
  commands = [
248
355
  [
249
356
  "pytest",
@@ -255,34 +362,31 @@ commands = [
255
362
  [tool.tox.env.ruff]
256
363
  base_python = ["python3.11"]
257
364
  skip_install = true
258
- deps = ["ruff"]
365
+ dependency_groups = ["ruff"]
259
366
  commands = [["ruff", "check"]]
260
367
 
261
368
  [tool.tox.env.flake8]
262
369
  base_python = ["python3.11"]
263
370
  skip_install = true
264
- deps = [
265
- "flake8",
266
- "flake8-type-checking",
267
- ]
371
+ dependency_groups = ["flake8"]
268
372
  commands = [["flake8", "src{/}", "tests{/}"]]
269
373
 
270
374
  [tool.tox.env.bandit]
271
375
  base_python = ["python3.11"]
272
376
  skip_install = true
273
- deps = ["bandit[toml]"]
377
+ dependency_groups = ["bandit"]
274
378
  commands = [["bandit", "-q", "-c", "pyproject.toml", "-r", "src"]]
275
379
 
276
380
  [tool.tox.env.mypy]
277
381
  base_python = ["python3.11"]
278
382
  skip_install = true
279
- deps = ["-e{toxinidir}[mypy]"]
383
+ dependency_groups = ["mypy"]
280
384
  commands = [
281
- ["mypy", "-p", "libres", "--python-version", "3.9"],
282
385
  ["mypy", "-p", "libres", "--python-version", "3.10"],
283
386
  ["mypy", "-p", "libres", "--python-version", "3.11"],
284
387
  ["mypy", "-p", "libres", "--python-version", "3.12"],
285
388
  ["mypy", "-p", "libres", "--python-version", "3.13"],
389
+ ["mypy", "-p", "libres", "--python-version", "3.14"],
286
390
  ]
287
391
 
288
392
  [tool.tox.env.report]
libres-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
libres-1.0.0/setup.py ADDED
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup()
@@ -5,7 +5,7 @@ from libres.db import new_scheduler
5
5
 
6
6
  registry = create_default_registry() # noqa: RUF067
7
7
 
8
- __version__ = '0.10.2'
8
+ __version__ = '1.0.0'
9
9
  __all__ = (
10
10
  'new_scheduler',
11
11
  'registry'
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
17
17
  from collections.abc import Iterator
18
18
  from sqlalchemy.orm import Session
19
19
  from sqlalchemy.orm.session import SessionTransaction
20
- from typing_extensions import TypeAlias
20
+ from typing import TypeAlias
21
21
  from uuid import UUID
22
22
 
23
23
  from libres.context.registry import Registry
@@ -6,15 +6,16 @@ from datetime import datetime, timedelta, time
6
6
  from itertools import groupby
7
7
  from sqlalchemy import types
8
8
  from sqlalchemy.ext.hybrid import hybrid_property
9
- from sqlalchemy.schema import Column
10
9
  from sqlalchemy.schema import Index
11
10
  from sqlalchemy.schema import UniqueConstraint
12
11
  from sqlalchemy.orm import object_session
12
+ from sqlalchemy.orm import mapped_column
13
13
  from sqlalchemy.orm import relationship
14
+ from sqlalchemy.orm import Mapped
14
15
  from sqlalchemy.orm.util import has_identity
16
+ from uuid import UUID
15
17
 
16
18
  from libres.db.models.base import ORMBase
17
- from libres.db.models.types import UUID, UTCDateTime, JSON
18
19
  from libres.db.models.other import OtherModels
19
20
  from libres.db.models.timestamp import TimestampMixin
20
21
  from libres.modules import utils
@@ -31,7 +32,6 @@ from typing import Any
31
32
  from typing import TypeVar
32
33
  from typing import TYPE_CHECKING
33
34
  if TYPE_CHECKING:
34
- import uuid
35
35
  from collections.abc import Iterator
36
36
  from sedate.types import TzInfoOrName
37
37
  from sqlalchemy.orm import Query
@@ -46,6 +46,11 @@ if TYPE_CHECKING:
46
46
 
47
47
  class _ReservationIdRow(NamedTuple):
48
48
  id: int
49
+ else:
50
+ # NOTE: Avoids us having to register a special type mapping
51
+ # for `Raster`, since we don't use an enum to represent
52
+ # these values.
53
+ Raster = int
49
54
 
50
55
 
51
56
  class Allocation(TimestampMixin, ORMBase, OtherModels):
@@ -73,76 +78,57 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
73
78
  __tablename__ = 'allocations'
74
79
 
75
80
  #: the id of the allocation, autoincremented
76
- id: Column[int] = Column(
77
- types.Integer(),
81
+ id: Mapped[int] = mapped_column(
78
82
  primary_key=True,
79
83
  autoincrement=True
80
84
  )
81
85
 
82
86
  #: the resource uuid of the allocation, may not be an actual resource
83
87
  #: see :class:`.models.Allocation` for more information
84
- resource: Column[uuid.UUID] = Column(UUID(), nullable=False)
88
+ resource: Mapped[UUID]
85
89
 
86
90
  #: the polymorphic type of the allocation
87
- type: Column[str] = Column(types.Text(), nullable=False, default='generic')
91
+ type: Mapped[str] = mapped_column(types.Text(), default='generic')
88
92
 
89
93
  #: resource of which this allocation is a mirror. If the mirror_of
90
94
  #: attribute equals the resource, this is a real resource
91
95
  #: see :class:`.models.Allocation` for more information
92
- mirror_of: Column[uuid.UUID] = Column(UUID(), nullable=False)
96
+ mirror_of: Mapped[UUID]
93
97
 
94
98
  #: Group uuid to which this allocation belongs to. Every allocation has a
95
99
  #: group but some allocations may be the only one in their group.
96
- group: Column[uuid.UUID] = Column(UUID(), nullable=False)
100
+ group: Mapped[UUID]
97
101
 
98
102
  #: Number of times this allocation may be reserved
99
- # FIXME: Why is this not nullable=False? For now we pretend that it is
100
- quota: Column[int] = Column(types.Integer(), default=1)
103
+ quota: Mapped[int] = mapped_column(default=1)
101
104
 
102
105
  #: Maximum number of times this allocation may be reserved with one
103
106
  #: single reservation.
104
- quota_limit: Column[int] = Column(
105
- types.Integer(),
106
- default=0,
107
- nullable=False
108
- )
107
+ quota_limit: Mapped[int] = mapped_column(default=0)
109
108
 
110
109
  #: Partly available allocations may be reserved partially. How They may
111
110
  #: be partitioned is defined by the allocation's raster.
112
- partly_available: Column[bool] = Column(types.Boolean(), default=False)
111
+ partly_available: Mapped[bool] = mapped_column(default=False)
113
112
 
114
113
  #: True if reservations for this allocation must be approved manually.
115
- approve_manually: Column[bool] = Column(types.Boolean(), default=False)
114
+ approve_manually: Mapped[bool] = mapped_column(default=False)
116
115
 
117
116
  #: The timezone this allocation resides in.
118
117
  # FIXME: Why is this not nullable=False? A lot of properties rely on this!
119
- timezone: Column[str | None] = Column(types.String())
118
+ timezone: Mapped[str | None]
120
119
 
121
120
  #: Custom data reserved for the user
122
- data: Column[dict[str, Any] | None] = Column(
123
- JSON(),
124
- nullable=True
125
- )
121
+ data: Mapped[dict[str, Any] | None]
126
122
 
127
- _start: Column[datetime] = Column(
128
- UTCDateTime(timezone=False),
129
- nullable=False
130
- )
131
- _end: Column[datetime] = Column(
132
- UTCDateTime(timezone=False),
133
- nullable=False
134
- )
135
- _raster: Column[Raster] = Column(
136
- types.Integer(), # type:ignore[arg-type]
137
- nullable=False
138
- )
123
+ _start: Mapped[datetime]
124
+ _end: Mapped[datetime]
125
+ _raster: Mapped[Raster]
139
126
 
140
- # Reserved_slots are eagerly joined since we usually want both
127
+ # Reserved_slots are eagerly loaded since we usually want both
141
128
  # allocation and reserved_slots. There's barely a function which does
142
129
  # not need to know about reserved slots when working with allocations.
143
- reserved_slots: relationship[list[ReservedSlot]] = relationship(
144
- 'ReservedSlot',
145
- lazy='joined',
130
+ reserved_slots: Mapped[list[ReservedSlot]] = relationship(
131
+ lazy='selectin',
146
132
  cascade='all, delete-orphan',
147
133
  back_populates='allocation'
148
134
  )
@@ -157,6 +143,33 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
157
143
  'polymorphic_on': type
158
144
  }
159
145
 
146
+ def __init__(
147
+ self,
148
+ resource: UUID | None = None,
149
+ start: datetime | None = None,
150
+ end: datetime | None = None,
151
+ raster: Raster | None = None,
152
+ timezone: str | None = None,
153
+ quota: int = 1,
154
+ quota_limit: int = 0,
155
+ partly_available: bool = False,
156
+ approve_manually: bool = False,
157
+ ) -> None:
158
+ if resource is not None:
159
+ self.resource = resource
160
+ if start is not None:
161
+ self.set_start(start)
162
+ if end is not None:
163
+ self.set_end(end)
164
+ if raster is not None:
165
+ self.set_raster(raster)
166
+ if timezone is not None:
167
+ self.timezone = timezone
168
+ self.quota = quota
169
+ self.quota_limit = quota_limit
170
+ self.partly_available = partly_available
171
+ self.approve_manually = approve_manually
172
+
160
173
  def __eq__(self, other: object) -> bool:
161
174
  if not isinstance(other, Allocation):
162
175
  return False
@@ -172,6 +185,7 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
172
185
  allocation.mirror_of = self.mirror_of
173
186
  allocation.group = self.group
174
187
  allocation.quota = self.quota
188
+ allocation.quota_limit = self.quota_limit
175
189
  allocation.partly_available = self.partly_available
176
190
  allocation.approve_manually = self.approve_manually
177
191
  allocation.timezone = self.timezone
@@ -492,9 +506,14 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
492
506
  "Don't call if the allocation does not yet exist"
493
507
  )
494
508
 
509
+ session = object_session(self)
510
+ assert session is not None, (
511
+ "Don't call if the allocation is detached"
512
+ )
513
+
495
514
  Reservation = self.models.Reservation # noqa: N806
496
515
  query: Query[_ReservationIdRow]
497
- query = object_session(self).query(Reservation.id)
516
+ query = session.query(Reservation.id) # type: ignore[assignment]
498
517
  query = query.filter(Reservation.target == self.group)
499
518
  query = query.filter(Reservation.status == 'pending')
500
519
 
@@ -618,7 +637,12 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
618
637
  def in_group(self) -> int:
619
638
  """True if the event is in any group."""
620
639
 
621
- query = object_session(self).query(Allocation.id)
640
+ session = object_session(self)
641
+ assert session is not None, (
642
+ "Don't call if the allocation is detached"
643
+ )
644
+
645
+ query = session.query(Allocation.id)
622
646
  query = query.filter(Allocation.resource == self.resource)
623
647
  query = query.filter(Allocation.group == self.group)
624
648
  query = query.limit(2)
@@ -849,9 +873,13 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
849
873
  if self.is_master:
850
874
  return self
851
875
  else:
876
+ session = object_session(self)
877
+ assert session is not None, (
878
+ "Don't call if the allocation is detached"
879
+ )
852
880
  # FIXME: This should either query `self.__class__` or
853
881
  # we need to return `Allocation` rather than `Self`
854
- query: Query[Self] = object_session(self).query(Allocation)
882
+ query: Query[Self] = session.query(Allocation)
855
883
  query = query.filter(Allocation._start == self._start)
856
884
  query = query.filter(Allocation.resource == self.mirror_of)
857
885
 
@@ -875,9 +903,14 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
875
903
  assert self.is_master
876
904
  return [self]
877
905
 
906
+ session = object_session(self)
907
+ assert session is not None, (
908
+ "Don't call if the allocation is detached"
909
+ )
910
+
878
911
  # FIXME: This should either query `self.__class__` or
879
912
  # we need to return `Allocation` rather than `Self`
880
- query: Query[Self] = object_session(self).query(Allocation)
913
+ query: Query[Self] = session.query(Allocation)
881
914
  query = query.filter(Allocation.mirror_of == self.mirror_of)
882
915
  query = query.filter(Allocation._start == self._start)
883
916
 
@@ -0,0 +1,22 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import datetime
4
+ from sqlalchemy.orm import registry
5
+ from sqlalchemy.orm import DeclarativeBase
6
+ from uuid import UUID as PythonUUID
7
+
8
+ from .types import JSON
9
+ from .types import UTCDateTime
10
+ from .types import UUID
11
+
12
+
13
+ from typing import Any
14
+
15
+
16
+ class ORMBase(DeclarativeBase):
17
+
18
+ registry = registry(type_annotation_map={
19
+ datetime: UTCDateTime(timezone=False),
20
+ dict[str, Any]: JSON,
21
+ PythonUUID: UUID,
22
+ })