diff --git a/src/kegstandcli/cli/config.py b/src/kegstandcli/cli/config.py index 5071512..1b603ff 100644 --- a/src/kegstandcli/cli/config.py +++ b/src/kegstandcli/cli/config.py @@ -35,7 +35,7 @@ def find_config_file(verbose: bool, config_file: str | None) -> str | None: # n return config_file -def get_kegstand_config(verbose: bool, project_dir: str, config_file: str) -> dict[str, Any]: +def get_kegstand_config(verbose: bool, project_dir: str, config_file: str) -> dict[str, Any]: # noqa: PLR0912 """Load and parse the Kegstand configuration. Args: @@ -58,15 +58,23 @@ def get_kegstand_config(verbose: bool, project_dir: str, config_file: str) -> di # If the config file is pyproject.toml, the config will be under the 'tool.kegstand' key if config_file.endswith("pyproject.toml"): config = parsed_toml_config.get("tool", {}).get("kegstand", {}) - # Some keys are used from the [project] section if not specified in [tool.kegstand] + # Some keys are used from the [project] or [tool.poetry] section + # if not specified in [tool.kegstand] properties_from_pyproject = ["name", "description", "version"] if "project" not in config: config["project"] = {} for property_name in properties_from_pyproject: if property_name not in config["project"]: - config["project"][property_name] = parsed_toml_config.get("project", {}).get( - property_name - ) + # Try to get the property from the [project] section + if property_name in parsed_toml_config.get("project", {}): + config["project"][property_name] = parsed_toml_config.get("project", {}).get( + property_name + ) + # Try to get the property from the [tool.poetry] section + elif property_name in parsed_toml_config.get("tool", {}).get("poetry", {}): + config["project"][property_name] = ( + parsed_toml_config.get("tool", {}).get("poetry", {}).get(property_name) + ) else: config = parsed_toml_config @@ -81,7 +89,9 @@ def get_kegstand_config(verbose: bool, project_dir: str, config_file: str) -> di config["config_file"] = str(config_path) # Set defaults where missing - config_defaults = {"api": {"name": "Untitled API", "entrypoint": "api.lambda.handler"}} + config_defaults = { + "api": {"name": "Untitled API", "entrypoint": "api.lambda.handler", "runtime": "python3.13"} + } for section, defaults in config_defaults.items(): if section not in config: config[section] = {} diff --git a/src/kegstandcli/infra/stacks/rest_api_backend.py b/src/kegstandcli/infra/stacks/rest_api_backend.py index 87026a1..d9c50ed 100644 --- a/src/kegstandcli/infra/stacks/rest_api_backend.py +++ b/src/kegstandcli/infra/stacks/rest_api_backend.py @@ -10,7 +10,7 @@ from aws_cdk import aws_lambda as lambda_ from constructs import Construct -from kegstandcli.utils import find_resource_modules +from kegstandcli.utils import LambdaRuntime, find_resource_modules MODULE_CONFIG_KEY = "api" @@ -66,7 +66,7 @@ def __init__( self, f"{construct_id}-Backend", function_name=f"{construct_id}-Function", - runtime=lambda_.Runtime.PYTHON_3_9, + runtime=LambdaRuntime(config[MODULE_CONFIG_KEY]["runtime"]).to_lambda_runtime(), handler=config[MODULE_CONFIG_KEY]["entrypoint"], code=lambda_.Code.from_asset(str(api_src_path)), layers=[ # See Lambda Powertools: https://awslabs.github.io/aws-lambda-powertools-python/2.4.0/ diff --git a/src/kegstandcli/utils.py b/src/kegstandcli/utils.py index d7432b3..cb74263 100644 --- a/src/kegstandcli/utils.py +++ b/src/kegstandcli/utils.py @@ -5,6 +5,7 @@ from typing import Any import click +from aws_cdk import aws_lambda as lambda_ from tomlkit import loads as parse_toml @@ -18,6 +19,26 @@ def __str__(self) -> str: return self.value +class LambdaRuntime(str, PythonEnum): + """Lambda runtime types.""" + + PYTHON_3_10 = "python3.10" + PYTHON_3_11 = "python3.11" + PYTHON_3_12 = "python3.12" + PYTHON_3_13 = "python3.13" + + def __str__(self) -> str: + return self.value + + def to_lambda_runtime(self) -> lambda_.Runtime: + return { + LambdaRuntime.PYTHON_3_10: lambda_.Runtime.PYTHON_3_10, + LambdaRuntime.PYTHON_3_11: lambda_.Runtime.PYTHON_3_11, + LambdaRuntime.PYTHON_3_12: lambda_.Runtime.PYTHON_3_12, + LambdaRuntime.PYTHON_3_13: lambda_.Runtime.PYTHON_3_13, + }[self] + + def find_resource_modules(api_src_dir: str) -> list[dict[str, Any]]: """Find API resource modules in the source directory. diff --git a/uv.lock b/uv.lock index 19137cf..a578909 100644 --- a/uv.lock +++ b/uv.lock @@ -446,7 +446,7 @@ wheels = [ [[package]] name = "kegstandcli" -version = "0.4.0" +version = "0.4.1" source = { editable = "." } dependencies = [ { name = "aws-cdk-lib" },