builder

Build-step functions for Lambda source deployment artifacts.

Each function installs the current Python package into a caller-supplied target directory (dir_lambda_source_build) using a different tool:

All three functions are intentionally thin: they accept plain Path arguments rather than a SourcePathLayout object so that the build logic stays decoupled from any particular path convention. Callers that use SourcePathLayout pass path_layout.dir_build / path_layout.path_source_zip as arguments.

Key assumptions

  • The Lambda entry point lives inside the installed package, not as a separate file outside it.

  • Only pyproject.toml-based projects are supported (setup.py is not).

  • The build backend configured in [build-system] (typically setuptools) controls which packages and data files are included; packages.find / package-data settings in pyproject.toml are fully respected.

  • zip (the system binary) must be available on PATH for create_source_zip().

aws_lbd_art_builder_core.source.builder.build_source_dir_using_pip(path_bin_pip: ~pathlib.Path, path_pyproject_toml: ~pathlib.Path, dir_lambda_source_build: ~pathlib.Path, skip_prompt: bool = False, verbose: bool = True, printer: ~typing.Callable[[str], None] = <built-in function print>)[source]

Install the current Python package into a target directory using pip.

Why pip install instead of copying files? pip resolves package metadata, entry points, and import paths exactly as the Lambda runtime expects. Plain file copying can silently break relative imports or miss *.dist-info records that some libraries rely on at runtime.

temp_cwd is intentionally not used here: path_pyproject_toml is always an absolute path so pip does not need a specific working directory to locate the project.

The build directory is cleaned before installation to guarantee a reproducible, artefact-free starting state.

Parameters:
  • path_bin_pip – pip executable, e.g. /path/to/.venv/bin/pip

  • path_pyproject_tomlpyproject.toml of the project to install. Its parent directory is passed to pip install as the source.

  • dir_lambda_source_build – Target directory for the installed files, i.e. dir_build.

  • skip_prompt – When True, wipe the build directory without asking for confirmation.

  • verbose – When True, print the pip command and its output.

  • printer – Callable used for log output (default: print()).

aws_lbd_art_builder_core.source.builder.build_source_dir_using_uv(path_bin_uv: ~pathlib.Path, path_pyproject_toml: ~pathlib.Path, dir_lambda_source_build: ~pathlib.Path, skip_prompt: bool = False, verbose: bool = True, printer: ~typing.Callable[[str], None] = <built-in function print>)[source]

Install the current Python package into a target directory using uv.

uv pip install has its own wheel installer and does not require pip to be present in the virtual environment. It is otherwise equivalent to pip install --no-deps --target but noticeably faster.

temp_cwd is intentionally not used: the project directory is passed as an explicit absolute path argument to uv, so the working directory is irrelevant.

setup.py-only projects are not supported; the project must have a pyproject.toml with a [build-system] table.

The build directory is cleaned before installation to guarantee a reproducible, artefact-free starting state.

Parameters:
  • path_bin_uv – uv executable, e.g. /path/to/.venv/bin/uv or the system-wide uv resolved via shutil.which().

  • path_pyproject_tomlpyproject.toml of the project to install. Its parent directory is passed to uv pip install as the source.

  • dir_lambda_source_build – Target directory for the installed files, i.e. dir_build.

  • skip_prompt – When True, wipe the build directory without asking for confirmation.

  • verbose – When True, print the uv command and its output.

  • printer – Callable used for log output (default: print()).

aws_lbd_art_builder_core.source.builder.create_source_zip(dir_lambda_source_build: ~pathlib.Path, path_source_zip: ~pathlib.Path, verbose: bool = True, printer: ~typing.Callable[[str], None] = <built-in function print>) str[source]

Zip the Lambda source build directory and return its SHA256 hash.

The zip is created with maximum compression (-9) and its root entries are the direct children of dir_lambda_source_build, so that the Lambda runtime can import them without any extra path prefix.

path_source_zip must not be inside dir_lambda_source_build. Place it at path_source_zip (a sibling of the build directory) to avoid the zip accidentally archiving itself mid-creation.

temp_cwd is required here: glob.glob() is CWD-relative and the zip command must run from inside dir_lambda_source_build so that archive entries carry relative (not absolute) paths.

The SHA256 is computed over the build directory (not the zip file) so that the hash is stable regardless of zip metadata or timestamps.

Parameters:
  • dir_lambda_source_build – Directory containing the installed package files, i.e. dir_build.

  • path_source_zip – Output path for the zip archive, i.e. path_source_zip.

  • verbose – When True, print progress and the computed hash.

  • printer – Callable used for log output (default: print()).

Returns:

SHA256 hex digest of the source build directory.