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:
build_source_dir_using_pip()—pip install --no-dependencies --targetbuild_source_dir_using_uv()—uv pip install --no-deps --targetcreate_source_zip()— zip the build dir and return its SHA256
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.pyis not).The build backend configured in
[build-system](typically setuptools) controls which packages and data files are included;packages.find/package-datasettings inpyproject.tomlare fully respected.zip(the system binary) must be available onPATHforcreate_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-inforecords that some libraries rely on at runtime.temp_cwdis intentionally not used here:path_pyproject_tomlis 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/pippath_pyproject_toml –
pyproject.tomlof the project to install. Its parent directory is passed topip installas 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 installhas its own wheel installer and does not require pip to be present in the virtual environment. It is otherwise equivalent topip install --no-deps --targetbut noticeably faster.temp_cwdis 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 apyproject.tomlwith 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/uvor the system-wide uv resolved viashutil.which().path_pyproject_toml –
pyproject.tomlof the project to install. Its parent directory is passed touv pip installas 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_zipmust not be inside dir_lambda_source_build. Place it atpath_source_zip(a sibling of the build directory) to avoid the zip accidentally archiving itself mid-creation.temp_cwdis required here:glob.glob()is CWD-relative and thezipcommand 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.