piccolo 1.4.2__py3-none-any.whl → 1.5.1__py3-none-any.whl

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 (35) hide show
  1. piccolo/__init__.py +1 -1
  2. piccolo/apps/asgi/commands/new.py +1 -0
  3. piccolo/apps/asgi/commands/templates/app/_lilya_app.py.jinja +45 -0
  4. piccolo/apps/asgi/commands/templates/app/app.py.jinja +2 -0
  5. piccolo/apps/asgi/commands/templates/app/home/_lilya_endpoints.py.jinja +21 -0
  6. piccolo/apps/asgi/commands/templates/app/home/endpoints.py.jinja +2 -0
  7. piccolo/apps/asgi/commands/templates/app/home/templates/home.html.jinja_raw +5 -0
  8. piccolo/apps/migrations/auto/migration_manager.py +9 -9
  9. piccolo/apps/migrations/auto/serialisation.py +2 -4
  10. piccolo/apps/migrations/commands/backwards.py +9 -7
  11. piccolo/apps/migrations/commands/base.py +3 -3
  12. piccolo/apps/migrations/commands/forwards.py +3 -3
  13. piccolo/apps/playground/commands/run.py +1 -0
  14. piccolo/apps/user/tables.py +1 -0
  15. piccolo/columns/base.py +5 -3
  16. piccolo/columns/column_types.py +97 -116
  17. piccolo/columns/reference.py +1 -0
  18. piccolo/conf/apps.py +1 -2
  19. piccolo/query/methods/objects.py +8 -8
  20. piccolo/query/methods/select.py +4 -8
  21. piccolo/query/mixins.py +3 -3
  22. piccolo/query/proxy.py +3 -2
  23. piccolo/table.py +19 -13
  24. piccolo/utils/pydantic.py +6 -0
  25. {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/METADATA +2 -2
  26. {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/RECORD +35 -33
  27. tests/columns/test_array.py +22 -0
  28. tests/columns/test_reference.py +1 -0
  29. tests/conf/example.py +1 -0
  30. tests/table/test_metaclass.py +12 -0
  31. tests/utils/test_pydantic.py +28 -0
  32. {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/LICENSE +0 -0
  33. {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/WHEEL +0 -0
  34. {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/entry_points.txt +0 -0
  35. {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/top_level.txt +0 -0
piccolo/__init__.py CHANGED
@@ -1 +1 @@
1
- __VERSION__ = "1.4.2"
1
+ __VERSION__ = "1.5.1"
@@ -16,6 +16,7 @@ ROUTER_DEPENDENCIES = {
16
16
  "blacksheep": ["blacksheep"],
17
17
  "litestar": ["litestar"],
18
18
  "esmerald": ["esmerald"],
19
+ "lilya": ["lilya"],
19
20
  }
20
21
  ROUTERS = list(ROUTER_DEPENDENCIES.keys())
21
22
 
@@ -0,0 +1,45 @@
1
+ from piccolo_admin.endpoints import create_admin
2
+ from piccolo_api.crud.endpoints import PiccoloCRUD
3
+ from piccolo.engine import engine_finder
4
+ from lilya.routing import Path, Include
5
+ from lilya.apps import Lilya
6
+ from lilya.staticfiles import StaticFiles
7
+
8
+ from home.endpoints import HomeController
9
+ from home.piccolo_app import APP_CONFIG
10
+ from home.tables import Task
11
+
12
+
13
+ app = Lilya(
14
+ routes=[
15
+ Path("/", HomeController),
16
+ Include(
17
+ "/admin/",
18
+ create_admin(
19
+ tables=APP_CONFIG.table_classes,
20
+ # Required when running under HTTPS:
21
+ # allowed_hosts=['my_site.com']
22
+ )
23
+ ),
24
+ Include("/static/", StaticFiles(directory="static")),
25
+ Include("/tasks/", PiccoloCRUD(table=Task))
26
+ ],
27
+ )
28
+
29
+
30
+ @app.on_event("on_startup")
31
+ async def open_database_connection_pool():
32
+ try:
33
+ engine = engine_finder()
34
+ await engine.start_connection_pool()
35
+ except Exception:
36
+ print("Unable to connect to the database")
37
+
38
+
39
+ @app.on_event("on_shutdown")
40
+ async def close_database_connection_pool():
41
+ try:
42
+ engine = engine_finder()
43
+ await engine.close_connection_pool()
44
+ except Exception:
45
+ print("Unable to connect to the database")
@@ -8,4 +8,6 @@
8
8
  {% include '_litestar_app.py.jinja' %}
9
9
  {% elif router == 'esmerald' %}
10
10
  {% include '_esmerald_app.py.jinja' %}
11
+ {% elif router == 'lilya' %}
12
+ {% include '_lilya_app.py.jinja' %}
11
13
  {% endif %}
@@ -0,0 +1,21 @@
1
+ import os
2
+
3
+ import jinja2
4
+ from lilya.controllers import Controller
5
+ from lilya.responses import HTMLResponse
6
+
7
+
8
+ ENVIRONMENT = jinja2.Environment(
9
+ loader=jinja2.FileSystemLoader(
10
+ searchpath=os.path.join(os.path.dirname(__file__), "templates")
11
+ )
12
+ )
13
+
14
+
15
+ class HomeController(Controller):
16
+ async def get(self, request):
17
+ template = ENVIRONMENT.get_template("home.html.jinja")
18
+
19
+ content = template.render(title="Piccolo + ASGI",)
20
+
21
+ return HTMLResponse(content)
@@ -6,4 +6,6 @@
6
6
  {% include '_litestar_endpoints.py.jinja' %}
7
7
  {% elif router == 'esmerald' %}
8
8
  {% include '_esmerald_endpoints.py.jinja' %}
9
+ {% elif router == 'lilya' %}
10
+ {% include '_lilya_endpoints.py.jinja' %}
9
11
  {% endif %}
@@ -61,6 +61,11 @@
61
61
  <li><a href="/admin/">Admin</a></li>
62
62
  <li><a href="/docs/swagger">Swagger API</a></li>
63
63
  </ul>
64
+ <h3>Lilya</h3>
65
+ <ul>
66
+ <li><a href="/admin/">Admin</a></li>
67
+ <li><a href="/tasks/">JSON endpoint</a></li>
68
+ </ul>
64
69
  </section>
65
70
  </div>
66
71
  {% endblock content %}
@@ -737,9 +737,9 @@ class MigrationManager:
737
737
  async def _run_add_tables(self, backwards: bool = False):
738
738
  table_classes: t.List[t.Type[Table]] = []
739
739
  for add_table in self.add_tables:
740
- add_columns: t.List[
741
- AddColumnClass
742
- ] = self.add_columns.for_table_class_name(add_table.class_name)
740
+ add_columns: t.List[AddColumnClass] = (
741
+ self.add_columns.for_table_class_name(add_table.class_name)
742
+ )
743
743
  _Table: t.Type[Table] = create_table_class(
744
744
  class_name=add_table.class_name,
745
745
  class_kwargs={
@@ -792,9 +792,9 @@ class MigrationManager:
792
792
  if table_class_name in [i.class_name for i in self.add_tables]:
793
793
  continue # No need to add columns to new tables
794
794
 
795
- add_columns: t.List[
796
- AddColumnClass
797
- ] = self.add_columns.for_table_class_name(table_class_name)
795
+ add_columns: t.List[AddColumnClass] = (
796
+ self.add_columns.for_table_class_name(table_class_name)
797
+ )
798
798
 
799
799
  ###############################################################
800
800
  # Define the table, with the columns, so the metaclass
@@ -838,9 +838,9 @@ class MigrationManager:
838
838
  else:
839
839
  primary_key = existing_table._meta.primary_key
840
840
 
841
- table_class_members[
842
- primary_key._meta.name
843
- ] = primary_key
841
+ table_class_members[primary_key._meta.name] = (
842
+ primary_key
843
+ )
844
844
 
845
845
  break
846
846
 
@@ -25,8 +25,7 @@ from .serialisation_legacy import deserialise_legacy_params
25
25
 
26
26
  class CanConflictWithGlobalNames(abc.ABC):
27
27
  @abc.abstractmethod
28
- def warn_if_is_conflicting_with_global_name(self):
29
- ...
28
+ def warn_if_is_conflicting_with_global_name(self): ...
30
29
 
31
30
 
32
31
  class UniqueGlobalNamesMeta(type):
@@ -237,8 +236,7 @@ class Import(CanConflictWithGlobalNames):
237
236
 
238
237
  class Definition(CanConflictWithGlobalNames, abc.ABC):
239
238
  @abc.abstractmethod
240
- def __repr__(self):
241
- ...
239
+ def __repr__(self): ...
242
240
 
243
241
  ###########################################################################
244
242
  # To allow sorting:
@@ -31,9 +31,9 @@ class BackwardsMigrationManager(BaseMigrationManager):
31
31
  super().__init__()
32
32
 
33
33
  async def run_migrations_backwards(self, app_config: AppConfig):
34
- migration_modules: t.Dict[
35
- str, MigrationModule
36
- ] = self.get_migration_modules(app_config.migrations_folder_path)
34
+ migration_modules: t.Dict[str, MigrationModule] = (
35
+ self.get_migration_modules(app_config.migrations_folder_path)
36
+ )
37
37
 
38
38
  ran_migration_ids = await Migration.get_migrations_which_ran(
39
39
  app_name=self.app_name
@@ -78,9 +78,11 @@ class BackwardsMigrationManager(BaseMigrationManager):
78
78
  _continue = (
79
79
  "y"
80
80
  if self.auto_agree
81
- else input(f"Reverse {n} migration{'s' if n != 1 else ''}? [y/N] ")
81
+ else input(
82
+ f"Reverse {n} migration{'s' if n != 1 else ''}? [y/N] "
83
+ ).lower()
82
84
  )
83
- if _continue in "yY":
85
+ if _continue == "y":
84
86
  for migration_id in reversed_migration_ids:
85
87
  migration_module = migration_modules[migration_id]
86
88
  response = await migration_module.forwards()
@@ -131,10 +133,10 @@ async def run_backwards(
131
133
  "apps:\n"
132
134
  f"{', '.join(names)}\n"
133
135
  "Are you sure you want to continue? [y/N] "
134
- )
136
+ ).lower()
135
137
  )
136
138
 
137
- if _continue not in "yY":
139
+ if _continue != "y":
138
140
  return MigrationResult(success=False, message="user cancelled")
139
141
  for _app_name in sorted_app_names:
140
142
  print_heading(_app_name)
@@ -88,9 +88,9 @@ class BaseMigrationManager(Finder):
88
88
 
89
89
  migrations_folder = app_config.migrations_folder_path
90
90
 
91
- migration_modules: t.Dict[
92
- str, MigrationModule
93
- ] = self.get_migration_modules(migrations_folder)
91
+ migration_modules: t.Dict[str, MigrationModule] = (
92
+ self.get_migration_modules(migrations_folder)
93
+ )
94
94
 
95
95
  migration_ids = sorted(migration_modules.keys())
96
96
 
@@ -32,9 +32,9 @@ class ForwardsMigrationManager(BaseMigrationManager):
32
32
  app_name=app_config.app_name
33
33
  )
34
34
 
35
- migration_modules: t.Dict[
36
- str, MigrationModule
37
- ] = self.get_migration_modules(app_config.migrations_folder_path)
35
+ migration_modules: t.Dict[str, MigrationModule] = (
36
+ self.get_migration_modules(app_config.migrations_folder_path)
37
+ )
38
38
 
39
39
  ids = self.get_migration_ids(migration_modules)
40
40
  n = len(ids)
@@ -2,6 +2,7 @@
2
2
  Populates a database with an example schema and data, and launches a shell
3
3
  for interacting with the data using Piccolo.
4
4
  """
5
+
5
6
  import datetime
6
7
  import sys
7
8
  import typing as t
@@ -1,6 +1,7 @@
1
1
  """
2
2
  A User model, used for authentication.
3
3
  """
4
+
4
5
  from __future__ import annotations
5
6
 
6
7
  import datetime
piccolo/columns/base.py CHANGED
@@ -887,9 +887,11 @@ class Column(Selectable):
887
887
  return (
888
888
  "'{"
889
889
  + ", ".join(
890
- f'"{i}"'
891
- if isinstance(i, str)
892
- else str(self.get_sql_value(i))
890
+ (
891
+ f'"{i}"'
892
+ if isinstance(i, str)
893
+ else str(self.get_sql_value(i))
894
+ )
893
895
  for i in value
894
896
  )
895
897
  ) + "}'"