instant-python 0.20.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.
- instant_python/__init__.py +1 -0
- instant_python/cli/__init__.py +0 -0
- instant_python/cli/cli.py +58 -0
- instant_python/cli/instant_python_typer.py +35 -0
- instant_python/config/__init__.py +0 -0
- instant_python/config/application/__init__.py +0 -0
- instant_python/config/application/config_generator.py +23 -0
- instant_python/config/delivery/__init__.py +0 -0
- instant_python/config/delivery/cli.py +19 -0
- instant_python/config/domain/__init__.py +0 -0
- instant_python/config/domain/question_wizard.py +7 -0
- instant_python/config/infra/__init__.py +0 -0
- instant_python/config/infra/question_wizard/__init__.py +0 -0
- instant_python/config/infra/question_wizard/questionary_console_wizard.py +25 -0
- instant_python/config/infra/question_wizard/step/__init__.py +0 -0
- instant_python/config/infra/question_wizard/step/dependencies_step.py +64 -0
- instant_python/config/infra/question_wizard/step/general_step.py +81 -0
- instant_python/config/infra/question_wizard/step/git_step.py +41 -0
- instant_python/config/infra/question_wizard/step/questionary.py +17 -0
- instant_python/config/infra/question_wizard/step/steps.py +21 -0
- instant_python/config/infra/question_wizard/step/template_step.py +63 -0
- instant_python/initialize/__init__.py +0 -0
- instant_python/initialize/application/__init__.py +0 -0
- instant_python/initialize/application/project_initializer.py +47 -0
- instant_python/initialize/delivery/__init__.py +0 -0
- instant_python/initialize/delivery/cli.py +48 -0
- instant_python/initialize/domain/__init__.py +0 -0
- instant_python/initialize/domain/env_manager.py +9 -0
- instant_python/initialize/domain/node.py +73 -0
- instant_python/initialize/domain/project_formatter.py +7 -0
- instant_python/initialize/domain/project_renderer.py +10 -0
- instant_python/initialize/domain/project_structure.py +77 -0
- instant_python/initialize/domain/project_writer.py +20 -0
- instant_python/initialize/domain/version_control_configurer.py +9 -0
- instant_python/initialize/infra/__init__.py +0 -0
- instant_python/initialize/infra/env_manager/__init__.py +0 -0
- instant_python/initialize/infra/env_manager/env_manager_factory.py +27 -0
- instant_python/initialize/infra/env_manager/pdm_env_manager.py +66 -0
- instant_python/initialize/infra/env_manager/system_console.py +65 -0
- instant_python/initialize/infra/env_manager/uv_env_manager.py +74 -0
- instant_python/initialize/infra/formatter/__init__.py +0 -0
- instant_python/initialize/infra/formatter/ruff_project_formatter.py +10 -0
- instant_python/initialize/infra/renderer/__init__.py +0 -0
- instant_python/initialize/infra/renderer/jinja_environment.py +71 -0
- instant_python/initialize/infra/renderer/jinja_project_renderer.py +57 -0
- instant_python/initialize/infra/version_control/__init__.py +0 -0
- instant_python/initialize/infra/version_control/git_configurer.py +29 -0
- instant_python/initialize/infra/writer/__init__.py +0 -0
- instant_python/initialize/infra/writer/file_system_project_writer.py +23 -0
- instant_python/shared/__init__.py +0 -0
- instant_python/shared/application_error.py +8 -0
- instant_python/shared/domain/__init__.py +0 -0
- instant_python/shared/domain/config_repository.py +18 -0
- instant_python/shared/domain/config_schema.py +113 -0
- instant_python/shared/domain/dependency_config.py +41 -0
- instant_python/shared/domain/general_config.py +71 -0
- instant_python/shared/domain/git_config.py +32 -0
- instant_python/shared/domain/template_config.py +76 -0
- instant_python/shared/infra/__init__.py +0 -0
- instant_python/shared/infra/persistence/__init__.py +0 -0
- instant_python/shared/infra/persistence/yaml_config_repository.py +39 -0
- instant_python/shared/supported_built_in_features.py +20 -0
- instant_python/shared/supported_licenses.py +11 -0
- instant_python/shared/supported_managers.py +10 -0
- instant_python/shared/supported_python_versions.py +12 -0
- instant_python/shared/supported_templates.py +12 -0
- instant_python/templates/boilerplate/.gitignore +164 -0
- instant_python/templates/boilerplate/.pre-commit-config.yml +73 -0
- instant_python/templates/boilerplate/.python-version +1 -0
- instant_python/templates/boilerplate/CITATION.cff +13 -0
- instant_python/templates/boilerplate/LICENSE +896 -0
- instant_python/templates/boilerplate/README.md +8 -0
- instant_python/templates/boilerplate/SECURITY.md +43 -0
- instant_python/templates/boilerplate/event_bus/__init__.py +0 -0
- instant_python/templates/boilerplate/event_bus/domain_event.py +15 -0
- instant_python/templates/boilerplate/event_bus/domain_event_json_deserializer.py +25 -0
- instant_python/templates/boilerplate/event_bus/domain_event_json_serializer.py +16 -0
- instant_python/templates/boilerplate/event_bus/domain_event_subscriber.py +33 -0
- instant_python/templates/boilerplate/event_bus/event_aggregate.py +19 -0
- instant_python/templates/boilerplate/event_bus/event_bus.py +9 -0
- instant_python/templates/boilerplate/event_bus/exchange_type.py +14 -0
- instant_python/templates/boilerplate/event_bus/mock_event_bus.py +16 -0
- instant_python/templates/boilerplate/event_bus/rabbit_mq_configurer.py +45 -0
- instant_python/templates/boilerplate/event_bus/rabbit_mq_connection.py +71 -0
- instant_python/templates/boilerplate/event_bus/rabbit_mq_consumer.py +56 -0
- instant_python/templates/boilerplate/event_bus/rabbit_mq_event_bus.py +26 -0
- instant_python/templates/boilerplate/event_bus/rabbit_mq_queue_formatter.py +21 -0
- instant_python/templates/boilerplate/event_bus/rabbit_mq_settings.py +8 -0
- instant_python/templates/boilerplate/exceptions/__init__.py +0 -0
- instant_python/templates/boilerplate/exceptions/base_error.py +13 -0
- instant_python/templates/boilerplate/exceptions/domain_error.py +6 -0
- instant_python/templates/boilerplate/exceptions/domain_event_type_not_found_error.py +6 -0
- instant_python/templates/boilerplate/exceptions/rabbit_mq_connection_not_established_error.py +7 -0
- instant_python/templates/boilerplate/exceptions/required_value_error.py +6 -0
- instant_python/templates/boilerplate/fastapi/__init__.py +0 -0
- instant_python/templates/boilerplate/fastapi/application.py +74 -0
- instant_python/templates/boilerplate/fastapi/error_handlers.py +88 -0
- instant_python/templates/boilerplate/fastapi/error_response.py +31 -0
- instant_python/templates/boilerplate/fastapi/fastapi_log_middleware.py +32 -0
- instant_python/templates/boilerplate/fastapi/lifespan.py +13 -0
- instant_python/templates/boilerplate/fastapi/success_response.py +13 -0
- instant_python/templates/boilerplate/github/action.yml +35 -0
- instant_python/templates/boilerplate/github/bug_report.yml +60 -0
- instant_python/templates/boilerplate/github/ci.yml +199 -0
- instant_python/templates/boilerplate/github/feature_request.yml +21 -0
- instant_python/templates/boilerplate/github/release.yml +94 -0
- instant_python/templates/boilerplate/logger/__init__.py +0 -0
- instant_python/templates/boilerplate/logger/file_logger.py +55 -0
- instant_python/templates/boilerplate/logger/file_rotating_handler.py +36 -0
- instant_python/templates/boilerplate/logger/json_formatter.py +16 -0
- instant_python/templates/boilerplate/mypy.ini +41 -0
- instant_python/templates/boilerplate/persistence/__init__.py +0 -0
- instant_python/templates/boilerplate/persistence/alembic_migrator.py +19 -0
- instant_python/templates/boilerplate/persistence/async/README.md +1 -0
- instant_python/templates/boilerplate/persistence/async/__init__.py +0 -0
- instant_python/templates/boilerplate/persistence/async/alembic.ini +124 -0
- instant_python/templates/boilerplate/persistence/async/async_engine_fixture.py +20 -0
- instant_python/templates/boilerplate/persistence/async/async_session.py +20 -0
- instant_python/templates/boilerplate/persistence/async/env.py +94 -0
- instant_python/templates/boilerplate/persistence/async/models_metadata.py +10 -0
- instant_python/templates/boilerplate/persistence/async/postgres_settings.py +15 -0
- instant_python/templates/boilerplate/persistence/async/script.py.mako +26 -0
- instant_python/templates/boilerplate/persistence/async/sqlalchemy_repository.py +28 -0
- instant_python/templates/boilerplate/persistence/base.py +4 -0
- instant_python/templates/boilerplate/persistence/synchronous/__init__.py +0 -0
- instant_python/templates/boilerplate/persistence/synchronous/session_maker.py +21 -0
- instant_python/templates/boilerplate/persistence/synchronous/sqlalchemy_repository.py +40 -0
- instant_python/templates/boilerplate/pyproject.toml +134 -0
- instant_python/templates/boilerplate/pytest.ini +10 -0
- instant_python/templates/boilerplate/scripts/add_dependency.py +45 -0
- instant_python/templates/boilerplate/scripts/create_aggregate.py +33 -0
- instant_python/templates/boilerplate/scripts/insert_template.py +90 -0
- instant_python/templates/boilerplate/scripts/integration.sh +39 -0
- instant_python/templates/boilerplate/scripts/local_setup.py +12 -0
- instant_python/templates/boilerplate/scripts/makefile +184 -0
- instant_python/templates/boilerplate/scripts/post-merge.py +40 -0
- instant_python/templates/boilerplate/scripts/pre-commit.py +15 -0
- instant_python/templates/boilerplate/scripts/pre-push.py +6 -0
- instant_python/templates/boilerplate/scripts/remove_dependency.py +40 -0
- instant_python/templates/boilerplate/scripts/unit.sh +40 -0
- instant_python/templates/project_structure/clean_architecture/layers/application.yml +3 -0
- instant_python/templates/project_structure/clean_architecture/layers/delivery.yml +8 -0
- instant_python/templates/project_structure/clean_architecture/layers/domain.yml +10 -0
- instant_python/templates/project_structure/clean_architecture/layers/infra.yml +12 -0
- instant_python/templates/project_structure/clean_architecture/layers/test_application.yml +3 -0
- instant_python/templates/project_structure/clean_architecture/layers/test_delivery.yml +3 -0
- instant_python/templates/project_structure/clean_architecture/layers/test_domain.yml +3 -0
- instant_python/templates/project_structure/clean_architecture/layers/test_infra.yml +9 -0
- instant_python/templates/project_structure/clean_architecture/main_structure.yml +38 -0
- instant_python/templates/project_structure/clean_architecture/source.yml +9 -0
- instant_python/templates/project_structure/clean_architecture/test.yml +9 -0
- instant_python/templates/project_structure/config_files/gitignore.yml +3 -0
- instant_python/templates/project_structure/config_files/mypy.yml +4 -0
- instant_python/templates/project_structure/config_files/pyproject.yml +4 -0
- instant_python/templates/project_structure/config_files/pytest.yml +4 -0
- instant_python/templates/project_structure/config_files/python_version.yml +3 -0
- instant_python/templates/project_structure/documentation/citation.yml +4 -0
- instant_python/templates/project_structure/documentation/license.yml +3 -0
- instant_python/templates/project_structure/documentation/readme.yml +4 -0
- instant_python/templates/project_structure/documentation/security.yml +4 -0
- instant_python/templates/project_structure/domain_driven_design/layers/bounded_context.yml +17 -0
- instant_python/templates/project_structure/domain_driven_design/layers/delivery.yml +8 -0
- instant_python/templates/project_structure/domain_driven_design/layers/shared.yml +18 -0
- instant_python/templates/project_structure/domain_driven_design/layers/shared_domain.yml +10 -0
- instant_python/templates/project_structure/domain_driven_design/layers/shared_infra.yml +12 -0
- instant_python/templates/project_structure/domain_driven_design/layers/test_shared.yml +8 -0
- instant_python/templates/project_structure/domain_driven_design/layers/test_shared_delivery.yml +3 -0
- instant_python/templates/project_structure/domain_driven_design/layers/test_shared_domain.yml +3 -0
- instant_python/templates/project_structure/domain_driven_design/layers/test_shared_infra.yml +9 -0
- instant_python/templates/project_structure/domain_driven_design/main_structure.yml +38 -0
- instant_python/templates/project_structure/domain_driven_design/source.yml +10 -0
- instant_python/templates/project_structure/domain_driven_design/test.yml +9 -0
- instant_python/templates/project_structure/errors.yml +12 -0
- instant_python/templates/project_structure/events/event_bus_domain.yml +48 -0
- instant_python/templates/project_structure/events/event_bus_infra.yml +40 -0
- instant_python/templates/project_structure/events/mock_event_bus.yml +4 -0
- instant_python/templates/project_structure/fastapi/fastapi_app.yml +32 -0
- instant_python/templates/project_structure/fastapi/fastapi_domain.yml +12 -0
- instant_python/templates/project_structure/fastapi/fastapi_infra.yml +12 -0
- instant_python/templates/project_structure/github/github_action.yml +24 -0
- instant_python/templates/project_structure/github/github_issues_template.yml +14 -0
- instant_python/templates/project_structure/github/makefile.yml +3 -0
- instant_python/templates/project_structure/github/precommit_hook.yml +4 -0
- instant_python/templates/project_structure/logger.yml +16 -0
- instant_python/templates/project_structure/macros.j2 +73 -0
- instant_python/templates/project_structure/persistence/alembic_migrator.yml +6 -0
- instant_python/templates/project_structure/persistence/async_alembic.yml +27 -0
- instant_python/templates/project_structure/persistence/async_engine_conftest.yml +4 -0
- instant_python/templates/project_structure/persistence/async_sqlalchemy.yml +14 -0
- instant_python/templates/project_structure/persistence/persistence.yml +8 -0
- instant_python/templates/project_structure/persistence/synchronous_sqlalchemy.yml +20 -0
- instant_python/templates/project_structure/standard_project/layers/source_features.yml +13 -0
- instant_python/templates/project_structure/standard_project/layers/test_event_bus.yml +6 -0
- instant_python/templates/project_structure/standard_project/layers/test_features.yml +6 -0
- instant_python/templates/project_structure/standard_project/main_structure.yml +38 -0
- instant_python/templates/project_structure/standard_project/source.yml +5 -0
- instant_python/templates/project_structure/standard_project/test.yml +5 -0
- instant_python-0.20.0.dist-info/METADATA +318 -0
- instant_python-0.20.0.dist-info/RECORD +202 -0
- instant_python-0.20.0.dist-info/WHEEL +4 -0
- instant_python-0.20.0.dist-info/entry_points.txt +2 -0
- instant_python-0.20.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# A generic, single database configuration.
|
|
2
|
+
|
|
3
|
+
[alembic]
|
|
4
|
+
# path to migration scripts
|
|
5
|
+
# Use forward slashes (/) also on windows to provide an os agnostic path
|
|
6
|
+
script_location = migrations
|
|
7
|
+
|
|
8
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
|
9
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
|
10
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
|
11
|
+
# for all available tokens
|
|
12
|
+
file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
|
13
|
+
|
|
14
|
+
# sys.path path, will be prepended to sys.path if present.
|
|
15
|
+
# defaults to the current working directory.
|
|
16
|
+
prepend_sys_path = .
|
|
17
|
+
|
|
18
|
+
# timezone to use when rendering the date within the migration file
|
|
19
|
+
# as well as the filename.
|
|
20
|
+
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
|
|
21
|
+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
|
|
22
|
+
# string value is passed to ZoneInfo()
|
|
23
|
+
# leave blank for localtime
|
|
24
|
+
# timezone =
|
|
25
|
+
|
|
26
|
+
# max length of characters to apply to the "slug" field
|
|
27
|
+
# truncate_slug_length = 40
|
|
28
|
+
|
|
29
|
+
# set to 'true' to run the environment during
|
|
30
|
+
# the 'revision' command, regardless of autogenerate
|
|
31
|
+
# revision_environment = false
|
|
32
|
+
|
|
33
|
+
# set to 'true' to allow .pyc and .pyo files without
|
|
34
|
+
# a source .py file to be detected as revisions in the
|
|
35
|
+
# versions/ directory
|
|
36
|
+
# sourceless = false
|
|
37
|
+
|
|
38
|
+
# version location specification; This defaults
|
|
39
|
+
# to migrations/versions. When using multiple version
|
|
40
|
+
# directories, initial revisions must be specified with --version-path.
|
|
41
|
+
# The path separator used here should be the separator specified by "version_path_separator" below.
|
|
42
|
+
# version_locations = %(here)s/bar:%(here)s/bat:migrations/versions
|
|
43
|
+
|
|
44
|
+
# version path separator; As mentioned above, this is the character used to split
|
|
45
|
+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
|
|
46
|
+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
|
|
47
|
+
# Valid values for version_path_separator are:
|
|
48
|
+
#
|
|
49
|
+
# version_path_separator = :
|
|
50
|
+
# version_path_separator = ;
|
|
51
|
+
# version_path_separator = space
|
|
52
|
+
# version_path_separator = newline
|
|
53
|
+
#
|
|
54
|
+
# Use os.pathsep. Default configuration used for new projects.
|
|
55
|
+
version_path_separator = os
|
|
56
|
+
|
|
57
|
+
# set to 'true' to search source files recursively
|
|
58
|
+
# in each "version_locations" directory
|
|
59
|
+
# new in Alembic version 1.10
|
|
60
|
+
# recursive_version_locations = false
|
|
61
|
+
|
|
62
|
+
# the output encoding used when revision files
|
|
63
|
+
# are written from script.py.mako
|
|
64
|
+
# output_encoding = utf-8
|
|
65
|
+
|
|
66
|
+
sqlalchemy.url = driver://user:pass@localhost/dbname
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
[post_write_hooks]
|
|
70
|
+
# post_write_hooks defines scripts or Python functions that are run
|
|
71
|
+
# on newly generated revision scripts. See the documentation for further
|
|
72
|
+
# detail and examples
|
|
73
|
+
|
|
74
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
|
75
|
+
# hooks = black
|
|
76
|
+
# black.type = console_scripts
|
|
77
|
+
# black.entrypoint = black
|
|
78
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
|
79
|
+
|
|
80
|
+
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
|
|
81
|
+
hooks = ruff_lint, ruff_format
|
|
82
|
+
ruff_lint.type = exec
|
|
83
|
+
ruff_lint.executable = %(here)s/.venv/bin/ruff
|
|
84
|
+
ruff_lint.options = check --fix REVISION_SCRIPT_FILENAME
|
|
85
|
+
|
|
86
|
+
# format with attempts to fix using "ruff" - use the exec runner, execute a binary
|
|
87
|
+
ruff_format.type = exec
|
|
88
|
+
ruff_format.executable = %(here)s/.venv/bin/ruff
|
|
89
|
+
ruff_format.options = format REVISION_SCRIPT_FILENAME
|
|
90
|
+
|
|
91
|
+
# Logging configuration
|
|
92
|
+
[loggers]
|
|
93
|
+
keys = root,sqlalchemy,alembic
|
|
94
|
+
|
|
95
|
+
[handlers]
|
|
96
|
+
keys = console
|
|
97
|
+
|
|
98
|
+
[formatters]
|
|
99
|
+
keys = generic
|
|
100
|
+
|
|
101
|
+
[logger_root]
|
|
102
|
+
level = WARNING
|
|
103
|
+
handlers = console
|
|
104
|
+
qualname =
|
|
105
|
+
|
|
106
|
+
[logger_sqlalchemy]
|
|
107
|
+
level = WARNING
|
|
108
|
+
handlers =
|
|
109
|
+
qualname = sqlalchemy.engine
|
|
110
|
+
|
|
111
|
+
[logger_alembic]
|
|
112
|
+
level = INFO
|
|
113
|
+
handlers =
|
|
114
|
+
qualname = alembic
|
|
115
|
+
|
|
116
|
+
[handler_console]
|
|
117
|
+
class = StreamHandler
|
|
118
|
+
args = (sys.stderr,)
|
|
119
|
+
level = NOTSET
|
|
120
|
+
formatter = generic
|
|
121
|
+
|
|
122
|
+
[formatter_generic]
|
|
123
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
124
|
+
datefmt = %H:%M:%S
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from collections.abc import AsyncGenerator
|
|
2
|
+
import pytest
|
|
3
|
+
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
|
4
|
+
|
|
5
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.postgres_settings" | resolve_import_path(template.name) }} import PostgresSettings
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
async def engine() -> AsyncGenerator[AsyncEngine]:
|
|
10
|
+
settings = PostgresSettings() # type: ignore
|
|
11
|
+
engine = create_async_engine(settings.postgres_url)
|
|
12
|
+
|
|
13
|
+
async with engine.begin() as conn:
|
|
14
|
+
await conn.run_sync(EntityModel.metadata.create_all)
|
|
15
|
+
|
|
16
|
+
yield engine
|
|
17
|
+
|
|
18
|
+
async with engine.begin() as conn:
|
|
19
|
+
await conn.run_sync(EntityModel.metadata.drop_all)
|
|
20
|
+
await engine.dispose()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from collections.abc import AsyncGenerator
|
|
2
|
+
|
|
3
|
+
from sqlalchemy.ext.asyncio import create_async_engine
|
|
4
|
+
from sqlalchemy.ext.asyncio.session import AsyncSession
|
|
5
|
+
|
|
6
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.postgres_settings" | resolve_import_path(template.name) }} import PostgresSettings
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
settings = PostgresSettings() # type: ignore
|
|
10
|
+
engine = create_async_engine(str(settings.postgres_url))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def get_async_session() -> AsyncGenerator[AsyncSession]:
|
|
14
|
+
async with AsyncSession(engine) as session:
|
|
15
|
+
try:
|
|
16
|
+
yield session
|
|
17
|
+
await session.commit()
|
|
18
|
+
except Exception:
|
|
19
|
+
await session.rollback()
|
|
20
|
+
raise
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from logging.config import fileConfig
|
|
3
|
+
|
|
4
|
+
from alembic import context
|
|
5
|
+
from sqlalchemy import pool
|
|
6
|
+
from sqlalchemy.engine import Connection
|
|
7
|
+
from sqlalchemy.ext.asyncio import async_engine_from_config
|
|
8
|
+
|
|
9
|
+
from migrations.models_metadata import base
|
|
10
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.postgres_settings" | resolve_import_path(template.name) }} import PostgresSettings
|
|
11
|
+
|
|
12
|
+
# this is the Alembic Config object, which provides
|
|
13
|
+
# access to the values within the .ini file in use.
|
|
14
|
+
config = context.config
|
|
15
|
+
|
|
16
|
+
settings = PostgresSettings() # type: ignore
|
|
17
|
+
config.set_main_option("sqlalchemy.url", settings.postgres_url)
|
|
18
|
+
|
|
19
|
+
# Interpret the config file for Python logging.
|
|
20
|
+
# This line sets up loggers basically.
|
|
21
|
+
if config.config_file_name is not None:
|
|
22
|
+
fileConfig(config.config_file_name)
|
|
23
|
+
|
|
24
|
+
# add your model's MetaData object here
|
|
25
|
+
# for 'autogenerate' support
|
|
26
|
+
# from myapp import mymodel
|
|
27
|
+
# target_metadata = mymodel.Base.metadata
|
|
28
|
+
target_metadata = base.metadata
|
|
29
|
+
|
|
30
|
+
# other values from the config, defined by the needs of env.py,
|
|
31
|
+
# can be acquired:
|
|
32
|
+
# my_important_option = config.get_main_option("my_important_option")
|
|
33
|
+
# ... etc.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run_migrations_offline() -> None:
|
|
37
|
+
"""Run migrations in 'offline' mode.
|
|
38
|
+
|
|
39
|
+
This configures the context with just a URL
|
|
40
|
+
and not an Engine, though an Engine is acceptable
|
|
41
|
+
here as well. By skipping the Engine creation
|
|
42
|
+
we don't even need a DBAPI to be available.
|
|
43
|
+
|
|
44
|
+
Calls to context.execute() here emit the given string to the
|
|
45
|
+
script output.
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
url = config.get_main_option("sqlalchemy.url")
|
|
49
|
+
context.configure(
|
|
50
|
+
url=url,
|
|
51
|
+
target_metadata=target_metadata,
|
|
52
|
+
literal_binds=True,
|
|
53
|
+
dialect_opts={"paramstyle": "named"},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
with context.begin_transaction():
|
|
57
|
+
context.run_migrations()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def do_run_migrations(connection: Connection) -> None:
|
|
61
|
+
context.configure(connection=connection, target_metadata=target_metadata)
|
|
62
|
+
|
|
63
|
+
with context.begin_transaction():
|
|
64
|
+
context.run_migrations()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async def run_async_migrations() -> None:
|
|
68
|
+
"""In this scenario we need to create an Engine
|
|
69
|
+
and associate a connection with the context.
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
connectable = async_engine_from_config(
|
|
74
|
+
config.get_section(config.config_ini_section, {}),
|
|
75
|
+
prefix="sqlalchemy.",
|
|
76
|
+
poolclass=pool.NullPool,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
async with connectable.connect() as connection:
|
|
80
|
+
await connection.run_sync(do_run_migrations)
|
|
81
|
+
|
|
82
|
+
await connectable.dispose()
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def run_migrations_online() -> None:
|
|
86
|
+
"""Run migrations in 'online' mode."""
|
|
87
|
+
|
|
88
|
+
asyncio.run(run_async_migrations())
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if context.is_offline_mode():
|
|
92
|
+
run_migrations_offline()
|
|
93
|
+
else:
|
|
94
|
+
run_migrations_online()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module is needed for alembic to detect correctly all models of the project.
|
|
3
|
+
|
|
4
|
+
When we import Base.metadata in the env.py file it will include all the models that inherit from it only if these models
|
|
5
|
+
have already been imported. To keep the env.py file clean, we import the Base.metadata in this file and then import all the
|
|
6
|
+
needed models.
|
|
7
|
+
"""
|
|
8
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.sqlalchemy.base" | resolve_import_path(template.name) }} import Base
|
|
9
|
+
|
|
10
|
+
base = Base
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import Field
|
|
2
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PostgresSettings(BaseSettings):
|
|
6
|
+
model_config = SettingsConfigDict(env_file=(".env", ".env.prod"), extra="ignore")
|
|
7
|
+
postgres_user: str = Field(alias="POSTGRES_USER")
|
|
8
|
+
postgres_password: str = Field(alias="POSTGRES_PASSWORD")
|
|
9
|
+
postgres_db: str = Field(alias="POSTGRES_DB")
|
|
10
|
+
postgres_host: str = Field(alias="POSTGRES_HOST")
|
|
11
|
+
postgres_port: str = Field(alias="POSTGRES_PORT")
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
def postgres_url(self) -> str:
|
|
15
|
+
return f"postgresql+asyncpg://{self.postgres_user}:{self.postgres_password}@{self.postgres_host}:{self.postgres_port}/{self.postgres_db}"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""${message}
|
|
2
|
+
|
|
3
|
+
Revision ID: ${up_revision}
|
|
4
|
+
Revises: ${down_revision | comma,n}
|
|
5
|
+
Create Date: ${create_date}
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
${imports if imports else ""}
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = ${repr(up_revision)}
|
|
16
|
+
down_revision: Union[str, None] = ${repr(down_revision)}
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
${upgrades if upgrades else "pass"}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def downgrade() -> None:
|
|
26
|
+
${downgrades if downgrades else "pass"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from typing import TypeVar
|
|
2
|
+
|
|
3
|
+
from {{ general.source_name }}{{ "shared.domain.value_objects.uuid" | resolve_import_path(template.name) }} import Uuid
|
|
4
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.sqlalchemy.base" | resolve_import_path(template.name) }} import Base
|
|
5
|
+
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Entity = TypeVar("Entity")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SqlalchemyRepository[Model: Base]:
|
|
12
|
+
_model_class: type[Model]
|
|
13
|
+
_session_maker: async_sessionmaker[AsyncSession]
|
|
14
|
+
|
|
15
|
+
def __init__(self, engine: AsyncEngine, model_class: type[Model]) -> None:
|
|
16
|
+
self._session_maker = async_sessionmaker(bind=engine)
|
|
17
|
+
self._model_class = model_class
|
|
18
|
+
|
|
19
|
+
async def persist(self, entity: Entity) -> None:
|
|
20
|
+
async with self._session_maker() as session:
|
|
21
|
+
entity_model = self._model_class(**entity.to_dict())
|
|
22
|
+
session.add(entity_model)
|
|
23
|
+
await session.commit()
|
|
24
|
+
|
|
25
|
+
async def find(self, entity_id: Uuid) -> Entity:
|
|
26
|
+
async with self._session_maker() as session:
|
|
27
|
+
entity_model = await session.get(self._model_class, entity_id.value)
|
|
28
|
+
return entity_model.to_aggregate() if entity_model else None
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from sqlalchemy import create_engine, Engine
|
|
2
|
+
from sqlalchemy.orm import sessionmaker, Session
|
|
3
|
+
|
|
4
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.sqlalchemy.base" | resolve_import_path(template.name) }} import (
|
|
5
|
+
Base,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SessionMaker:
|
|
10
|
+
_session_maker: sessionmaker[Session]
|
|
11
|
+
_engine: Engine
|
|
12
|
+
|
|
13
|
+
def __init__(self, url: str) -> None:
|
|
14
|
+
self._engine = create_engine(url)
|
|
15
|
+
self._session_maker = sessionmaker(bind=self._engine)
|
|
16
|
+
|
|
17
|
+
def get_session(self) -> Session:
|
|
18
|
+
return self._session_maker()
|
|
19
|
+
|
|
20
|
+
def create_tables(self) -> None:
|
|
21
|
+
Base.metadata.create_all(self._engine)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{% if general.python_version in ["3.13", "3.12", "3.11"] %}
|
|
2
|
+
from typing import TypeVar
|
|
3
|
+
{% else %}
|
|
4
|
+
from typing import TypeVar, Generic
|
|
5
|
+
{% endif %}
|
|
6
|
+
|
|
7
|
+
from {{ general.source_name }}{{ "shared.domain.value_object.uuid" | resolve_import_path(template.name) }} import Uuid
|
|
8
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.sqlalchemy.base" | resolve_import_path(template.name) }} import Base
|
|
9
|
+
from {{ general.source_name }}{{ "shared.infra.persistence.sqlalchemy.session_maker" | resolve_import_path(template.name) }} import (
|
|
10
|
+
SessionMaker,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
Entity = TypeVar("Entity")
|
|
14
|
+
{% if general.python_version in ["3.13", "3.12", "3.11"] %}
|
|
15
|
+
class SqlAlchemyRepository[Model: Base]:
|
|
16
|
+
{% else %}
|
|
17
|
+
Model = TypeVar("Model", bound=Base)
|
|
18
|
+
class SqlAlchemyRepository(Generic[Model]):
|
|
19
|
+
{% endif %}
|
|
20
|
+
_model_class: type[Model]
|
|
21
|
+
_session_maker: SessionMaker
|
|
22
|
+
|
|
23
|
+
def __init__(self, session_maker: SessionMaker, model_class: Type[Model]) -> None:
|
|
24
|
+
self._session_maker = session_maker
|
|
25
|
+
self._model_class = model_class
|
|
26
|
+
|
|
27
|
+
def persist(self, entity: Entity) -> None:
|
|
28
|
+
with self._session_maker.get_session() as session:
|
|
29
|
+
entity_model = self._model_class(**entity.to_dict())
|
|
30
|
+
session.add(entity_model)
|
|
31
|
+
session.commit()
|
|
32
|
+
|
|
33
|
+
def search_by_id(self, entity_id: Uuid) -> Entity | None:
|
|
34
|
+
with self._session_maker.get_session() as session:
|
|
35
|
+
entity_model = (
|
|
36
|
+
session.query(self._model_class)
|
|
37
|
+
.filter(self._model_class.id == entity_id.value)
|
|
38
|
+
.first()
|
|
39
|
+
)
|
|
40
|
+
return entity_model.to_aggregate() if entity_model else None
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
{% set feature_to_main_dependencies = {
|
|
2
|
+
"async_sqlalchemy": ["sqlalchemy", "asyncpg", "psycopg2-binary", "pydantic", "pydantic-settings"],
|
|
3
|
+
"async_alembic": ["alembic", "pydantic", "pydantic-settings"],
|
|
4
|
+
"event_bus": ["pika", "sindripy"],
|
|
5
|
+
"fastapi_application": ["fastapi[standard]"],
|
|
6
|
+
"value_objects": ["sindripy"]
|
|
7
|
+
} %}
|
|
8
|
+
{% macro get_main_dependencies() -%}
|
|
9
|
+
{%- set deps = [] -%}
|
|
10
|
+
{%- for feature, dependencies in feature_to_main_dependencies.items() -%}
|
|
11
|
+
{%- if feature in template.built_in_features -%}
|
|
12
|
+
{%- set _ = deps.extend(dependencies) -%}
|
|
13
|
+
{%- endif -%}
|
|
14
|
+
{%- endfor -%}
|
|
15
|
+
{% for dep in deps %}
|
|
16
|
+
"{{ dep }}",
|
|
17
|
+
{% endfor -%}
|
|
18
|
+
{%- endmacro %}
|
|
19
|
+
{% set has_github_actions_or_makefile = ["github_actions", "makefile"] | is_in(template.built_in_features) %}
|
|
20
|
+
{% set feature_to_dev_dependencies = {
|
|
21
|
+
"release": {
|
|
22
|
+
"python-semantic-release": ["github_actions"]
|
|
23
|
+
},
|
|
24
|
+
"lint": {
|
|
25
|
+
"mypy": ["github_actions", "makefile", "precommit_hook"],
|
|
26
|
+
"ruff": ["github_actions", "makefile", "precommit_hook"],
|
|
27
|
+
"pip-audit": ["github_actions"],
|
|
28
|
+
"pre-commit": ["precommit_hook"]
|
|
29
|
+
},
|
|
30
|
+
"test": {
|
|
31
|
+
"pytest": ["github_actions", "makefile", "precommit_hook"],
|
|
32
|
+
"pytest-asyncio": ["async_alembic", "async_sqlalchemy"]
|
|
33
|
+
}
|
|
34
|
+
} %}
|
|
35
|
+
{% macro get_dev_group_dependencies(group_name) -%}
|
|
36
|
+
{%- set deps_result = [] -%}
|
|
37
|
+
{%- set group = feature_to_dev_dependencies[group_name] -%}
|
|
38
|
+
{%- for dep, required_features in group.items() -%}
|
|
39
|
+
{%- if required_features | length == 0 or required_features | is_in(template.built_in_features) -%}
|
|
40
|
+
{%- set _ = deps_result.append(dep) -%}
|
|
41
|
+
{%- endif -%}
|
|
42
|
+
{%- endfor -%}
|
|
43
|
+
{%- for dep in deps_result %}
|
|
44
|
+
"{{ dep }}",
|
|
45
|
+
{% endfor -%}
|
|
46
|
+
{%- endmacro -%}
|
|
47
|
+
{% set release_deps = get_dev_group_dependencies("release") %}
|
|
48
|
+
{% set lint_deps = get_dev_group_dependencies("lint") %}
|
|
49
|
+
{% set test_deps = get_dev_group_dependencies("test") %}
|
|
50
|
+
[project]
|
|
51
|
+
name = "{{ general.slug }}"
|
|
52
|
+
version = "{{ general.version }}"
|
|
53
|
+
description = "{{ general.description }}"
|
|
54
|
+
authors = [{name = "{{ general.author }}", email = "{{ git.email }}"}]
|
|
55
|
+
dependencies = [
|
|
56
|
+
{{ get_main_dependencies() }}]
|
|
57
|
+
requires-python = "=={{ general.python_version }}.*"
|
|
58
|
+
readme = "README.md"
|
|
59
|
+
license = { file = "LICENSE" }
|
|
60
|
+
|
|
61
|
+
{% if general.dependency_manager == "pdm" %}
|
|
62
|
+
[tool.pdm]
|
|
63
|
+
distribution = false
|
|
64
|
+
{% endif %}
|
|
65
|
+
{% if release_deps.strip() or lint_deps.strip() or test_deps.strip() %}
|
|
66
|
+
[dependency-groups]
|
|
67
|
+
{% if release_deps.strip() %}
|
|
68
|
+
release = [
|
|
69
|
+
{{ release_deps }}]
|
|
70
|
+
{% endif %}
|
|
71
|
+
{% if lint_deps.strip() %}
|
|
72
|
+
lint = [
|
|
73
|
+
{{ lint_deps }}]
|
|
74
|
+
{% endif %}
|
|
75
|
+
{% if test_deps.strip() %}
|
|
76
|
+
test = [
|
|
77
|
+
{{ test_deps }}]
|
|
78
|
+
{% endif %}
|
|
79
|
+
{% endif %}
|
|
80
|
+
|
|
81
|
+
{% if dependencies | has_dependency("ruff") or has_github_actions_or_makefile %}
|
|
82
|
+
[tool.ruff]
|
|
83
|
+
line-length = 120
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint]
|
|
86
|
+
select = ["E", "F", "W", "B", "C4", "UP", "I"]
|
|
87
|
+
ignore = ["B008"]
|
|
88
|
+
|
|
89
|
+
[tool.ruff.lint.isort]
|
|
90
|
+
known-first-party = ["{{ general.source_name }}", "test"]
|
|
91
|
+
|
|
92
|
+
[tool.ruff.format]
|
|
93
|
+
quote-style = "double"
|
|
94
|
+
indent-style = "space"
|
|
95
|
+
skip-magic-trailing-comma = false
|
|
96
|
+
{% endif %}
|
|
97
|
+
|
|
98
|
+
{% if "github_actions" in template.built_in_features %}
|
|
99
|
+
[project.optional-dependencies]
|
|
100
|
+
build = ["uv>=0.7.21"]
|
|
101
|
+
|
|
102
|
+
[tool.semantic_release]
|
|
103
|
+
version_toml = ["pyproject.toml:project.version"]
|
|
104
|
+
commit_message = "bump: new version {version} created"
|
|
105
|
+
commit_parser = "conventional"
|
|
106
|
+
major_on_zero = false
|
|
107
|
+
allow_zero_version = true
|
|
108
|
+
no_git_verify = false
|
|
109
|
+
tag_format = "{version}"
|
|
110
|
+
build_command = """
|
|
111
|
+
pip install -e '.[build]'
|
|
112
|
+
{{ general.dependency_manager }} lock --upgrade-package {{ general.slug }}
|
|
113
|
+
git add {{ general.dependency_manager }}.lock
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
[tool.semantic_release.commit_parser_options]
|
|
117
|
+
minor_tags = ["feat"]
|
|
118
|
+
patch_tags = ["fix", "perf", "refactor", "test", "build"]
|
|
119
|
+
allowed_tags = ["feat", "fix", "refactor", "perf", "build"]
|
|
120
|
+
default_bump_level = 0
|
|
121
|
+
parse_squash_commits = false
|
|
122
|
+
ignore_merge_commits = true
|
|
123
|
+
|
|
124
|
+
[tool.semantic_release.changelog]
|
|
125
|
+
changelog_file = "CHANGELOG.md"
|
|
126
|
+
exclude_commit_patterns = ['''^Merge pull request #''', '''^Merge branch ''']
|
|
127
|
+
mode = "update"
|
|
128
|
+
#template_dir = "docs/changelog"
|
|
129
|
+
|
|
130
|
+
[tool.semantic_release.changelog.default_templates]
|
|
131
|
+
changelog_file = "CHANGELOG"
|
|
132
|
+
output_format = "md"
|
|
133
|
+
mask_initial_release = false
|
|
134
|
+
{% endif %}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
{% if general.dependency_manager == "pdm" -%}
|
|
5
|
+
def main() -> None:
|
|
6
|
+
dependency = input("Dependency to install: ")
|
|
7
|
+
is_dev = input(f"Do you want to install {dependency} as a dev dependency? (y/n): ")
|
|
8
|
+
add_to_group = input(
|
|
9
|
+
f"Do you want to install the {dependency} inside a group? (y/n): "
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
dev_flag = ""
|
|
13
|
+
group_flag = ""
|
|
14
|
+
if is_dev.lower() == "y":
|
|
15
|
+
dev_flag = "--dev"
|
|
16
|
+
if add_to_group.lower() == "y":
|
|
17
|
+
group_name = input("Group name: ")
|
|
18
|
+
group_flag = f"--group {group_name}"
|
|
19
|
+
|
|
20
|
+
cmd = f"pdm add {dev_flag} {group_flag} {dependency}".strip()
|
|
21
|
+
subprocess.run(cmd, shell=True, check=True)
|
|
22
|
+
|
|
23
|
+
{%- elif general.dependency_manager == "uv" -%}
|
|
24
|
+
def main() -> None:
|
|
25
|
+
dependency = input("Dependency to install: ")
|
|
26
|
+
is_dev = input(f"Do you want to install {dependency} as a dev dependency? (y/n): ")
|
|
27
|
+
add_to_group = input(
|
|
28
|
+
f"Do you want to install the {dependency} inside a group? (y/n): "
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
flag = ""
|
|
32
|
+
if is_dev.lower() == "y":
|
|
33
|
+
flag = "-d"
|
|
34
|
+
if add_to_group.lower() == "y":
|
|
35
|
+
group_name = input("Group name: ")
|
|
36
|
+
flag = f"-G {group_name}"
|
|
37
|
+
|
|
38
|
+
cmd = f"uv add {flag} {dependency}".strip()
|
|
39
|
+
subprocess.run(cmd, shell=True, check=True)
|
|
40
|
+
{%- endif %}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
45
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
def create_package_structure(base_dir: str, context: str, aggregate: str) -> None:
|
|
4
|
+
"""Create the folder structure and __init__.py files for the given context and aggregate."""
|
|
5
|
+
context_base_path = Path(base_dir, "contexts", context)
|
|
6
|
+
aggregate_base_path = context_base_path / aggregate
|
|
7
|
+
|
|
8
|
+
dirs_to_create = [
|
|
9
|
+
context_base_path,
|
|
10
|
+
aggregate_base_path,
|
|
11
|
+
aggregate_base_path / "application",
|
|
12
|
+
aggregate_base_path / "domain",
|
|
13
|
+
aggregate_base_path / "infra",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
for directory in dirs_to_create:
|
|
17
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
init_file = directory / "__init__.py"
|
|
19
|
+
if not init_file.exists():
|
|
20
|
+
init_file.touch()
|
|
21
|
+
|
|
22
|
+
def main() -> None:
|
|
23
|
+
context = input("Enter the name of the bounded context: ").strip()
|
|
24
|
+
aggregate = input("Enter the name of the new aggregate: ").strip()
|
|
25
|
+
|
|
26
|
+
create_package_structure("instant_python", context, aggregate)
|
|
27
|
+
create_package_structure("tests", context, aggregate)
|
|
28
|
+
|
|
29
|
+
print(f"Successfully created the aggregate '{aggregate}' under context '{context}'.")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|