ecodev-core 0.0.29__tar.gz → 0.0.31__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.
Potentially problematic release.
This version of ecodev-core might be problematic. Click here for more details.
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/PKG-INFO +2 -1
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/__init__.py +5 -1
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/db_connection.py +9 -1
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/list_utils.py +39 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/pyproject.toml +2 -1
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/LICENSE.md +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/README.md +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/app_activity.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/app_rights.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/app_user.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/auth_configuration.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/authentication.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/backup.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/check_dependencies.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/custom_equal.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/db_filters.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/db_insertion.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/db_retrieval.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/email_sender.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/enum_utils.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/logger.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/pandas_utils.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/permissions.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/pydantic_utils.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/read_write.py +0 -0
- {ecodev_core-0.0.29 → ecodev_core-0.0.31}/ecodev_core/safe_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ecodev-core
|
|
3
|
-
Version: 0.0.
|
|
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
|
|
|
@@ -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
|
|
|
@@ -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
|
[tool.poetry]
|
|
2
2
|
name = "ecodev-core"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.31"
|
|
4
4
|
description = "Low level sqlmodel/fastapi/pydantic building blocks"
|
|
5
5
|
authors = ["Thomas Epelbaum <tomepel@gmail.com>",
|
|
6
6
|
"Olivier Gabriel <olivier.gabriel.geom@gmail.com>",
|
|
@@ -55,6 +55,7 @@ pydantic-settings = "~2"
|
|
|
55
55
|
psycopg2-binary = "~2"
|
|
56
56
|
openpyxl = "~3"
|
|
57
57
|
xlsxwriter = "~3"
|
|
58
|
+
uvicorn = "0.28.1"
|
|
58
59
|
|
|
59
60
|
|
|
60
61
|
[build-system]
|
|
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
|