ecodev-core 0.0.29__py3-none-any.whl → 0.0.31__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.

Potentially problematic release.


This version of ecodev-core might be problematic. Click here for more details.

ecodev_core/__init__.py CHANGED
@@ -42,12 +42,15 @@ from ecodev_core.db_retrieval import get_rows
42
42
  from ecodev_core.db_retrieval import ServerSideField
43
43
  from ecodev_core.email_sender import send_email
44
44
  from ecodev_core.enum_utils import enum_converter
45
+ from ecodev_core.list_utils import first_func_or_default
45
46
  from ecodev_core.list_utils import first_or_default
46
47
  from ecodev_core.list_utils import first_transformed_or_default
47
48
  from ecodev_core.list_utils import group_by
48
49
  from ecodev_core.list_utils import group_by_value
49
50
  from ecodev_core.list_utils import lselect
50
51
  from ecodev_core.list_utils import lselectfirst
52
+ from ecodev_core.list_utils import sort_by_keys
53
+ from ecodev_core.list_utils import sort_by_values
51
54
  from ecodev_core.logger import log_critical
52
55
  from ecodev_core.logger import logger_get
53
56
  from ecodev_core.pandas_utils import get_excelfile
@@ -85,4 +88,5 @@ __all__ = [
85
88
  'generic_insertion', 'custom_equal', 'is_authorized_user', 'get_method', 'AppActivity',
86
89
  'fastapi_monitor', 'dash_monitor', 'is_monitoring_user', 'get_recent_activities', 'select_user',
87
90
  'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user',
88
- 'datify', 'safe_drop_columns', 'get_value', 'is_null', 'send_email']
91
+ 'datify', 'safe_drop_columns', 'get_value', 'is_null', 'send_email', 'first_func_or_default',
92
+ 'sort_by_keys', 'sort_by_values']
@@ -2,6 +2,8 @@
2
2
  Module implementing postgresql connection
3
3
  """
4
4
  from typing import Callable
5
+ from typing import List
6
+ from typing import Optional
5
7
  from urllib.parse import quote
6
8
 
7
9
  from pydantic_settings import BaseSettings
@@ -34,11 +36,17 @@ DB_URL = f'postgresql://{DB.db_username}:{_PASSWORD}@{DB.db_host}:{DB.db_port}/{
34
36
  engine = create_engine(DB_URL)
35
37
 
36
38
 
37
- def create_db_and_tables(model: Callable) -> None:
39
+ def create_db_and_tables(model: Callable, excluded_tables: Optional[List[str]] = None) -> None:
38
40
  """
39
41
  Create all tables based on the declared schemas in core/models thanks to sqlmodel
42
+ Does not create the tables which are passed in the optional list of excluded tables,
43
+ must be the table names
40
44
  """
41
45
  log.info(f'Inserting on the fly {model} and all other domain tables')
46
+ SQLModel.metadata.tables = {table: meta_data for table, meta_data in
47
+ SQLModel.metadata.__dict__.get('tables').items()
48
+ if not excluded_tables or table
49
+ not in excluded_tables}
42
50
  SQLModel.metadata.create_all(engine)
43
51
 
44
52
 
ecodev_core/list_utils.py CHANGED
@@ -45,6 +45,45 @@ def first_or_default(sequence: Union[List[Any], None],
45
45
  return next((elt for elt in sequence if condition(elt)), default)
46
46
 
47
47
 
48
+ def sort_by_keys(unsorted_dict: dict, reverse: bool = False) -> dict:
49
+ """
50
+ Returns a sorted dictionary out of the passed unsorted_dict.
51
+ Sorting is done on unsorted_dict keys.
52
+ If reverse is True, reverse sorting
53
+ """
54
+ return dict(sorted(unsorted_dict.items(), reverse=reverse))
55
+
56
+
57
+ def sort_by_values(unsorted_dict: dict, reverse: bool = False) -> dict:
58
+ """
59
+ Returns a sorted dictionary out of the passed unsorted_dict.
60
+ Sorting is done on unsorted_dict values.
61
+ If reverse is True, reverse sorting
62
+ """
63
+ return dict(sorted(unsorted_dict.items(), key=lambda item: item[1], reverse=reverse))
64
+
65
+
66
+ def first_func_or_default(sequence: list[Callable] | None,
67
+ elt: Any,
68
+ condition: Callable | None = None,
69
+ default: Any | None = None
70
+ ) -> Any | None:
71
+ """
72
+ Returns the first element of a functional sequence if a certain criteria is met
73
+ or default value if the criteria is never met.
74
+ The criteria is like so:
75
+ - If no condition is provided, then
76
+ just check that func applied on elt is not None
77
+ - If a condition is provided, then
78
+ check that condition applied on func(elt) is not None
79
+ """
80
+ if not sequence:
81
+ return default
82
+
83
+ return next((func(elt) for func in sequence if (condition or (lambda x: x))(func(elt))),
84
+ default)
85
+
86
+
48
87
  def group_by(sequence: List[Any], key: Union[Callable, None]) -> Iterator[Tuple[Any, List[Any]]]:
49
88
  """
50
89
  Extension of itertools groupby method.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ecodev-core
3
- Version: 0.0.29
3
+ Version: 0.0.31
4
4
  Summary: Low level sqlmodel/fastapi/pydantic building blocks
5
5
  License: MIT
6
6
  Author: Thomas Epelbaum
@@ -45,6 +45,7 @@ Requires-Dist: pydantic-settings (>=2,<3)
45
45
  Requires-Dist: python-jose[cryptography] (>=3,<4)
46
46
  Requires-Dist: sqladmin (==0.15.2)
47
47
  Requires-Dist: sqlmodel (>=0,<1)
48
+ Requires-Dist: uvicorn (==0.28.1)
48
49
  Requires-Dist: xlsxwriter (>=3,<4)
49
50
  Description-Content-Type: text/markdown
50
51
 
@@ -1,4 +1,4 @@
1
- ecodev_core/__init__.py,sha256=UfdudadIclGQH_twdS5-spE-1g7SNDAo1XFDzjE24NU,4752
1
+ ecodev_core/__init__.py,sha256=BcZLnkIVxOlVVXubWqKAAMRbUyFQt8v6JgfawC_6cPY,4970
2
2
  ecodev_core/app_activity.py,sha256=_rU5uPfttHxXX5IaCuTA7K9We5w2qluJ3Xpf6i12HhY,3763
3
3
  ecodev_core/app_rights.py,sha256=RZPdDtydFqc_nFj96huKAc56BS0qS6ScKv4Kghqd6lc,726
4
4
  ecodev_core/app_user.py,sha256=r1bqA4H08x53XmxmjwyGKl_PFjYQazzBbVErdkztqeE,2947
@@ -7,20 +7,20 @@ ecodev_core/authentication.py,sha256=aLMk2_fn1Fodrby2ywZraB3JTSsSrPsBiQq0ag0ySiY
7
7
  ecodev_core/backup.py,sha256=8fwBHic6hE8swNESIayZqqWZFHFz5f-puBWSt5f_ZLw,3119
8
8
  ecodev_core/check_dependencies.py,sha256=aFn8GI4eBbuJT8RxsfhSSnlpNYYj_LPOH-tZF0EqfKQ,6917
9
9
  ecodev_core/custom_equal.py,sha256=2gRn0qpyJ8-Kw9GQSueu0nLngLrRrwyMPlP6zqPac0U,899
10
- ecodev_core/db_connection.py,sha256=qRcs0MjLFfhO7pnSof1l1m1BbPqYfEsUlMQkKT9fn_4,1798
10
+ ecodev_core/db_connection.py,sha256=bc5MujZ57f204wTsuNVdn1JdP-zBzkDJxHmdxBDTiNs,2286
11
11
  ecodev_core/db_filters.py,sha256=T_5JVF27UEu7sC6NOm7-W3_Y0GLfbWQO_EeTXcD2cv8,5041
12
12
  ecodev_core/db_insertion.py,sha256=RSCyAlUObbBlWJuMRX-YFY4VgtWqYLdwRqMWw--x95Y,3646
13
13
  ecodev_core/db_retrieval.py,sha256=IxyF3ZtKgACLiNFggK7boKggvMRKYDRD2IimxU4dap4,7345
14
14
  ecodev_core/email_sender.py,sha256=XD7jAVXhGzvbiHqMhK9_aTEIS70Lw_CmPeAxRZGji-Y,1610
15
15
  ecodev_core/enum_utils.py,sha256=BkQ4YQ97tXBYmMcQiSIi0mbioD5CgVU79myg1BBAXuA,556
16
- ecodev_core/list_utils.py,sha256=Vyws12Jv0CLdQiQl1ym0z7E6-LJTLholYHZySQxYwhM,3006
16
+ ecodev_core/list_utils.py,sha256=s56vvhylMFzi6A76YvOIi4d5QYml73n_TmYNq1wM_P4,4427
17
17
  ecodev_core/logger.py,sha256=AWGGNZz12Ql0JDq1wCJQxwxK2syiczEBftmuJkjbAPw,3149
18
18
  ecodev_core/pandas_utils.py,sha256=Juc6gvPnoBiSVF2SR6_vfMi5W-QEkY3fnpo5ROB1L9s,2191
19
19
  ecodev_core/permissions.py,sha256=WAx-ilMu8LlQp2sjJVdkhNQieytEaEm8577ZF1HWeTY,502
20
20
  ecodev_core/pydantic_utils.py,sha256=e3GH50JmcpTmd2UgrB94QSwWOlOCW3WIlVdyX9C4T-U,741
21
21
  ecodev_core/read_write.py,sha256=auJ5bBJTVGkLRkiP_vZxVCX64B0Y-9qpsaDhovHmbas,996
22
22
  ecodev_core/safe_utils.py,sha256=JCfxo6fcznjsL-XHNJ1TKo1UvfJB83WT5jpTFmtJwsE,6160
23
- ecodev_core-0.0.29.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
24
- ecodev_core-0.0.29.dist-info/METADATA,sha256=ixhS45ZEBips9qHEXN-RRRzCzJvAkiHigPV79-NotUo,3311
25
- ecodev_core-0.0.29.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
26
- ecodev_core-0.0.29.dist-info/RECORD,,
23
+ ecodev_core-0.0.31.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
24
+ ecodev_core-0.0.31.dist-info/METADATA,sha256=V9Oak_F0Rg8ye05DUTvxu0zFv4VMABvWNAVXLpZmL38,3345
25
+ ecodev_core-0.0.31.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
26
+ ecodev_core-0.0.31.dist-info/RECORD,,