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,18 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from instant_python.shared.domain.config_schema import ConfigSchema
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ConfigRepository(ABC):
|
|
8
|
+
@abstractmethod
|
|
9
|
+
def write(self, config: ConfigSchema) -> None:
|
|
10
|
+
raise NotImplementedError
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def read(self, path: Path) -> ConfigSchema:
|
|
14
|
+
raise NotImplementedError
|
|
15
|
+
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def move(self, config: ConfigSchema, destination_path: Path) -> None:
|
|
18
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import TypedDict, Union
|
|
4
|
+
|
|
5
|
+
from instant_python.shared.domain.dependency_config import (
|
|
6
|
+
DependencyConfig,
|
|
7
|
+
)
|
|
8
|
+
from instant_python.shared.domain.general_config import (
|
|
9
|
+
GeneralConfig,
|
|
10
|
+
)
|
|
11
|
+
from instant_python.shared.domain.git_config import GitConfig
|
|
12
|
+
from instant_python.shared.domain.template_config import (
|
|
13
|
+
TemplateConfig,
|
|
14
|
+
)
|
|
15
|
+
from instant_python.shared.application_error import ApplicationError
|
|
16
|
+
from instant_python.shared.supported_templates import SupportedTemplates
|
|
17
|
+
|
|
18
|
+
_GENERAL = "general"
|
|
19
|
+
_DEPENDENCIES = "dependencies"
|
|
20
|
+
_TEMPLATE = "template"
|
|
21
|
+
_GIT = "git"
|
|
22
|
+
_REQUIRED_CONFIG_KEYS = [_GENERAL, _DEPENDENCIES, _TEMPLATE, _GIT]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class ConfigSchema:
|
|
27
|
+
general: GeneralConfig
|
|
28
|
+
dependencies: list[DependencyConfig]
|
|
29
|
+
template: TemplateConfig
|
|
30
|
+
git: GitConfig
|
|
31
|
+
config_file_path: Path = field(default_factory=lambda: ConfigSchema._DEFAULT_CONFIG_PATH)
|
|
32
|
+
|
|
33
|
+
_DEFAULT_CONFIG_PATH: Path = Path.cwd() / "ipy.yml"
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def from_primitives(
|
|
37
|
+
cls, content: dict[str, Union[dict, list]], custom_config_path: Union[Path, None] = None
|
|
38
|
+
) -> "ConfigSchema":
|
|
39
|
+
cls._ensure_config_is_not_empty(content)
|
|
40
|
+
cls._ensure_all_required_sections_are_present(content)
|
|
41
|
+
return cls(
|
|
42
|
+
general=GeneralConfig(**content[_GENERAL]),
|
|
43
|
+
dependencies=[DependencyConfig(**dep) for dep in content[_DEPENDENCIES]] if content[_DEPENDENCIES] else [],
|
|
44
|
+
template=TemplateConfig(**content[_TEMPLATE]),
|
|
45
|
+
git=GitConfig(**content[_GIT]),
|
|
46
|
+
config_file_path=custom_config_path if custom_config_path else cls._DEFAULT_CONFIG_PATH,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def _ensure_config_is_not_empty(cls, content: dict[str, Union[dict, list]]) -> None:
|
|
51
|
+
if not content:
|
|
52
|
+
raise EmptyConfigurationNotAllowed
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def _ensure_all_required_sections_are_present(cls, content: dict[str, Union[dict, list]]):
|
|
56
|
+
missing_keys = [key for key in _REQUIRED_CONFIG_KEYS if key not in content]
|
|
57
|
+
if missing_keys:
|
|
58
|
+
raise ConfigKeyNotPresent(missing_keys, _REQUIRED_CONFIG_KEYS)
|
|
59
|
+
|
|
60
|
+
def calculate_config_destination_path(self, base_directory: Path) -> Path:
|
|
61
|
+
return base_directory / self.project_folder_name / self.config_file_path.name
|
|
62
|
+
|
|
63
|
+
def calculate_project_structure_template_name(self) -> str:
|
|
64
|
+
if self.template_type == SupportedTemplates.CUSTOM:
|
|
65
|
+
return ""
|
|
66
|
+
return self.template_type
|
|
67
|
+
|
|
68
|
+
def to_primitives(self) -> "ConfigSchemaPrimitives":
|
|
69
|
+
return ConfigSchemaPrimitives(
|
|
70
|
+
general=self.general.to_primitives(),
|
|
71
|
+
dependencies=[dependency.to_primitives() for dependency in self.dependencies],
|
|
72
|
+
template=self.template.to_primitives(),
|
|
73
|
+
git=self.git.to_primitives(),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def template_type(self) -> str:
|
|
78
|
+
return self.template.name
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def project_folder_name(self) -> str:
|
|
82
|
+
return self.general.slug
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def dependency_manager(self) -> str:
|
|
86
|
+
return self.general.dependency_manager
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def python_version(self) -> str:
|
|
90
|
+
return self.general.python_version
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def version_control_has_to_be_initialized(self) -> bool:
|
|
94
|
+
return self.git.initialize
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class ConfigSchemaPrimitives(TypedDict):
|
|
98
|
+
general: dict[str, str]
|
|
99
|
+
dependencies: list[dict[str, Union[str, bool]]]
|
|
100
|
+
template: dict[str, Union[str, list[str]]]
|
|
101
|
+
git: dict[str, Union[str, bool]]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class ConfigKeyNotPresent(ApplicationError):
|
|
105
|
+
def __init__(self, missing_keys: list[str], required_keys: list[str]) -> None:
|
|
106
|
+
super().__init__(
|
|
107
|
+
message=f"The following required keys are missing from the config file: {', '.join(missing_keys)}. Required keys are: {', '.join(required_keys)}."
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class EmptyConfigurationNotAllowed(ApplicationError):
|
|
112
|
+
def __init__(self) -> None:
|
|
113
|
+
super().__init__(message="Configuration file cannot be empty.")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from dataclasses import dataclass, field, asdict
|
|
2
|
+
|
|
3
|
+
from instant_python.shared.application_error import ApplicationError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class DependencyConfig:
|
|
8
|
+
name: str
|
|
9
|
+
version: str
|
|
10
|
+
is_dev: bool = field(default=False)
|
|
11
|
+
group: str = field(default_factory=str)
|
|
12
|
+
|
|
13
|
+
def __post_init__(self) -> None:
|
|
14
|
+
self.version = str(self.version)
|
|
15
|
+
self._ensure_dependency_is_dev_if_group_is_set()
|
|
16
|
+
|
|
17
|
+
def to_primitives(self) -> dict[str, str | bool]:
|
|
18
|
+
return asdict(self)
|
|
19
|
+
|
|
20
|
+
def get_installation_flag(self) -> tuple[str, ...]:
|
|
21
|
+
if self.group:
|
|
22
|
+
return (f"--group {self.group}",)
|
|
23
|
+
elif self.is_dev:
|
|
24
|
+
return ("--dev",)
|
|
25
|
+
return tuple()
|
|
26
|
+
|
|
27
|
+
def get_specification(self) -> str:
|
|
28
|
+
if self.version == "latest":
|
|
29
|
+
return self.name
|
|
30
|
+
return f"{self.name}=={self.version}"
|
|
31
|
+
|
|
32
|
+
def _ensure_dependency_is_dev_if_group_is_set(self) -> None:
|
|
33
|
+
if self.group and not self.is_dev:
|
|
34
|
+
raise NotDevDependencyIncludedInGroup(self.name, self.group)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class NotDevDependencyIncludedInGroup(ApplicationError):
|
|
38
|
+
def __init__(self, dependency_name: str, dependency_group: str) -> None:
|
|
39
|
+
super().__init__(
|
|
40
|
+
message=f"Dependency '{dependency_name}' has been included in group '{dependency_group}' but it is not a development dependency. Please ensure that only development dependencies are included in groups."
|
|
41
|
+
)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from dataclasses import dataclass, asdict, field
|
|
3
|
+
from typing import ClassVar
|
|
4
|
+
|
|
5
|
+
from instant_python.shared.application_error import ApplicationError
|
|
6
|
+
from instant_python.shared.supported_licenses import SupportedLicenses
|
|
7
|
+
from instant_python.shared.supported_managers import SupportedManagers
|
|
8
|
+
from instant_python.shared.supported_python_versions import SupportedPythonVersions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class GeneralConfig:
|
|
13
|
+
slug: str
|
|
14
|
+
source_name: str
|
|
15
|
+
description: str
|
|
16
|
+
version: str
|
|
17
|
+
author: str
|
|
18
|
+
license: str
|
|
19
|
+
python_version: str
|
|
20
|
+
dependency_manager: str
|
|
21
|
+
year: int = field(default=datetime.now().year)
|
|
22
|
+
|
|
23
|
+
_SUPPORTED_DEPENDENCY_MANAGERS: ClassVar[list[str]] = SupportedManagers.get_supported_managers()
|
|
24
|
+
_SUPPORTED_PYTHON_VERSIONS: ClassVar[list[str]] = SupportedPythonVersions.get_supported_versions()
|
|
25
|
+
_SUPPORTED_LICENSES: ClassVar[list[str]] = SupportedLicenses.get_supported_licenses()
|
|
26
|
+
|
|
27
|
+
def __post_init__(self) -> None:
|
|
28
|
+
self.version = str(self.version)
|
|
29
|
+
self.python_version = str(self.python_version)
|
|
30
|
+
self._remove_white_spaces_from_slug_if_present()
|
|
31
|
+
self._ensure_license_is_supported()
|
|
32
|
+
self._ensure_python_version_is_supported()
|
|
33
|
+
self._ensure_dependency_manager_is_supported()
|
|
34
|
+
|
|
35
|
+
def _remove_white_spaces_from_slug_if_present(self) -> None:
|
|
36
|
+
if " " in self.slug:
|
|
37
|
+
self.slug = self.slug.replace(" ", "")
|
|
38
|
+
|
|
39
|
+
def _ensure_license_is_supported(self) -> None:
|
|
40
|
+
if self.license not in self._SUPPORTED_LICENSES:
|
|
41
|
+
raise InvalidLicenseValue(self.license, self._SUPPORTED_LICENSES)
|
|
42
|
+
|
|
43
|
+
def _ensure_python_version_is_supported(self) -> None:
|
|
44
|
+
if self.python_version not in self._SUPPORTED_PYTHON_VERSIONS:
|
|
45
|
+
raise InvalidPythonVersionValue(self.python_version, self._SUPPORTED_PYTHON_VERSIONS)
|
|
46
|
+
|
|
47
|
+
def _ensure_dependency_manager_is_supported(self) -> None:
|
|
48
|
+
if self.dependency_manager not in self._SUPPORTED_DEPENDENCY_MANAGERS:
|
|
49
|
+
raise InvalidDependencyManagerValue(self.dependency_manager, self._SUPPORTED_DEPENDENCY_MANAGERS)
|
|
50
|
+
|
|
51
|
+
def to_primitives(self) -> dict[str, str]:
|
|
52
|
+
return asdict(self)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class InvalidDependencyManagerValue(ApplicationError):
|
|
56
|
+
def __init__(self, value: str, supported_values: list[str]) -> None:
|
|
57
|
+
super().__init__(
|
|
58
|
+
message=f"Invalid dependency manager: {value}. Allowed values are {', '.join(supported_values)}."
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class InvalidLicenseValue(ApplicationError):
|
|
63
|
+
def __init__(self, value: str, supported_values: list[str]) -> None:
|
|
64
|
+
super().__init__(message=f"Invalid license: {value}. Allowed values are {', '.join(supported_values)}.")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class InvalidPythonVersionValue(ApplicationError):
|
|
68
|
+
def __init__(self, value: str, supported_values: list[str]) -> None:
|
|
69
|
+
super().__init__(
|
|
70
|
+
message=f"Invalid Python version: {value}. Allowed versions are {', '.join(supported_values)}."
|
|
71
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from dataclasses import dataclass, field, asdict
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from instant_python.shared.application_error import ApplicationError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class GitConfig:
|
|
9
|
+
initialize: bool
|
|
10
|
+
username: Optional[str] = field(default=None)
|
|
11
|
+
email: Optional[str] = field(default=None)
|
|
12
|
+
|
|
13
|
+
def __post_init__(self) -> None:
|
|
14
|
+
self._ensure_username_and_email_are_set_if_initializing()
|
|
15
|
+
|
|
16
|
+
def _ensure_username_and_email_are_set_if_initializing(self) -> None:
|
|
17
|
+
if self.initialize and (self._username_is_not_specified() or self._email_is_not_specified()):
|
|
18
|
+
raise GitUserOrEmailNotPresent()
|
|
19
|
+
|
|
20
|
+
def _email_is_not_specified(self) -> bool:
|
|
21
|
+
return self.email is None or self.email == ""
|
|
22
|
+
|
|
23
|
+
def _username_is_not_specified(self) -> bool:
|
|
24
|
+
return self.username is None or self.username == ""
|
|
25
|
+
|
|
26
|
+
def to_primitives(self) -> dict[str, str | bool]:
|
|
27
|
+
return asdict(self)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class GitUserOrEmailNotPresent(ApplicationError):
|
|
31
|
+
def __init__(self) -> None:
|
|
32
|
+
super().__init__(message="When initializing a git repository, both username and email must be provided.")
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from dataclasses import dataclass, field, asdict
|
|
2
|
+
from typing import ClassVar, Optional, Union
|
|
3
|
+
|
|
4
|
+
from instant_python.shared.application_error import ApplicationError
|
|
5
|
+
from instant_python.shared.supported_built_in_features import SupportedBuiltInFeatures
|
|
6
|
+
from instant_python.shared.supported_templates import SupportedTemplates
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class TemplateConfig:
|
|
11
|
+
name: str
|
|
12
|
+
built_in_features: list[str] = field(default_factory=list)
|
|
13
|
+
specify_bounded_context: bool = field(default=False)
|
|
14
|
+
bounded_context: Optional[str] = field(default=None)
|
|
15
|
+
aggregate_name: Optional[str] = field(default=None)
|
|
16
|
+
|
|
17
|
+
_SUPPORTED_TEMPLATES: ClassVar[list[str]] = SupportedTemplates.get_supported_templates()
|
|
18
|
+
_SUPPORTED_BUILT_IN_FEATURES: ClassVar[list[str]] = SupportedBuiltInFeatures.get_supported_built_in_features()
|
|
19
|
+
|
|
20
|
+
def __post_init__(self) -> None:
|
|
21
|
+
self._ensure_template_is_supported()
|
|
22
|
+
self._ensure_built_in_features_are_supported()
|
|
23
|
+
self._ensure_bounded_context_is_only_applicable_for_ddd_template()
|
|
24
|
+
self._ensure_bounded_context_is_set_if_specified()
|
|
25
|
+
|
|
26
|
+
def _ensure_template_is_supported(self) -> None:
|
|
27
|
+
if self.name not in self._SUPPORTED_TEMPLATES:
|
|
28
|
+
raise InvalidTemplateValue(self.name, self._SUPPORTED_TEMPLATES)
|
|
29
|
+
|
|
30
|
+
def _ensure_built_in_features_are_supported(self) -> None:
|
|
31
|
+
unsupported_features = [
|
|
32
|
+
feature for feature in self.built_in_features if feature not in self._SUPPORTED_BUILT_IN_FEATURES
|
|
33
|
+
]
|
|
34
|
+
if unsupported_features:
|
|
35
|
+
raise InvalidBuiltInFeaturesValues(unsupported_features, self._SUPPORTED_BUILT_IN_FEATURES)
|
|
36
|
+
|
|
37
|
+
def _ensure_bounded_context_is_only_applicable_for_ddd_template(self) -> None:
|
|
38
|
+
if (
|
|
39
|
+
self.specify_bounded_context or self.bounded_context or self.aggregate_name
|
|
40
|
+
) and self.name != SupportedTemplates.DDD:
|
|
41
|
+
raise BoundedContextNotApplicable(self.name)
|
|
42
|
+
|
|
43
|
+
def _ensure_bounded_context_is_set_if_specified(self) -> None:
|
|
44
|
+
if self.specify_bounded_context and (not self.bounded_context or not self.aggregate_name):
|
|
45
|
+
raise BoundedContextNotSpecified()
|
|
46
|
+
|
|
47
|
+
def to_primitives(self) -> dict[str, Union[str, list[str]]]:
|
|
48
|
+
return asdict(self)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class BoundedContextNotApplicable(ApplicationError):
|
|
52
|
+
def __init__(self, value: str) -> None:
|
|
53
|
+
super().__init__(
|
|
54
|
+
message=f"Bounded context feature is not applicable for template '{value}'. Is only applicable for 'domain_driven_design' template."
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class BoundedContextNotSpecified(ApplicationError):
|
|
59
|
+
def __init__(self) -> None:
|
|
60
|
+
super().__init__(
|
|
61
|
+
message="Option to specify bounded context is set as True, but either bounded context or aggregate name is not specified."
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class InvalidBuiltInFeaturesValues(ApplicationError):
|
|
66
|
+
def __init__(self, values: list[str], supported_values: list[str]) -> None:
|
|
67
|
+
super().__init__(
|
|
68
|
+
message=f"Features {', '.join(values)} are not supported. Supported features are: {', '.join(supported_values)}."
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class InvalidTemplateValue(ApplicationError):
|
|
73
|
+
def __init__(self, value: str, supported_values: list[str]) -> None:
|
|
74
|
+
super().__init__(
|
|
75
|
+
message=f"Invalid template: '{value}'. Supported templates are: {', '.join(supported_values)}."
|
|
76
|
+
)
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
import yaml
|
|
5
|
+
|
|
6
|
+
from instant_python.shared.domain.config_schema import ConfigSchema
|
|
7
|
+
from instant_python.shared.domain.config_repository import ConfigRepository
|
|
8
|
+
from instant_python.shared.application_error import ApplicationError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class YamlConfigRepository(ConfigRepository):
|
|
12
|
+
def write(self, config: ConfigSchema) -> None:
|
|
13
|
+
destination_path = config.config_file_path
|
|
14
|
+
with destination_path.open("w") as file:
|
|
15
|
+
yaml.dump(config.to_primitives(), file)
|
|
16
|
+
|
|
17
|
+
def read(self, path: Path) -> ConfigSchema:
|
|
18
|
+
try:
|
|
19
|
+
with path.open("r") as file:
|
|
20
|
+
raw_config = yaml.safe_load(file)
|
|
21
|
+
return ConfigSchema.from_primitives(content=raw_config, custom_config_path=path)
|
|
22
|
+
except FileNotFoundError:
|
|
23
|
+
raise ConfigurationFileNotFound(str(path))
|
|
24
|
+
|
|
25
|
+
def move(self, config: ConfigSchema, base_directory: Path) -> None:
|
|
26
|
+
final_destination = config.calculate_config_destination_path(
|
|
27
|
+
base_directory=base_directory,
|
|
28
|
+
)
|
|
29
|
+
ipy_config_project_folder = final_destination.parent / "ipy.yml"
|
|
30
|
+
shutil.move(config.config_file_path, ipy_config_project_folder)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ConfigurationFileNotFound(ApplicationError):
|
|
34
|
+
def __init__(self, path: str) -> None:
|
|
35
|
+
super().__init__(
|
|
36
|
+
message=f"Configuration file not found at '{path}'. To create a project, you first"
|
|
37
|
+
f" need a configuration file. Please, run 'ipy config' command to create one.\n"
|
|
38
|
+
f"If you have the configuration file in another location, use the '-c' flag.",
|
|
39
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SupportedBuiltInFeatures(str, Enum):
|
|
5
|
+
VALUE_OBJECTS = "value_objects"
|
|
6
|
+
GITHUB_ACTIONS = "github_actions"
|
|
7
|
+
GITHUB_ISSUES_TEMPLATE = "github_issues_template"
|
|
8
|
+
MAKEFILE = "makefile"
|
|
9
|
+
LOGGER = "logger"
|
|
10
|
+
EVENT_BUS = "event_bus"
|
|
11
|
+
ASYNC_SQLALCHEMY = "async_sqlalchemy"
|
|
12
|
+
ASYNC_ALEMBIC = "async_alembic"
|
|
13
|
+
FASTAPI = "fastapi_application"
|
|
14
|
+
PRECOMMIT = "precommit_hook"
|
|
15
|
+
CITATION = "citation_file"
|
|
16
|
+
SECURITY = "security_file"
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def get_supported_built_in_features(cls) -> list[str]:
|
|
20
|
+
return [feature.value for feature in cls]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SupportedPythonVersions(str, Enum):
|
|
5
|
+
PYTHON_3_10 = "3.10"
|
|
6
|
+
PYTHON_3_11 = "3.11"
|
|
7
|
+
PYTHON_3_12 = "3.12"
|
|
8
|
+
PYTHON_3_13 = "3.13"
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def get_supported_versions(cls) -> list[str]:
|
|
12
|
+
return [version.value for version in cls]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SupportedTemplates(str, Enum):
|
|
5
|
+
DDD = "domain_driven_design"
|
|
6
|
+
CLEAN = "clean_architecture"
|
|
7
|
+
STANDARD = "standard_project"
|
|
8
|
+
CUSTOM = "custom"
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def get_supported_templates(cls) -> list[str]:
|
|
12
|
+
return [template.value for template in cls]
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
116
|
+
.pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
121
|
+
__pypackages__/
|
|
122
|
+
|
|
123
|
+
# Celery stuff
|
|
124
|
+
celerybeat-schedule
|
|
125
|
+
celerybeat.pid
|
|
126
|
+
|
|
127
|
+
# SageMath parsed files
|
|
128
|
+
*.sage.py
|
|
129
|
+
|
|
130
|
+
# Environments
|
|
131
|
+
.env
|
|
132
|
+
.venv
|
|
133
|
+
env/
|
|
134
|
+
venv/
|
|
135
|
+
ENV/
|
|
136
|
+
env.bak/
|
|
137
|
+
venv.bak/
|
|
138
|
+
|
|
139
|
+
# Spyder project settings
|
|
140
|
+
.spyderproject
|
|
141
|
+
.spyproject
|
|
142
|
+
|
|
143
|
+
# Rope project settings
|
|
144
|
+
.ropeproject
|
|
145
|
+
|
|
146
|
+
# mkdocs documentation
|
|
147
|
+
/site
|
|
148
|
+
|
|
149
|
+
# mypy
|
|
150
|
+
.mypy_cache/
|
|
151
|
+
.dmypy.json
|
|
152
|
+
dmypy.json
|
|
153
|
+
|
|
154
|
+
# Pyre type checker
|
|
155
|
+
.pyre/
|
|
156
|
+
|
|
157
|
+
# pytype static type analyzer
|
|
158
|
+
.pytype/
|
|
159
|
+
|
|
160
|
+
# Cython debug symbols
|
|
161
|
+
cython_debug/
|
|
162
|
+
|
|
163
|
+
# PyPI configuration file
|
|
164
|
+
.pypirc
|