flagsmith-common 2.2.2__tar.gz → 2.2.4__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 (91) hide show
  1. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/PKG-INFO +1 -1
  2. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/pyproject.toml +1 -1
  3. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/main.py +8 -4
  4. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/utils.py +56 -5
  5. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/LICENSE +0 -0
  6. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/README.md +0 -0
  7. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/__init__.py +0 -0
  8. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/__init__.py +0 -0
  9. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/app.py +0 -0
  10. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/cli/__init__.py +0 -0
  11. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/cli/healthcheck.py +0 -0
  12. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/logging.py +0 -0
  13. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/management/__init__.py +0 -0
  14. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/management/commands/__init__.py +0 -0
  15. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/management/commands/docgen.py +0 -0
  16. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/management/commands/start.py +0 -0
  17. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/management/commands/waitfordb.py +0 -0
  18. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/metrics.py +0 -0
  19. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/middleware.py +0 -0
  20. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/templates/docgen-metrics.md +0 -0
  21. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/urls.py +0 -0
  22. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/core/views.py +0 -0
  23. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/environments/permissions.py +0 -0
  24. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/features/__init__.py +0 -0
  25. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/features/multivariate/__init__.py +0 -0
  26. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/features/multivariate/serializers.py +0 -0
  27. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/features/serializers.py +0 -0
  28. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/features/versioning/__init__.py +0 -0
  29. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/features/versioning/serializers.py +0 -0
  30. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/gunicorn/__init__.py +0 -0
  31. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/gunicorn/conf.py +0 -0
  32. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/gunicorn/constants.py +0 -0
  33. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/gunicorn/logging.py +0 -0
  34. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/gunicorn/metrics.py +0 -0
  35. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/gunicorn/middleware.py +0 -0
  36. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/gunicorn/utils.py +0 -0
  37. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/migrations/__init__.py +0 -0
  38. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/migrations/helpers/__init__.py +0 -0
  39. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/migrations/helpers/postgres_helpers.py +0 -0
  40. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/organisations/permissions.py +0 -0
  41. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/projects/permissions.py +0 -0
  42. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/prometheus/__init__.py +0 -0
  43. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/prometheus/utils.py +0 -0
  44. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/py.typed +0 -0
  45. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/test_tools/__init__.py +0 -0
  46. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/test_tools/plugin.py +0 -0
  47. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/test_tools/types.py +0 -0
  48. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/test_tools/utils.py +0 -0
  49. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/common/types.py +0 -0
  50. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/__init__.py +0 -0
  51. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/admin.py +0 -0
  52. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/apps.py +0 -0
  53. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/decorators.py +0 -0
  54. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/exceptions.py +0 -0
  55. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/health.py +0 -0
  56. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/managers.py +0 -0
  57. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/metrics.py +0 -0
  58. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0001_initial.py +0 -0
  59. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0002_healthcheckmodel.py +0 -0
  60. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0003_add_completed_to_task.py +0 -0
  61. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0004_recreate_task_indexes.py +0 -0
  62. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0005_update_conditional_index_conditions.py +0 -0
  63. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0006_auto_20230221_0802.py +0 -0
  64. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0007_add_is_locked.py +0 -0
  65. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0008_add_get_task_to_process_function.py +0 -0
  66. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0009_add_recurring_task_run_first_run_at.py +0 -0
  67. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0010_task_priority.py +0 -0
  68. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0011_add_priority_to_get_tasks_to_process.py +0 -0
  69. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0012_add_locked_at_and_timeout.py +0 -0
  70. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/0013_add_last_picked_at.py +0 -0
  71. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/__init__.py +0 -0
  72. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/sql/0008_get_recurring_tasks_to_process.sql +0 -0
  73. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/sql/0008_get_tasks_to_process.sql +0 -0
  74. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/sql/0011_get_tasks_to_process.sql +0 -0
  75. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/sql/0012_get_recurringtasks_to_process.sql +0 -0
  76. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/sql/0013_get_recurringtasks_to_process.sql +0 -0
  77. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/migrations/sql/__init__.py +0 -0
  78. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/models.py +0 -0
  79. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/monitoring.py +0 -0
  80. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/processor.py +0 -0
  81. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/py.typed +0 -0
  82. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/routers.py +0 -0
  83. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/serializers.py +0 -0
  84. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/task_registry.py +0 -0
  85. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/task_run_method.py +0 -0
  86. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/tasks.py +0 -0
  87. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/threads.py +0 -0
  88. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/types.py +0 -0
  89. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/urls.py +0 -0
  90. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/utils.py +0 -0
  91. {flagsmith_common-2.2.2 → flagsmith_common-2.2.4}/src/task_processor/views.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flagsmith-common
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
4
  Summary: Flagsmith's common library
5
5
  License-Expression: BSD-3-Clause
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flagsmith-common"
3
- version = "2.2.2"
3
+ version = "2.2.4"
4
4
  description = "Flagsmith's common library"
5
5
  requires-python = ">=3.11,<4.0"
6
6
  dependencies = [
@@ -2,14 +2,15 @@ import contextlib
2
2
  import logging
3
3
  import os
4
4
  import sys
5
- import tempfile
6
5
  import typing
7
6
 
8
7
  from django.core.management import (
9
8
  execute_from_command_line as django_execute_from_command_line,
10
9
  )
10
+ from environs import Env
11
11
 
12
12
  from common.core.cli import healthcheck
13
+ from common.core.utils import TemporaryDirectory
13
14
 
14
15
  logger = logging.getLogger(__name__)
15
16
 
@@ -30,6 +31,7 @@ def ensure_cli_env() -> typing.Generator[None, None, None]:
30
31
  main()
31
32
  ```
32
33
  """
34
+ env = Env()
33
35
  ctx = contextlib.ExitStack()
34
36
 
35
37
  # TODO @khvn26 Move logging setup to here
@@ -43,9 +45,11 @@ def ensure_cli_env() -> typing.Generator[None, None, None]:
43
45
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.dev")
44
46
 
45
47
  # Set up Prometheus' multiprocess mode
46
- if "PROMETHEUS_MULTIPROC_DIR" not in os.environ:
47
- prometheus_multiproc_dir_name = tempfile.mkdtemp()
48
-
48
+ if not env.str("PROMETHEUS_MULTIPROC_DIR", ""):
49
+ delete = not env.bool("PROMETHEUS_MULTIPROC_DIR_KEEP", False)
50
+ prometheus_multiproc_dir_name = ctx.enter_context(
51
+ TemporaryDirectory(delete=delete)
52
+ )
49
53
  logger.info(
50
54
  "Created %s for Prometheus multi-process mode",
51
55
  prometheus_multiproc_dir_name,
@@ -2,25 +2,39 @@ import json
2
2
  import logging
3
3
  import pathlib
4
4
  import random
5
+ import sys
6
+ import tempfile
5
7
  from functools import lru_cache
6
8
  from itertools import cycle
7
- from typing import Iterator, Literal, NotRequired, TypedDict, TypeVar, get_args
9
+ from typing import (
10
+ TYPE_CHECKING,
11
+ Iterator,
12
+ Literal,
13
+ NotRequired,
14
+ TypedDict,
15
+ TypeVar,
16
+ get_args,
17
+ )
8
18
 
9
19
  from django.conf import settings
10
20
  from django.contrib.auth import get_user_model
11
- from django.contrib.auth.models import AbstractBaseUser
12
21
  from django.db import connections
13
- from django.db.models import Manager, Model
14
22
  from django.db.utils import OperationalError
15
23
 
16
24
  from common.core import ReplicaReadStrategy
17
25
 
26
+ if TYPE_CHECKING:
27
+ from django.contrib.auth.models import AbstractBaseUser
28
+ from django.db.models.base import Model
29
+ from django.db.models.manager import Manager
30
+
31
+
18
32
  logger = logging.getLogger(__name__)
19
33
 
20
34
  UNKNOWN = "unknown"
21
35
  VERSIONS_INFO_FILE_LOCATION = ".versions.json"
22
36
 
23
- ManagerType = TypeVar("ManagerType", bound=Manager[Model])
37
+ ManagerType = TypeVar("ManagerType", bound="Manager[Model]")
24
38
 
25
39
  ReplicaNamePrefix = Literal["replica_", "cross_region_replica_"]
26
40
  _replica_sequential_names_by_prefix: dict[ReplicaNamePrefix, Iterator[str]] = {}
@@ -93,7 +107,7 @@ def get_version_info() -> VersionInfo:
93
107
  version_json["image_tag"] = manifest_versions["."]
94
108
 
95
109
  if not _is_saas:
96
- user_objects: Manager[AbstractBaseUser] = getattr(get_user_model(), "objects")
110
+ user_objects: "Manager[AbstractBaseUser]" = getattr(get_user_model(), "objects")
97
111
 
98
112
  version_json["self_hosted_data"] = {
99
113
  "has_users": user_objects.exists(),
@@ -186,3 +200,40 @@ def using_database_replica(
186
200
  return manager
187
201
 
188
202
  return manager.db_manager(chosen_replica)
203
+
204
+
205
+ if sys.version_info >= (3, 12):
206
+ # Already has the desired behavior; re-export for uniform imports.
207
+ TemporaryDirectory = tempfile.TemporaryDirectory
208
+ else:
209
+ import contextlib
210
+ from typing import ContextManager, Generator
211
+
212
+ def TemporaryDirectory(
213
+ suffix: str | None = None,
214
+ prefix: str | None = None,
215
+ dir: str | None = None,
216
+ *,
217
+ delete: bool = True,
218
+ ) -> ContextManager[str]:
219
+ """
220
+ Create a temporary directory with optional cleanup control.
221
+
222
+ This wrapper exists because Python 3.12 changed TemporaryDirectory's behavior
223
+ by adding a 'delete' parameter, which doesn't exist in Python 3.11. This
224
+ function provides a consistent API across both versions.
225
+
226
+ When delete=True, uses the stdlib's TemporaryDirectory (auto-cleanup).
227
+ When delete=False, creates a directory with mkdtemp that persists after
228
+ the context manager exits, matching Python 3.12's delete=False behavior.
229
+
230
+ See https://docs.python.org/3.12/library/tempfile.html#tempfile.TemporaryDirectory for usage details.
231
+ """
232
+ if delete:
233
+ return tempfile.TemporaryDirectory(suffix, prefix, dir)
234
+
235
+ @contextlib.contextmanager
236
+ def _tmpdir() -> Generator[str, None, None]:
237
+ yield tempfile.mkdtemp(suffix, prefix, dir)
238
+
239
+ return _tmpdir()