utg-base 1.6.1__tar.gz → 1.8.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 (61) hide show
  1. {utg_base-1.6.1 → utg_base-1.8.0}/PKG-INFO +3 -3
  2. {utg_base-1.6.1 → utg_base-1.8.0}/pyproject.toml +2 -2
  3. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/apps.py +1 -1
  4. utg_base-1.8.0/src/utg_base/migration/apps.py +6 -0
  5. utg_base-1.8.0/src/utg_base/migration/management/commands/__init__.py +0 -0
  6. utg_base-1.8.0/src/utg_base/migration/management/commands/makemigrations.py +91 -0
  7. utg_base-1.8.0/src/utg_base/references_api/__init__.py +0 -0
  8. utg_base-1.8.0/src/utg_base/references_api/migrations/__init__.py +0 -0
  9. utg_base-1.8.0/src/utg_base/utils/thread.py +67 -0
  10. {utg_base-1.6.1 → utg_base-1.8.0}/README.md +0 -0
  11. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/__init__.py +0 -0
  12. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/__init__.py +0 -0
  13. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/base.py +0 -0
  14. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/pagination.py +0 -0
  15. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/permissions.py +0 -0
  16. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/routers.py +0 -0
  17. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/serializers.py +0 -0
  18. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/spectacular.py +0 -0
  19. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/api/views.py +0 -0
  20. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/authentications/__init__.py +0 -0
  21. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/authentications/microservice_authentication.py +0 -0
  22. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/authentications/models.py +0 -0
  23. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/__init__.py +0 -0
  24. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/filters/__init__.py +0 -0
  25. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/filters/task_result.py +0 -0
  26. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/management/__init__.py +0 -0
  27. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/management/commands/__init__.py +0 -0
  28. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/management/commands/migrate_tasks.py +0 -0
  29. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/serializers/__init__.py +0 -0
  30. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/serializers/periodic_task.py +0 -0
  31. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/serializers/task_result.py +0 -0
  32. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/urls.py +0 -0
  33. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/views/__init__.py +0 -0
  34. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/views/periodic_task.py +0 -0
  35. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/celery/views/task_result.py +0 -0
  36. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/constants/__init__.py +0 -0
  37. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/constants/available_languages.py +0 -0
  38. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/env.py +0 -0
  39. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/logging.py +0 -0
  40. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/middleware/__init__.py +0 -0
  41. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/middleware/debug.py +0 -0
  42. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/middleware/locale.py +0 -0
  43. {utg_base-1.6.1/src/utg_base/references_api → utg_base-1.8.0/src/utg_base/migration}/__init__.py +0 -0
  44. {utg_base-1.6.1/src/utg_base/references_api/migrations → utg_base-1.8.0/src/utg_base/migration/management}/__init__.py +0 -0
  45. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/models/__init__.py +0 -0
  46. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/models/jwt_user.py +0 -0
  47. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/models/timestamp.py +0 -0
  48. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/references_api/admin.py +0 -0
  49. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/references_api/apps.py +0 -0
  50. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/references_api/models.py +0 -0
  51. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/references_api/urls.py +0 -0
  52. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/references_api/utils.py +0 -0
  53. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/services/__init__.py +0 -0
  54. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/services/base_api.py +0 -0
  55. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/utils/__init__.py +0 -0
  56. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/utils/data.py +0 -0
  57. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/utils/date.py +0 -0
  58. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/utils/dict_util.py +0 -0
  59. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/utils/response_processors.py +0 -0
  60. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/utils/sql.py +0 -0
  61. {utg_base-1.6.1 → utg_base-1.8.0}/src/utg_base/utils/translation.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: utg-base
3
- Version: 1.6.1
3
+ Version: 1.8.0
4
4
  Summary: UTG Base Package
5
- Author: Rovshen
6
- Author-email: rovshenashirov1619@gmail.com
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)
@@ -1,8 +1,8 @@
1
1
  [tool.poetry]
2
2
  name = "utg-base"
3
- version = "1.6.1"
3
+ version = "1.8.0"
4
4
  description = "UTG Base Package"
5
- authors = ["Rovshen <rovshenashirov1619@gmail.com>"]
5
+ authors = ["Olimboy <shavkatov.olimboy@mail.ru>", "Rovshen <rovshenashirov1619@gmail.com>"]
6
6
  readme = "README.md"
7
7
 
8
8
  [tool.poetry.dependencies]
@@ -1,6 +1,6 @@
1
1
  from django.apps import AppConfig
2
2
 
3
3
 
4
- class QApiConfig(AppConfig):
4
+ class CeleryApiConfig(AppConfig):
5
5
  default_auto_field = "django.db.models.BigAutoField"
6
6
  name = "utg_base.celery"
@@ -0,0 +1,6 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class MigrationApiConfig(AppConfig):
5
+ default_auto_field = "django.db.models.BigAutoField"
6
+ name = "utg_base.migration"
@@ -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
File without changes
@@ -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
File without changes
File without changes