utg-base 1.6.1__py3-none-any.whl → 1.8.0__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.
- utg_base/celery/apps.py +1 -1
- utg_base/migration/__init__.py +0 -0
- utg_base/migration/apps.py +6 -0
- utg_base/migration/management/__init__.py +0 -0
- utg_base/migration/management/commands/__init__.py +0 -0
- utg_base/migration/management/commands/makemigrations.py +91 -0
- utg_base/utils/thread.py +67 -0
- {utg_base-1.6.1.dist-info → utg_base-1.8.0.dist-info}/METADATA +3 -3
- {utg_base-1.6.1.dist-info → utg_base-1.8.0.dist-info}/RECORD +10 -4
- {utg_base-1.6.1.dist-info → utg_base-1.8.0.dist-info}/WHEEL +0 -0
utg_base/celery/apps.py
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from django.core.management.commands.makemigrations import Command as BaseMakeMigrations
|
|
4
|
+
from django.core.management.utils import run_formatters
|
|
5
|
+
from django.db.migrations.writer import MigrationWriter
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Command(BaseMakeMigrations):
|
|
9
|
+
|
|
10
|
+
def write_migration_files(self, changes, update_previous_migration_paths=None):
|
|
11
|
+
"""
|
|
12
|
+
Take a changes dict and write them out as migration files.
|
|
13
|
+
"""
|
|
14
|
+
directory_created = {}
|
|
15
|
+
for app_label, app_migrations in changes.items():
|
|
16
|
+
if self.verbosity >= 1:
|
|
17
|
+
self.log(self.style.MIGRATE_HEADING("Migrations for '%s':" % app_label))
|
|
18
|
+
for migration in app_migrations:
|
|
19
|
+
# Describe the migration
|
|
20
|
+
writer = MigrationWriter(migration, self.include_header)
|
|
21
|
+
|
|
22
|
+
# BEGIN Customizing
|
|
23
|
+
# fix 'created_at', 'updated_at' fields order
|
|
24
|
+
for operation in migration.operations:
|
|
25
|
+
_fields = []
|
|
26
|
+
_end_fields = []
|
|
27
|
+
for field_name, field in operation.fields:
|
|
28
|
+
if field_name in ['created_at', 'updated_at']:
|
|
29
|
+
_end_fields.append((field_name, field))
|
|
30
|
+
else:
|
|
31
|
+
_fields.append((field_name, field))
|
|
32
|
+
|
|
33
|
+
operation.fields = _fields + _end_fields
|
|
34
|
+
|
|
35
|
+
# END Customizing
|
|
36
|
+
|
|
37
|
+
if self.verbosity >= 1:
|
|
38
|
+
# Display a relative path if it's below the current working
|
|
39
|
+
# directory, or an absolute path otherwise.
|
|
40
|
+
migration_string = self.get_relative_path(writer.path)
|
|
41
|
+
self.log(" %s\n" % self.style.MIGRATE_LABEL(migration_string))
|
|
42
|
+
for operation in migration.operations:
|
|
43
|
+
self.log(" %s" % operation.formatted_description())
|
|
44
|
+
if self.scriptable:
|
|
45
|
+
self.stdout.write(migration_string)
|
|
46
|
+
if not self.dry_run:
|
|
47
|
+
# Write the migrations file to the disk.
|
|
48
|
+
migrations_directory = os.path.dirname(writer.path)
|
|
49
|
+
if not directory_created.get(app_label):
|
|
50
|
+
os.makedirs(migrations_directory, exist_ok=True)
|
|
51
|
+
init_path = os.path.join(migrations_directory, "__init__.py")
|
|
52
|
+
if not os.path.isfile(init_path):
|
|
53
|
+
open(init_path, "w").close()
|
|
54
|
+
# We just do this once per app
|
|
55
|
+
directory_created[app_label] = True
|
|
56
|
+
migration_string = writer.as_string()
|
|
57
|
+
with open(writer.path, "w", encoding="utf-8") as fh:
|
|
58
|
+
fh.write(migration_string)
|
|
59
|
+
self.written_files.append(writer.path)
|
|
60
|
+
if update_previous_migration_paths:
|
|
61
|
+
prev_path = update_previous_migration_paths[app_label]
|
|
62
|
+
rel_prev_path = self.get_relative_path(prev_path)
|
|
63
|
+
if writer.needs_manual_porting:
|
|
64
|
+
migration_path = self.get_relative_path(writer.path)
|
|
65
|
+
self.log(
|
|
66
|
+
self.style.WARNING(
|
|
67
|
+
f"Updated migration {migration_path} requires "
|
|
68
|
+
f"manual porting.\n"
|
|
69
|
+
f"Previous migration {rel_prev_path} was kept and "
|
|
70
|
+
f"must be deleted after porting functions manually."
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
else:
|
|
74
|
+
os.remove(prev_path)
|
|
75
|
+
self.log(f"Deleted {rel_prev_path}")
|
|
76
|
+
elif self.verbosity == 3:
|
|
77
|
+
# Alternatively, makemigrations --dry-run --verbosity 3
|
|
78
|
+
# will log the migrations rather than saving the file to
|
|
79
|
+
# the disk.
|
|
80
|
+
self.log(
|
|
81
|
+
self.style.MIGRATE_HEADING(
|
|
82
|
+
"Full migrations file '%s':" % writer.filename
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
self.log(writer.as_string())
|
|
86
|
+
run_formatters(self.written_files, stderr=self.stderr)
|
|
87
|
+
|
|
88
|
+
def handle(self, *args, **options):
|
|
89
|
+
self.written_files = []
|
|
90
|
+
result = super().handle(*args, **options)
|
|
91
|
+
return result
|
utg_base/utils/thread.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import multiprocessing
|
|
2
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
3
|
+
from typing import Callable, Any, Iterable, Tuple, Dict, Union
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ThreadPoolException(Exception):
|
|
7
|
+
"""Exception to wrap the error in each task."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, func: str, exception: Exception):
|
|
10
|
+
self.func = func
|
|
11
|
+
self.exception = exception
|
|
12
|
+
super().__init__(f"Exception in {func}: {exception}")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def parallel_execute(
|
|
16
|
+
*tasks: Union[
|
|
17
|
+
Callable, # func
|
|
18
|
+
Tuple[Callable, Iterable], # (func, args)
|
|
19
|
+
Tuple[Callable, Iterable, Dict[str, Any]] # (func, args, kwargs)
|
|
20
|
+
],
|
|
21
|
+
max_workers: int = None
|
|
22
|
+
) -> list[Any]:
|
|
23
|
+
"""
|
|
24
|
+
Executes multiple functions in parallel.
|
|
25
|
+
Each can be without arguments or with args/kwargs.
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
parallel_execute(func1, func2)
|
|
29
|
+
parallel_execute((func1, (1, 2)), (func2, (), {"x": 5}))
|
|
30
|
+
|
|
31
|
+
The sequence is preserved.
|
|
32
|
+
|
|
33
|
+
:return: Result list or ThreadPoolException objects
|
|
34
|
+
"""
|
|
35
|
+
if not tasks:
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
cpu_count = multiprocessing.cpu_count()
|
|
39
|
+
max_workers = max_workers or min(cpu_count * 10, len(tasks))
|
|
40
|
+
results = [None] * len(tasks)
|
|
41
|
+
|
|
42
|
+
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
43
|
+
futures = {}
|
|
44
|
+
|
|
45
|
+
for i, task in enumerate(tasks):
|
|
46
|
+
# Task unpacking
|
|
47
|
+
if callable(task):
|
|
48
|
+
func, args, kwargs = task, (), {}
|
|
49
|
+
elif isinstance(task, tuple):
|
|
50
|
+
func = task[0]
|
|
51
|
+
args = task[1] if len(task) > 1 else ()
|
|
52
|
+
kwargs = task[2] if len(task) > 2 else {}
|
|
53
|
+
else:
|
|
54
|
+
raise ValueError(f"Invalid task format: {task}")
|
|
55
|
+
|
|
56
|
+
futures[executor.submit(func, *args, **kwargs)] = i
|
|
57
|
+
|
|
58
|
+
for future in as_completed(futures):
|
|
59
|
+
idx = futures[future]
|
|
60
|
+
func = tasks[idx][0] if isinstance(tasks[idx], tuple) else tasks[idx]
|
|
61
|
+
func_name = getattr(func, "__name__", str(func))
|
|
62
|
+
try:
|
|
63
|
+
results[idx] = future.result()
|
|
64
|
+
except Exception as e:
|
|
65
|
+
results[idx] = ThreadPoolException(func=func_name, exception=e)
|
|
66
|
+
|
|
67
|
+
return results
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: utg-base
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0
|
|
4
4
|
Summary: UTG Base Package
|
|
5
|
-
Author:
|
|
6
|
-
Author-email:
|
|
5
|
+
Author: Olimboy
|
|
6
|
+
Author-email: shavkatov.olimboy@mail.ru
|
|
7
7
|
Requires-Python: >=3.14,<4.0
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Requires-Dist: celery (>=5.5.3,<6.0.0)
|
|
@@ -11,7 +11,7 @@ utg_base/authentications/__init__.py,sha256=a6twO_bBf8FAHYl7PXawfR2UbBwwdueG1uS_
|
|
|
11
11
|
utg_base/authentications/microservice_authentication.py,sha256=6aAncxIpA4FcyRegd7QqRYvW5Wn8FxyPU0nQqCVuEs4,976
|
|
12
12
|
utg_base/authentications/models.py,sha256=JQonSdXeSeoF003QlmPvH58nWmVJRKlWWjW_ySqXaYg,2496
|
|
13
13
|
utg_base/celery/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
utg_base/celery/apps.py,sha256=
|
|
14
|
+
utg_base/celery/apps.py,sha256=slwNufuKTuNGT3o9oV7MicERn5nh3FuL5OJirBC83Ys,156
|
|
15
15
|
utg_base/celery/filters/__init__.py,sha256=wnkV8cPEvvHIl8OoMTv7fvSglDSFY8XxpCjUveRNUyg,45
|
|
16
16
|
utg_base/celery/filters/task_result.py,sha256=iXgOrXrO8bvF9S47D53UzsdWQr_JrJ-LtxdjPfcTVjA,138
|
|
17
17
|
utg_base/celery/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -31,6 +31,11 @@ utg_base/logging.py,sha256=JHGhuLKU1js_26ReE0LCLWZ66fmlGKuLG9sfbQSfI5w,4565
|
|
|
31
31
|
utg_base/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
32
|
utg_base/middleware/debug.py,sha256=exkeYUK-zSN3PMd4L9F6WlROmQ7Qlpmi_Gr2dqt5vk4,416
|
|
33
33
|
utg_base/middleware/locale.py,sha256=1hp_T_VuHCz0ITjwJ_F1rpf5kXQ0ulEmK1yoRWD1GRc,557
|
|
34
|
+
utg_base/migration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
|
+
utg_base/migration/apps.py,sha256=sATh5UNLRJeyFGiWTjU5L8qRSVM2NVG9GK196w6dd0A,162
|
|
36
|
+
utg_base/migration/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
37
|
+
utg_base/migration/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
38
|
+
utg_base/migration/management/commands/makemigrations.py,sha256=cV-YOjJry3MFP5WR5YYq8Ji1mW_wM0umBNjIb8Ts1zE,4513
|
|
34
39
|
utg_base/models/__init__.py,sha256=1zXygGICiR3iUCKdkNal9d3i3kNp654gFgBf_VlR2gI,67
|
|
35
40
|
utg_base/models/jwt_user.py,sha256=6TQ5wB_OZBtGhRL-2MonBGZm0n0Y86s4BRTxiRlUJOk,375
|
|
36
41
|
utg_base/models/timestamp.py,sha256=AkCliNXnvs8Z17b1mcS7gOK7v6h3Jul6WCyGyVAkb-w,217
|
|
@@ -49,7 +54,8 @@ utg_base/utils/date.py,sha256=thcbK6RgTUYZfs4_vW5ucuu2e8H0rei6tv7SEC72iwM,3612
|
|
|
49
54
|
utg_base/utils/dict_util.py,sha256=ipdCZO8aTukGQ319OWHb2Ij5MNtV-FioJQ4qCX3Th48,758
|
|
50
55
|
utg_base/utils/response_processors.py,sha256=WdZQL49wOJqCIY2MucAI6sez_llCqih0v_ltQa-mv7k,687
|
|
51
56
|
utg_base/utils/sql.py,sha256=rqIWcSjdjIMszdRnsnhV5TTYB8W17RPOujIQA9rKC_Y,762
|
|
57
|
+
utg_base/utils/thread.py,sha256=4RqRnwtyHymY-dNcuPrMSTamE2V7wCMVfzzyIb0P4TI,2191
|
|
52
58
|
utg_base/utils/translation.py,sha256=GxJHUt0iar_0E7RWBPbeLFQ4DhgXBjffHCmxfKyjFtk,463
|
|
53
|
-
utg_base-1.
|
|
54
|
-
utg_base-1.
|
|
55
|
-
utg_base-1.
|
|
59
|
+
utg_base-1.8.0.dist-info/METADATA,sha256=e7ukwTXgHmcSQ1ZIu9K6I3xJjSnCcMSuAkNtntBpPTY,871
|
|
60
|
+
utg_base-1.8.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
61
|
+
utg_base-1.8.0.dist-info/RECORD,,
|
|
File without changes
|