amsdal 0.4.13__cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.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.
- amsdal/Third-Party Materials - AMSDAL Dependencies - License Notices.md +1334 -0
- amsdal/__about__.py +4 -0
- amsdal/__about__.pyi +1 -0
- amsdal/__init__.py +23 -0
- amsdal/__init__.pyi +9 -0
- amsdal/__migrations__/0000_initial.py +217 -0
- amsdal/__migrations__/0001_datetime_type.py +18 -0
- amsdal/__migrations__/0002_fixture_order.py +44 -0
- amsdal/__migrations__/0003_schema_type_in_class_meta.py +44 -0
- amsdal/cloud/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/__init__.pyi +0 -0
- amsdal/cloud/client.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/client.pyi +57 -0
- amsdal/cloud/constants.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/constants.pyi +13 -0
- amsdal/cloud/enums.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/enums.pyi +68 -0
- amsdal/cloud/models/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/models/__init__.pyi +0 -0
- amsdal/cloud/models/base.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/models/base.pyi +247 -0
- amsdal/cloud/services/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/__init__.pyi +0 -0
- amsdal/cloud/services/actions/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/__init__.pyi +0 -0
- amsdal/cloud/services/actions/add_allowlist_ip.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/add_allowlist_ip.pyi +19 -0
- amsdal/cloud/services/actions/add_basic_auth.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/add_basic_auth.pyi +21 -0
- amsdal/cloud/services/actions/add_dependency.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/add_dependency.pyi +19 -0
- amsdal/cloud/services/actions/add_secret.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/add_secret.pyi +20 -0
- amsdal/cloud/services/actions/base.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/base.pyi +122 -0
- amsdal/cloud/services/actions/create_deploy.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/create_deploy.pyi +41 -0
- amsdal/cloud/services/actions/create_env.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/create_env.pyi +19 -0
- amsdal/cloud/services/actions/create_session.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/create_session.pyi +17 -0
- amsdal/cloud/services/actions/delete_allowlist_ip.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/delete_allowlist_ip.pyi +19 -0
- amsdal/cloud/services/actions/delete_basic_auth.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/delete_basic_auth.pyi +20 -0
- amsdal/cloud/services/actions/delete_dependency.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/delete_dependency.pyi +21 -0
- amsdal/cloud/services/actions/delete_env.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/delete_env.pyi +21 -0
- amsdal/cloud/services/actions/delete_secret.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/delete_secret.pyi +21 -0
- amsdal/cloud/services/actions/destroy_deploy.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/destroy_deploy.pyi +18 -0
- amsdal/cloud/services/actions/expose_db.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/expose_db.pyi +22 -0
- amsdal/cloud/services/actions/get_basic_auth_credentials.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/get_basic_auth_credentials.pyi +21 -0
- amsdal/cloud/services/actions/get_monitoring_info.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/get_monitoring_info.pyi +21 -0
- amsdal/cloud/services/actions/list_dependencies.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/list_dependencies.pyi +21 -0
- amsdal/cloud/services/actions/list_deploys.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/list_deploys.pyi +19 -0
- amsdal/cloud/services/actions/list_envs.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/list_envs.pyi +20 -0
- amsdal/cloud/services/actions/list_secrets.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/list_secrets.pyi +22 -0
- amsdal/cloud/services/actions/manager.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/manager.pyi +278 -0
- amsdal/cloud/services/actions/signup_action.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/signup_action.pyi +20 -0
- amsdal/cloud/services/actions/update_deploy.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/actions/update_deploy.pyi +19 -0
- amsdal/cloud/services/auth/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/auth/__init__.pyi +0 -0
- amsdal/cloud/services/auth/base.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/auth/base.pyi +6 -0
- amsdal/cloud/services/auth/credentials.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/auth/credentials.pyi +30 -0
- amsdal/cloud/services/auth/manager.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/auth/manager.pyi +26 -0
- amsdal/cloud/services/auth/signup_service.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/auth/signup_service.pyi +32 -0
- amsdal/cloud/services/auth/token.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/cloud/services/auth/token.pyi +27 -0
- amsdal/configs/__init__.py +0 -0
- amsdal/configs/__init__.pyi +0 -0
- amsdal/configs/constants.py +33 -0
- amsdal/configs/constants.pyi +22 -0
- amsdal/configs/main.py +258 -0
- amsdal/configs/main.pyi +173 -0
- amsdal/context/__init__.py +0 -0
- amsdal/context/__init__.pyi +0 -0
- amsdal/context/manager.py +69 -0
- amsdal/context/manager.pyi +50 -0
- amsdal/contrib/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/contrib/__init__.pyi +0 -0
- amsdal/contrib/app_config.py +7 -0
- amsdal/contrib/app_config.pyi +6 -0
- amsdal/contrib/auth/__init__.py +0 -0
- amsdal/contrib/auth/__init__.pyi +0 -0
- amsdal/contrib/auth/app.py +27 -0
- amsdal/contrib/auth/app.pyi +15 -0
- amsdal/contrib/auth/decorators/__init__.py +35 -0
- amsdal/contrib/auth/decorators/__init__.pyi +6 -0
- amsdal/contrib/auth/errors.py +7 -0
- amsdal/contrib/auth/errors.pyi +4 -0
- amsdal/contrib/auth/fixtures/basic_permissions.json +64 -0
- amsdal/contrib/auth/lifecycle/__init__.py +0 -0
- amsdal/contrib/auth/lifecycle/__init__.pyi +0 -0
- amsdal/contrib/auth/lifecycle/consumer.py +394 -0
- amsdal/contrib/auth/lifecycle/consumer.pyi +108 -0
- amsdal/contrib/auth/migrations/0000_initial.py +84 -0
- amsdal/contrib/auth/models/__init__.py +0 -0
- amsdal/contrib/auth/models/__init__.pyi +0 -0
- amsdal/contrib/auth/models/login_session.py +118 -0
- amsdal/contrib/auth/models/login_session.pyi +37 -0
- amsdal/contrib/auth/models/permission.py +23 -0
- amsdal/contrib/auth/models/permission.pyi +18 -0
- amsdal/contrib/auth/models/user.py +106 -0
- amsdal/contrib/auth/models/user.pyi +46 -0
- amsdal/contrib/auth/settings.py +36 -0
- amsdal/contrib/auth/settings.pyi +26 -0
- amsdal/contrib/frontend_configs/__init__.py +0 -0
- amsdal/contrib/frontend_configs/__init__.pyi +0 -0
- amsdal/contrib/frontend_configs/app.py +24 -0
- amsdal/contrib/frontend_configs/app.pyi +19 -0
- amsdal/contrib/frontend_configs/constants.py +1 -0
- amsdal/contrib/frontend_configs/constants.pyi +1 -0
- amsdal/contrib/frontend_configs/conversion/__init__.py +5 -0
- amsdal/contrib/frontend_configs/conversion/__init__.pyi +3 -0
- amsdal/contrib/frontend_configs/conversion/convert.py +286 -0
- amsdal/contrib/frontend_configs/conversion/convert.pyi +22 -0
- amsdal/contrib/frontend_configs/lifecycle/__init__.py +0 -0
- amsdal/contrib/frontend_configs/lifecycle/__init__.pyi +0 -0
- amsdal/contrib/frontend_configs/lifecycle/consumer.py +306 -0
- amsdal/contrib/frontend_configs/lifecycle/consumer.pyi +98 -0
- amsdal/contrib/frontend_configs/migrations/0000_initial.py +256 -0
- amsdal/contrib/frontend_configs/models/__init__.py +0 -0
- amsdal/contrib/frontend_configs/models/__init__.pyi +0 -0
- amsdal/contrib/frontend_configs/models/frontend_activator_config.py +22 -0
- amsdal/contrib/frontend_configs/models/frontend_activator_config.pyi +12 -0
- amsdal/contrib/frontend_configs/models/frontend_config_async_validator.py +11 -0
- amsdal/contrib/frontend_configs/models/frontend_config_async_validator.pyi +7 -0
- amsdal/contrib/frontend_configs/models/frontend_config_control_action.py +54 -0
- amsdal/contrib/frontend_configs/models/frontend_config_control_action.pyi +32 -0
- amsdal/contrib/frontend_configs/models/frontend_config_group_validator.py +21 -0
- amsdal/contrib/frontend_configs/models/frontend_config_group_validator.pyi +11 -0
- amsdal/contrib/frontend_configs/models/frontend_config_option.py +12 -0
- amsdal/contrib/frontend_configs/models/frontend_config_option.pyi +8 -0
- amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base.py +17 -0
- amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base.pyi +8 -0
- amsdal/contrib/frontend_configs/models/frontend_config_slider_option.py +13 -0
- amsdal/contrib/frontend_configs/models/frontend_config_slider_option.pyi +9 -0
- amsdal/contrib/frontend_configs/models/frontend_config_text_mask.py +14 -0
- amsdal/contrib/frontend_configs/models/frontend_config_text_mask.pyi +10 -0
- amsdal/contrib/frontend_configs/models/frontend_config_validator.py +28 -0
- amsdal/contrib/frontend_configs/models/frontend_config_validator.pyi +15 -0
- amsdal/contrib/frontend_configs/models/frontend_control_config.py +87 -0
- amsdal/contrib/frontend_configs/models/frontend_control_config.pyi +35 -0
- amsdal/contrib/frontend_configs/models/frontend_model_config.py +14 -0
- amsdal/contrib/frontend_configs/models/frontend_model_config.pyi +9 -0
- amsdal/contrib/frontend_configs/utils.py +29 -0
- amsdal/contrib/frontend_configs/utils.pyi +17 -0
- amsdal/errors.py +31 -0
- amsdal/errors.pyi +12 -0
- amsdal/fixtures/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/fixtures/__init__.pyi +0 -0
- amsdal/fixtures/manager.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/fixtures/manager.pyi +170 -0
- amsdal/fixtures/utils.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/fixtures/utils.pyi +9 -0
- amsdal/manager.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/manager.pyi +265 -0
- amsdal/mixins/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/mixins/__init__.pyi +0 -0
- amsdal/mixins/class_versions_mixin.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/mixins/class_versions_mixin.pyi +12 -0
- amsdal/models/__init__.py +19 -0
- amsdal/models/__init__.pyi +9 -0
- amsdal/models/core/__init__.py +0 -0
- amsdal/models/core/__init__.pyi +0 -0
- amsdal/models/core/class_object.py +37 -0
- amsdal/models/core/class_object.pyi +24 -0
- amsdal/models/core/class_object_meta.py +26 -0
- amsdal/models/core/class_object_meta.pyi +15 -0
- amsdal/models/core/class_property.py +20 -0
- amsdal/models/core/class_property.pyi +11 -0
- amsdal/models/core/class_property_meta.py +15 -0
- amsdal/models/core/class_property_meta.pyi +10 -0
- amsdal/models/core/file.py +156 -0
- amsdal/models/core/file.pyi +104 -0
- amsdal/models/core/fixture.py +25 -0
- amsdal/models/core/fixture.pyi +14 -0
- amsdal/models/core/option.py +11 -0
- amsdal/models/core/option.pyi +8 -0
- amsdal/models/core/validator.py +12 -0
- amsdal/models/core/validator.pyi +8 -0
- amsdal/models/types/__init__.py +0 -0
- amsdal/models/types/__init__.pyi +0 -0
- amsdal/models/types/object.py +26 -0
- amsdal/models/types/object.pyi +16 -0
- amsdal/py.typed +0 -0
- amsdal/queryset/__init__.py +21 -0
- amsdal/queryset/__init__.pyi +6 -0
- amsdal/schemas/__init__.py +0 -0
- amsdal/schemas/__init__.pyi +0 -0
- amsdal/schemas/core/class_object/model.json +31 -0
- amsdal/schemas/core/class_object/properties/display_name.py +9 -0
- amsdal/schemas/core/class_object_meta/model.json +59 -0
- amsdal/schemas/core/class_property/model.json +22 -0
- amsdal/schemas/core/class_property_meta/model.json +23 -0
- amsdal/schemas/core/file/hooks/pre_create.py +24 -0
- amsdal/schemas/core/file/hooks/pre_update.py +24 -0
- amsdal/schemas/core/file/model.json +23 -0
- amsdal/schemas/core/file/properties/from_file.py +34 -0
- amsdal/schemas/core/file/properties/mimetype.py +13 -0
- amsdal/schemas/core/file/properties/str.py +6 -0
- amsdal/schemas/core/file/properties/to_file.py +24 -0
- amsdal/schemas/core/file/properties/validate_data.py +32 -0
- amsdal/schemas/core/fixture/model.json +35 -0
- amsdal/schemas/core/option/model.json +19 -0
- amsdal/schemas/core/validator/model.json +19 -0
- amsdal/schemas/interfaces.py +25 -0
- amsdal/schemas/interfaces.pyi +20 -0
- amsdal/schemas/manager.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/schemas/manager.py +0 -0
- amsdal/schemas/manager.pyi +0 -0
- amsdal/schemas/mixins/__init__.py +0 -0
- amsdal/schemas/mixins/__init__.pyi +0 -0
- amsdal/schemas/mixins/check_dependencies_mixin.py +125 -0
- amsdal/schemas/mixins/check_dependencies_mixin.pyi +45 -0
- amsdal/schemas/mixins/verify_schemas_mixin.py +96 -0
- amsdal/schemas/mixins/verify_schemas_mixin.pyi +33 -0
- amsdal/schemas/repository.py +84 -0
- amsdal/schemas/repository.pyi +22 -0
- amsdal/schemas/types/anything/model.json +7 -0
- amsdal/schemas/types/array/model.json +7 -0
- amsdal/schemas/types/binary/model.json +7 -0
- amsdal/schemas/types/boolean/model.json +17 -0
- amsdal/schemas/types/date/model.json +7 -0
- amsdal/schemas/types/datetime/model.json +7 -0
- amsdal/schemas/types/dictionary/model.json +8 -0
- amsdal/schemas/types/number/model.json +8 -0
- amsdal/schemas/types/object/model.json +53 -0
- amsdal/schemas/types/string/model.json +8 -0
- amsdal/schemas/utils.py +16 -0
- amsdal/schemas/utils.pyi +10 -0
- amsdal/services/__init__.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/services/__init__.pyi +0 -0
- amsdal/services/transaction_execution.cpython-311-x86_64-linux-gnu.so +0 -0
- amsdal/services/transaction_execution.pyi +93 -0
- amsdal/transactions/__init__.py +13 -0
- amsdal/transactions/__init__.pyi +4 -0
- amsdal/utils/__init__.py +0 -0
- amsdal/utils/__init__.pyi +0 -0
- amsdal/utils/contrib_paths.py +23 -0
- amsdal/utils/contrib_paths.pyi +14 -0
- amsdal/utils/rollback/__init__.py +440 -0
- amsdal/utils/rollback/__init__.pyi +38 -0
- amsdal/utils/tests/__init__.py +0 -0
- amsdal/utils/tests/enums.py +18 -0
- amsdal/utils/tests/factories.py +49 -0
- amsdal/utils/tests/helpers.py +499 -0
- amsdal-0.4.13.dist-info/METADATA +369 -0
- amsdal-0.4.13.dist-info/RECORD +269 -0
- amsdal-0.4.13.dist-info/WHEEL +6 -0
- amsdal-0.4.13.dist-info/licenses/LICENSE.txt +107 -0
- amsdal-0.4.13.dist-info/top_level.txt +1 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from amsdal.cloud.services.actions.signup_action import FreeSignupAction as FreeSignupAction
|
3
|
+
from amsdal.configs.main import settings as settings
|
4
|
+
|
5
|
+
LICENCE_PATH: Incomplete
|
6
|
+
LICENCE_MESSAGE: Incomplete
|
7
|
+
|
8
|
+
def _input(msg: str) -> str: ...
|
9
|
+
def _print(msg: str) -> None: ...
|
10
|
+
def want_signup_input() -> str: ...
|
11
|
+
def licence_input() -> str: ...
|
12
|
+
def organization_name_input() -> str: ...
|
13
|
+
def email_input() -> str: ...
|
14
|
+
|
15
|
+
class SignupService:
|
16
|
+
"""
|
17
|
+
Service to handle the signup process for the Amsdal Framework.
|
18
|
+
|
19
|
+
This class provides functionality to prompt the user for signup details, validate the license agreement,
|
20
|
+
and create credentials for the user.
|
21
|
+
"""
|
22
|
+
@classmethod
|
23
|
+
def signup_prompt(cls) -> bool:
|
24
|
+
"""
|
25
|
+
Prompts the user to sign up for the Amsdal Framework.
|
26
|
+
|
27
|
+
This method guides the user through the signup process, including accepting the license agreement and
|
28
|
+
entering organization and email details. It then creates credentials for the user.
|
29
|
+
|
30
|
+
Returns:
|
31
|
+
bool: True if the signup process is completed successfully, False otherwise.
|
32
|
+
"""
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from amsdal.cloud.constants import JWT_PUBLIC_KEY as JWT_PUBLIC_KEY
|
3
|
+
from amsdal.cloud.services.auth.base import AuthHandlerBase as AuthHandlerBase
|
4
|
+
from amsdal.errors import AmsdalAuthenticationError as AmsdalAuthenticationError
|
5
|
+
|
6
|
+
HMAC_KEY: bytes
|
7
|
+
|
8
|
+
class TokenAuthHandler(AuthHandlerBase):
|
9
|
+
"""
|
10
|
+
Handles authentication using a token.
|
11
|
+
|
12
|
+
This class provides functionality to authenticate using a JWT token and validate its checksum.
|
13
|
+
"""
|
14
|
+
__token: Incomplete
|
15
|
+
public_key: Incomplete
|
16
|
+
def __init__(self, token: str | None, public_key: str = ...) -> None: ...
|
17
|
+
def _validate_checksum(self, expected_checksum: str) -> None: ...
|
18
|
+
def validate_credentials(self) -> None:
|
19
|
+
"""
|
20
|
+
Validates the provided JWT token.
|
21
|
+
|
22
|
+
This method decodes the token and validates its checksum or expiration date.
|
23
|
+
|
24
|
+
Raises:
|
25
|
+
AmsdalAuthenticationError: If the token is expired, has an invalid signature, is invalid, or is missing
|
26
|
+
an expiration date.
|
27
|
+
"""
|
File without changes
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import sys
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
5
|
+
|
6
|
+
TYPE_SCHEMAS_PATH: Path = BASE_DIR / 'schemas' / 'types'
|
7
|
+
CORE_SCHEMAS_PATH: Path = BASE_DIR / 'schemas' / 'core'
|
8
|
+
|
9
|
+
CORE_MIGRATIONS_PATH: Path = BASE_DIR / '__migrations__'
|
10
|
+
|
11
|
+
# Environment
|
12
|
+
TESTING_ENVIRONMENT = 'testing'
|
13
|
+
DEVELOPMENT_ENVIRONMENT = 'development'
|
14
|
+
PRODUCTION_ENVIRONMENT = 'production'
|
15
|
+
|
16
|
+
|
17
|
+
def get_default_environment() -> str:
|
18
|
+
"""
|
19
|
+
Determines the default environment based on the command used to run the script.
|
20
|
+
|
21
|
+
This function checks the command used to run the script and returns the appropriate
|
22
|
+
environment string. If the script is run using `pytest`, it returns 'testing'. Otherwise,
|
23
|
+
it returns 'development'.
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
str: The default environment string, either 'testing' or 'development'.
|
27
|
+
"""
|
28
|
+
cmd = sys.argv[0] if sys.argv else ''
|
29
|
+
|
30
|
+
if 'pytest' in cmd:
|
31
|
+
return TESTING_ENVIRONMENT
|
32
|
+
|
33
|
+
return DEVELOPMENT_ENVIRONMENT
|
@@ -0,0 +1,22 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
BASE_DIR: Incomplete
|
5
|
+
TYPE_SCHEMAS_PATH: Path
|
6
|
+
CORE_SCHEMAS_PATH: Path
|
7
|
+
CORE_MIGRATIONS_PATH: Path
|
8
|
+
TESTING_ENVIRONMENT: str
|
9
|
+
DEVELOPMENT_ENVIRONMENT: str
|
10
|
+
PRODUCTION_ENVIRONMENT: str
|
11
|
+
|
12
|
+
def get_default_environment() -> str:
|
13
|
+
"""
|
14
|
+
Determines the default environment based on the command used to run the script.
|
15
|
+
|
16
|
+
This function checks the command used to run the script and returns the appropriate
|
17
|
+
environment string. If the script is run using `pytest`, it returns 'testing'. Otherwise,
|
18
|
+
it returns 'development'.
|
19
|
+
|
20
|
+
Returns:
|
21
|
+
str: The default environment string, either 'testing' or 'development'.
|
22
|
+
"""
|
amsdal/configs/main.py
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
import importlib
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import TYPE_CHECKING
|
4
|
+
from typing import Any
|
5
|
+
from typing import TypeAlias
|
6
|
+
|
7
|
+
from pydantic import field_validator
|
8
|
+
from pydantic import model_validator
|
9
|
+
from pydantic_settings import BaseSettings
|
10
|
+
from pydantic_settings import SettingsConfigDict
|
11
|
+
|
12
|
+
|
13
|
+
class Settings(BaseSettings):
|
14
|
+
"""
|
15
|
+
Configuration settings for the application.
|
16
|
+
|
17
|
+
This class defines the configuration settings for the application, including paths,
|
18
|
+
environment variables, and other settings.
|
19
|
+
|
20
|
+
Attributes:
|
21
|
+
model_config (SettingsConfigDict): Configuration for the settings model.
|
22
|
+
APP_PATH (Path): Path to the app directory where the generated models and other files will be placed.
|
23
|
+
CONFIG_PATH (Path | None): Path to the config.yml file. If not specified, the default APP_PATH/config.yml
|
24
|
+
file will be used.
|
25
|
+
MODELS_MODULE_NAME (str): The models module name. The generated models will be placed in this module.
|
26
|
+
SCHEMAS_MODULE_NAME (str): The schemas module name. The schemas will be placed in this module.
|
27
|
+
FIXTURES_MODULE_NAME (str): The fixtures module name. The fixtures will be placed in this module.
|
28
|
+
STATIC_MODULE_NAME (str): The static module name. The static files will be placed in this module.
|
29
|
+
TRANSACTIONS_MODULE_NAME (str): The transactions module name. The transactions will be placed in this module.
|
30
|
+
MIGRATIONS_DIRECTORY_NAME (str): The migrations directory name. The migration files will be placed in this
|
31
|
+
folder.
|
32
|
+
ACCESS_KEY_ID (str | None): The access key that you will get during registering process.
|
33
|
+
SECRET_ACCESS_KEY (str | None): The secret access key that you will get during registering process.
|
34
|
+
ACCESS_TOKEN (str | None): The access token that you will get during sign in process.
|
35
|
+
SANDBOX_ENVIRONMENT (bool | None): If True, the sandbox environment will be used. If False,
|
36
|
+
the cloud environment will be used.
|
37
|
+
CONTRIBS (list[str]): List of contrib modules that will be loaded and used.
|
38
|
+
Can be specified via environment variable AMSDAL_CONTRIBS as comma separated string.
|
39
|
+
"""
|
40
|
+
|
41
|
+
model_config = SettingsConfigDict(
|
42
|
+
case_sensitive=True,
|
43
|
+
env_prefix='AMSDAL_',
|
44
|
+
env_file='.env',
|
45
|
+
env_file_encoding='utf-8',
|
46
|
+
extra='ignore',
|
47
|
+
)
|
48
|
+
|
49
|
+
APP_PATH: Path = Path('.')
|
50
|
+
CONFIG_PATH: Path | None = None
|
51
|
+
TYPE_MODELS_MODULE: str = 'amsdal.models.types'
|
52
|
+
CORE_MODELS_MODULE: str = 'amsdal.models.core'
|
53
|
+
USER_MODELS_MODULE_PATH: Path | None = None
|
54
|
+
USER_MODELS_MODULE: str = 'models'
|
55
|
+
FIXTURES_MODULE_PATH: Path | None = None
|
56
|
+
FIXTURES_MODULE_NAME: str = 'fixtures'
|
57
|
+
STATIC_MODULE_PATH: Path | None = None
|
58
|
+
STATIC_MODULE_NAME: str = 'static'
|
59
|
+
TRANSACTIONS_MODULE_PATH: Path | None = None
|
60
|
+
TRANSACTIONS_MODULE_NAME: str = 'transactions'
|
61
|
+
MIGRATIONS_MODULE_PATH: Path | None = None
|
62
|
+
MIGRATIONS_DIRECTORY_NAME: str = 'migrations'
|
63
|
+
ACCESS_KEY_ID: str | None = None
|
64
|
+
SECRET_ACCESS_KEY: str | None = None
|
65
|
+
ACCESS_TOKEN: str | None = None
|
66
|
+
SANDBOX_ENVIRONMENT: bool | None = None
|
67
|
+
CONTRIBS: list[str] = [
|
68
|
+
'amsdal.contrib.auth.app.AuthAppConfig',
|
69
|
+
'amsdal.contrib.frontend_configs.app.FrontendConfigAppConfig',
|
70
|
+
]
|
71
|
+
CONTRIB_MODELS_PACKAGE_NAME: str = 'models'
|
72
|
+
CONTRIB_MIGRATIONS_DIRECTORY_NAME: str = 'migrations'
|
73
|
+
|
74
|
+
@field_validator('CONTRIBS', mode='after')
|
75
|
+
def load_contrib_modules(cls, value: list[str]) -> list[str]: # noqa: N805
|
76
|
+
"""
|
77
|
+
Loads and initializes contrib modules.
|
78
|
+
|
79
|
+
This method takes a list of contrib module paths, imports each module, and calls the `on_ready` method
|
80
|
+
of the `AppConfig` class within each module.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
value (list[str]): A list of contrib module paths in the format 'package.module.ClassName'.
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
list[str]: The same list of contrib module paths after loading and initializing the modules.
|
87
|
+
"""
|
88
|
+
from amsdal.contrib.app_config import AppConfig
|
89
|
+
|
90
|
+
for contrib_module in value:
|
91
|
+
package_name, class_name = contrib_module.rsplit('.', 1)
|
92
|
+
_contrib_module = importlib.import_module(package_name)
|
93
|
+
app_config_class: type[AppConfig] = getattr(_contrib_module, class_name)
|
94
|
+
app_config_class().on_ready()
|
95
|
+
|
96
|
+
return value
|
97
|
+
|
98
|
+
@property
|
99
|
+
def user_models_path(self) -> Path:
|
100
|
+
"""
|
101
|
+
Returns the root path for models.
|
102
|
+
|
103
|
+
This property constructs and returns the path to the models directory
|
104
|
+
based on the `APP_PATH` and `MODELS_MODULE_NAME` attributes.
|
105
|
+
|
106
|
+
Returns:
|
107
|
+
Path: The root path for the models directory.
|
108
|
+
"""
|
109
|
+
if self.USER_MODELS_MODULE_PATH:
|
110
|
+
return self.USER_MODELS_MODULE_PATH
|
111
|
+
|
112
|
+
if '.' in self.USER_MODELS_MODULE:
|
113
|
+
_package, _ = self.USER_MODELS_MODULE.split('.', 1)
|
114
|
+
_module = importlib.import_module(_package)
|
115
|
+
|
116
|
+
return Path(_module.__path__[0])
|
117
|
+
|
118
|
+
return self.APP_PATH / self.USER_MODELS_MODULE
|
119
|
+
|
120
|
+
@property
|
121
|
+
def fixtures_root_path(self) -> Path:
|
122
|
+
"""
|
123
|
+
Returns the root path for fixtures.
|
124
|
+
|
125
|
+
This property constructs and returns the path to the fixtures directory
|
126
|
+
based on the `APP_PATH` and `FIXTURES_MODULE_NAME` attributes.
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
Path: The root path for the fixtures directory.
|
130
|
+
"""
|
131
|
+
return self.FIXTURES_MODULE_PATH or self.APP_PATH / self.FIXTURES_MODULE_NAME
|
132
|
+
|
133
|
+
@property
|
134
|
+
def static_root_path(self) -> Path:
|
135
|
+
"""
|
136
|
+
Returns the root path for static files.
|
137
|
+
|
138
|
+
This property constructs and returns the path to the static files directory
|
139
|
+
based on the `APP_PATH` and `STATIC_MODULE_NAME` attributes.
|
140
|
+
|
141
|
+
Returns:
|
142
|
+
Path: The root path for the static files directory.
|
143
|
+
"""
|
144
|
+
return self.STATIC_MODULE_PATH or self.APP_PATH / self.STATIC_MODULE_NAME
|
145
|
+
|
146
|
+
@property
|
147
|
+
def transactions_root_path(self) -> Path:
|
148
|
+
"""
|
149
|
+
Returns the root path for transactions.
|
150
|
+
|
151
|
+
This property constructs and returns the path to the transactions directory
|
152
|
+
based on the `models_root_path` and `TRANSACTIONS_MODULE_NAME` attributes.
|
153
|
+
|
154
|
+
Returns:
|
155
|
+
Path: The root path for the transactions directory.
|
156
|
+
"""
|
157
|
+
return self.TRANSACTIONS_MODULE_PATH or self.APP_PATH / self.TRANSACTIONS_MODULE_NAME
|
158
|
+
|
159
|
+
@property
|
160
|
+
def migrations_root_path(self) -> Path:
|
161
|
+
"""
|
162
|
+
Returns the root path for migrations.
|
163
|
+
|
164
|
+
This property constructs and returns the path to the migrations directory
|
165
|
+
based on the `models_root_path` and `MIGRATIONS_DIRECTORY_NAME` attributes.
|
166
|
+
|
167
|
+
Returns:
|
168
|
+
Path: The root path for the migrations directory.
|
169
|
+
"""
|
170
|
+
return self.MIGRATIONS_MODULE_PATH or self.APP_PATH / self.MIGRATIONS_DIRECTORY_NAME
|
171
|
+
|
172
|
+
@model_validator(mode='after')
|
173
|
+
def check_config_path_set(self) -> 'Settings':
|
174
|
+
"""
|
175
|
+
Ensures the configuration path is set.
|
176
|
+
|
177
|
+
This method checks if the `CONFIG_PATH` attribute is set. If it is not set,
|
178
|
+
it assigns a default path based on the `APP_PATH` attribute.
|
179
|
+
|
180
|
+
Returns:
|
181
|
+
Settings: The updated settings instance with the `CONFIG_PATH` attribute set.
|
182
|
+
"""
|
183
|
+
config_path = self.CONFIG_PATH
|
184
|
+
|
185
|
+
if not config_path:
|
186
|
+
self.CONFIG_PATH = self.APP_PATH / 'config.yml'
|
187
|
+
|
188
|
+
return self
|
189
|
+
|
190
|
+
|
191
|
+
if TYPE_CHECKING:
|
192
|
+
base: TypeAlias = Settings
|
193
|
+
else:
|
194
|
+
base: TypeAlias = object
|
195
|
+
|
196
|
+
|
197
|
+
class SettingsProxy(base):
|
198
|
+
"""
|
199
|
+
Proxy class for accessing and modifying settings.
|
200
|
+
|
201
|
+
This class acts as a proxy for the `Settings` class, allowing for dynamic
|
202
|
+
overriding and accessing of settings attributes.
|
203
|
+
"""
|
204
|
+
|
205
|
+
def __init__(self) -> None:
|
206
|
+
self._settings = Settings()
|
207
|
+
|
208
|
+
def override(self, **kwargs: Any) -> None:
|
209
|
+
"""
|
210
|
+
Overrides settings with provided keyword arguments.
|
211
|
+
|
212
|
+
This method updates the current settings with the provided keyword arguments.
|
213
|
+
|
214
|
+
Args:
|
215
|
+
**kwargs: Keyword arguments representing settings to override.
|
216
|
+
|
217
|
+
Returns:
|
218
|
+
None
|
219
|
+
"""
|
220
|
+
new_settings = self._settings.model_dump()
|
221
|
+
new_settings.update(kwargs)
|
222
|
+
self._settings = Settings(**new_settings)
|
223
|
+
|
224
|
+
def model_dump(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
|
225
|
+
"""
|
226
|
+
Dumps the current settings model to a dictionary.
|
227
|
+
|
228
|
+
This method returns the current settings as a dictionary.
|
229
|
+
|
230
|
+
Args:
|
231
|
+
*args: Additional positional arguments to pass to the underlying model dump method.
|
232
|
+
**kwargs: Additional keyword arguments to pass to the underlying model dump method.
|
233
|
+
|
234
|
+
Returns:
|
235
|
+
dict[str, Any]: The current settings as a dictionary.
|
236
|
+
"""
|
237
|
+
return self._settings.model_dump(*args, **kwargs)
|
238
|
+
|
239
|
+
def __getattr__(self, name: str) -> Any:
|
240
|
+
return getattr(self._settings, name)
|
241
|
+
|
242
|
+
def __delattr__(self, name: str) -> None:
|
243
|
+
try:
|
244
|
+
getattr(self._settings, name)
|
245
|
+
self._settings.__delattr__(name)
|
246
|
+
except AttributeError:
|
247
|
+
msg = f'Settings object has no attribute {name}'
|
248
|
+
raise AttributeError(msg) from None
|
249
|
+
|
250
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
251
|
+
if name == '_settings':
|
252
|
+
super().__setattr__(name, value)
|
253
|
+
return
|
254
|
+
|
255
|
+
self._settings.__setattr__(name, value)
|
256
|
+
|
257
|
+
|
258
|
+
settings: SettingsProxy = SettingsProxy()
|
amsdal/configs/main.pyi
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from pathlib import Path
|
3
|
+
from pydantic_settings import BaseSettings
|
4
|
+
from typing import Any, TypeAlias
|
5
|
+
|
6
|
+
class Settings(BaseSettings):
|
7
|
+
"""
|
8
|
+
Configuration settings for the application.
|
9
|
+
|
10
|
+
This class defines the configuration settings for the application, including paths,
|
11
|
+
environment variables, and other settings.
|
12
|
+
|
13
|
+
Attributes:
|
14
|
+
model_config (SettingsConfigDict): Configuration for the settings model.
|
15
|
+
APP_PATH (Path): Path to the app directory where the generated models and other files will be placed.
|
16
|
+
CONFIG_PATH (Path | None): Path to the config.yml file. If not specified, the default APP_PATH/config.yml
|
17
|
+
file will be used.
|
18
|
+
MODELS_MODULE_NAME (str): The models module name. The generated models will be placed in this module.
|
19
|
+
SCHEMAS_MODULE_NAME (str): The schemas module name. The schemas will be placed in this module.
|
20
|
+
FIXTURES_MODULE_NAME (str): The fixtures module name. The fixtures will be placed in this module.
|
21
|
+
STATIC_MODULE_NAME (str): The static module name. The static files will be placed in this module.
|
22
|
+
TRANSACTIONS_MODULE_NAME (str): The transactions module name. The transactions will be placed in this module.
|
23
|
+
MIGRATIONS_DIRECTORY_NAME (str): The migrations directory name. The migration files will be placed in this
|
24
|
+
folder.
|
25
|
+
ACCESS_KEY_ID (str | None): The access key that you will get during registering process.
|
26
|
+
SECRET_ACCESS_KEY (str | None): The secret access key that you will get during registering process.
|
27
|
+
ACCESS_TOKEN (str | None): The access token that you will get during sign in process.
|
28
|
+
SANDBOX_ENVIRONMENT (bool | None): If True, the sandbox environment will be used. If False,
|
29
|
+
the cloud environment will be used.
|
30
|
+
CONTRIBS (list[str]): List of contrib modules that will be loaded and used.
|
31
|
+
Can be specified via environment variable AMSDAL_CONTRIBS as comma separated string.
|
32
|
+
"""
|
33
|
+
model_config: Incomplete
|
34
|
+
APP_PATH: Path
|
35
|
+
CONFIG_PATH: Path | None
|
36
|
+
TYPE_MODELS_MODULE: str
|
37
|
+
CORE_MODELS_MODULE: str
|
38
|
+
USER_MODELS_MODULE_PATH: Path | None
|
39
|
+
USER_MODELS_MODULE: str
|
40
|
+
FIXTURES_MODULE_PATH: Path | None
|
41
|
+
FIXTURES_MODULE_NAME: str
|
42
|
+
STATIC_MODULE_PATH: Path | None
|
43
|
+
STATIC_MODULE_NAME: str
|
44
|
+
TRANSACTIONS_MODULE_PATH: Path | None
|
45
|
+
TRANSACTIONS_MODULE_NAME: str
|
46
|
+
MIGRATIONS_MODULE_PATH: Path | None
|
47
|
+
MIGRATIONS_DIRECTORY_NAME: str
|
48
|
+
ACCESS_KEY_ID: str | None
|
49
|
+
SECRET_ACCESS_KEY: str | None
|
50
|
+
ACCESS_TOKEN: str | None
|
51
|
+
SANDBOX_ENVIRONMENT: bool | None
|
52
|
+
CONTRIBS: list[str]
|
53
|
+
CONTRIB_MODELS_PACKAGE_NAME: str
|
54
|
+
CONTRIB_MIGRATIONS_DIRECTORY_NAME: str
|
55
|
+
def load_contrib_modules(cls, value: list[str]) -> list[str]:
|
56
|
+
"""
|
57
|
+
Loads and initializes contrib modules.
|
58
|
+
|
59
|
+
This method takes a list of contrib module paths, imports each module, and calls the `on_ready` method
|
60
|
+
of the `AppConfig` class within each module.
|
61
|
+
|
62
|
+
Args:
|
63
|
+
value (list[str]): A list of contrib module paths in the format 'package.module.ClassName'.
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
list[str]: The same list of contrib module paths after loading and initializing the modules.
|
67
|
+
"""
|
68
|
+
@property
|
69
|
+
def user_models_path(self) -> Path:
|
70
|
+
"""
|
71
|
+
Returns the root path for models.
|
72
|
+
|
73
|
+
This property constructs and returns the path to the models directory
|
74
|
+
based on the `APP_PATH` and `MODELS_MODULE_NAME` attributes.
|
75
|
+
|
76
|
+
Returns:
|
77
|
+
Path: The root path for the models directory.
|
78
|
+
"""
|
79
|
+
@property
|
80
|
+
def fixtures_root_path(self) -> Path:
|
81
|
+
"""
|
82
|
+
Returns the root path for fixtures.
|
83
|
+
|
84
|
+
This property constructs and returns the path to the fixtures directory
|
85
|
+
based on the `APP_PATH` and `FIXTURES_MODULE_NAME` attributes.
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
Path: The root path for the fixtures directory.
|
89
|
+
"""
|
90
|
+
@property
|
91
|
+
def static_root_path(self) -> Path:
|
92
|
+
"""
|
93
|
+
Returns the root path for static files.
|
94
|
+
|
95
|
+
This property constructs and returns the path to the static files directory
|
96
|
+
based on the `APP_PATH` and `STATIC_MODULE_NAME` attributes.
|
97
|
+
|
98
|
+
Returns:
|
99
|
+
Path: The root path for the static files directory.
|
100
|
+
"""
|
101
|
+
@property
|
102
|
+
def transactions_root_path(self) -> Path:
|
103
|
+
"""
|
104
|
+
Returns the root path for transactions.
|
105
|
+
|
106
|
+
This property constructs and returns the path to the transactions directory
|
107
|
+
based on the `models_root_path` and `TRANSACTIONS_MODULE_NAME` attributes.
|
108
|
+
|
109
|
+
Returns:
|
110
|
+
Path: The root path for the transactions directory.
|
111
|
+
"""
|
112
|
+
@property
|
113
|
+
def migrations_root_path(self) -> Path:
|
114
|
+
"""
|
115
|
+
Returns the root path for migrations.
|
116
|
+
|
117
|
+
This property constructs and returns the path to the migrations directory
|
118
|
+
based on the `models_root_path` and `MIGRATIONS_DIRECTORY_NAME` attributes.
|
119
|
+
|
120
|
+
Returns:
|
121
|
+
Path: The root path for the migrations directory.
|
122
|
+
"""
|
123
|
+
def check_config_path_set(self) -> Settings:
|
124
|
+
"""
|
125
|
+
Ensures the configuration path is set.
|
126
|
+
|
127
|
+
This method checks if the `CONFIG_PATH` attribute is set. If it is not set,
|
128
|
+
it assigns a default path based on the `APP_PATH` attribute.
|
129
|
+
|
130
|
+
Returns:
|
131
|
+
Settings: The updated settings instance with the `CONFIG_PATH` attribute set.
|
132
|
+
"""
|
133
|
+
base: TypeAlias = Settings
|
134
|
+
|
135
|
+
class SettingsProxy(base):
|
136
|
+
"""
|
137
|
+
Proxy class for accessing and modifying settings.
|
138
|
+
|
139
|
+
This class acts as a proxy for the `Settings` class, allowing for dynamic
|
140
|
+
overriding and accessing of settings attributes.
|
141
|
+
"""
|
142
|
+
_settings: Incomplete
|
143
|
+
def __init__(self) -> None: ...
|
144
|
+
def override(self, **kwargs: Any) -> None:
|
145
|
+
"""
|
146
|
+
Overrides settings with provided keyword arguments.
|
147
|
+
|
148
|
+
This method updates the current settings with the provided keyword arguments.
|
149
|
+
|
150
|
+
Args:
|
151
|
+
**kwargs: Keyword arguments representing settings to override.
|
152
|
+
|
153
|
+
Returns:
|
154
|
+
None
|
155
|
+
"""
|
156
|
+
def model_dump(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
|
157
|
+
"""
|
158
|
+
Dumps the current settings model to a dictionary.
|
159
|
+
|
160
|
+
This method returns the current settings as a dictionary.
|
161
|
+
|
162
|
+
Args:
|
163
|
+
*args: Additional positional arguments to pass to the underlying model dump method.
|
164
|
+
**kwargs: Additional keyword arguments to pass to the underlying model dump method.
|
165
|
+
|
166
|
+
Returns:
|
167
|
+
dict[str, Any]: The current settings as a dictionary.
|
168
|
+
"""
|
169
|
+
def __getattr__(self, name: str) -> Any: ...
|
170
|
+
def __delattr__(self, name: str) -> None: ...
|
171
|
+
def __setattr__(self, name: str, value: Any) -> None: ...
|
172
|
+
|
173
|
+
settings: SettingsProxy
|
File without changes
|
File without changes
|
@@ -0,0 +1,69 @@
|
|
1
|
+
from contextvars import ContextVar
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
_CONTEXT: ContextVar[dict[str, Any] | None] = ContextVar('_context', default=None)
|
5
|
+
|
6
|
+
|
7
|
+
class AmsdalContextManager:
|
8
|
+
"""
|
9
|
+
Manages a context for storing and retrieving data.
|
10
|
+
|
11
|
+
This class provides methods to get, set, and add to a context stored in a
|
12
|
+
`ContextVar`. The context is a dictionary that can hold any key-value pairs.
|
13
|
+
"""
|
14
|
+
|
15
|
+
@classmethod
|
16
|
+
def get_context(cls) -> dict[str, Any]:
|
17
|
+
"""
|
18
|
+
Retrieves the current context or creates a new one if none exists.
|
19
|
+
|
20
|
+
This method gets the current context from the `_CONTEXT` variable. If no
|
21
|
+
context exists, it creates a new empty context and sets it.
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
dict[str, Any]: The current context.
|
25
|
+
"""
|
26
|
+
_context = _CONTEXT.get()
|
27
|
+
|
28
|
+
if _context is not None:
|
29
|
+
return _context
|
30
|
+
|
31
|
+
new_context: dict[str, Any] = {}
|
32
|
+
cls.set_context(new_context)
|
33
|
+
|
34
|
+
return new_context
|
35
|
+
|
36
|
+
@classmethod
|
37
|
+
def set_context(cls, context: dict[str, Any]) -> None:
|
38
|
+
"""
|
39
|
+
Sets the context to the provided dictionary.
|
40
|
+
|
41
|
+
This method sets the `_CONTEXT` variable to the provided context.
|
42
|
+
|
43
|
+
Args:
|
44
|
+
context (dict[str, Any]): The context to set.
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
None
|
48
|
+
"""
|
49
|
+
_CONTEXT.set(context)
|
50
|
+
|
51
|
+
@classmethod
|
52
|
+
def add_to_context(cls, key: str, value: Any) -> None:
|
53
|
+
"""
|
54
|
+
Adds a key-value pair to the current context.
|
55
|
+
|
56
|
+
This method adds the provided key-value pair to the current context.
|
57
|
+
|
58
|
+
Args:
|
59
|
+
key (str): The key to add to the context.
|
60
|
+
value (Any): The value to associate with the key.
|
61
|
+
|
62
|
+
Returns:
|
63
|
+
None
|
64
|
+
"""
|
65
|
+
context = cls.get_context()
|
66
|
+
|
67
|
+
context[key] = value
|
68
|
+
|
69
|
+
cls.set_context(context)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
from contextvars import ContextVar
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
_CONTEXT: ContextVar[dict[str, Any] | None]
|
5
|
+
|
6
|
+
class AmsdalContextManager:
|
7
|
+
"""
|
8
|
+
Manages a context for storing and retrieving data.
|
9
|
+
|
10
|
+
This class provides methods to get, set, and add to a context stored in a
|
11
|
+
`ContextVar`. The context is a dictionary that can hold any key-value pairs.
|
12
|
+
"""
|
13
|
+
@classmethod
|
14
|
+
def get_context(cls) -> dict[str, Any]:
|
15
|
+
"""
|
16
|
+
Retrieves the current context or creates a new one if none exists.
|
17
|
+
|
18
|
+
This method gets the current context from the `_CONTEXT` variable. If no
|
19
|
+
context exists, it creates a new empty context and sets it.
|
20
|
+
|
21
|
+
Returns:
|
22
|
+
dict[str, Any]: The current context.
|
23
|
+
"""
|
24
|
+
@classmethod
|
25
|
+
def set_context(cls, context: dict[str, Any]) -> None:
|
26
|
+
"""
|
27
|
+
Sets the context to the provided dictionary.
|
28
|
+
|
29
|
+
This method sets the `_CONTEXT` variable to the provided context.
|
30
|
+
|
31
|
+
Args:
|
32
|
+
context (dict[str, Any]): The context to set.
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
None
|
36
|
+
"""
|
37
|
+
@classmethod
|
38
|
+
def add_to_context(cls, key: str, value: Any) -> None:
|
39
|
+
"""
|
40
|
+
Adds a key-value pair to the current context.
|
41
|
+
|
42
|
+
This method adds the provided key-value pair to the current context.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
key (str): The key to add to the context.
|
46
|
+
value (Any): The value to associate with the key.
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
None
|
50
|
+
"""
|
Binary file
|
File without changes
|