runway.cfngin.hooks.awslambda.python_requirements package

Handle python requirements.

class runway.cfngin.hooks.awslambda.python_requirements.PythonDeploymentPackage[source]

Bases: DeploymentPackage[PythonProject]

AWS Lambda Python Deployment Package.

property gitignore_filter: IgnoreParser | None

Filter to use when zipping dependencies.

This should be overridden by subclasses if a filter should be used.

static insert_layer_dir(file_path: Path, relative_to: Path) Path[source]

Insert python directory into local file path for layer archive.

Parameters:
  • file_path – Path to local file.

  • relative_to – Path to a directory that the file_path will be relative to in the deployment package.

project: PythonProject

Project that is being built into a deployment package.

class runway.cfngin.hooks.awslambda.python_requirements.PythonDockerDependencyInstaller[source]

Bases: DockerDependencyInstaller

Docker dependency installer for Python.

__init__(project: PythonProject, *, client: DockerClient | None = None, context: CfnginContext | RunwayContext | None = None) None[source]

Instantiate class.

Parameters:
  • project – awslambda project.

  • client – Pre-configured docker.client.DockerClient.

  • context – CFNgin or Runway context object.

property bind_mounts: list[Mount]

Bind mounts that will be used by the container.

property environment_variables: dict[str, str]

Environment variables to pass to the docker container.

This is a subset of the environment variables stored in the context object as some will cause issues if they are passed.

property install_commands: list[str]

Commands to run to install dependencies.

property python_version: Version | None

Version of Python installed in the docker container.

property runtime: str | None

AWS Lambda runtime determined from the docker container’s Python version.

class runway.cfngin.hooks.awslambda.python_requirements.PythonProject[source]

Bases: Project[PythonHookArgs]

Python project.

DEFAULT_CACHE_DIR_NAME: ClassVar[str] = 'pip_cache'

Name of the default cache directory.

cleanup() None[source]

Cleanup temporary files after the build process has run.

property docker: PythonDockerDependencyInstaller | None

Docker interface that can be used to build the project.

install_dependencies() None[source]

Install project dependencies.

property metadata_files: tuple[Path, ...]

Project metadata files.

Files are only included in return value if they exist.

property pip: Pip

Pip dependency manager.

property pipenv: Pipenv | None

Pipenv dependency manager.

Returns:

If the project uses pipenv and pipenv is not explicitly disabled, an object for interfacing with pipenv will be returned.

Raises:

PipenvNotFoundError – pipenv is not installed or not found in PATH.

property poetry: Poetry | None

Poetry dependency manager.

Returns:

If the project uses poetry and poetry is not explicitly disabled, an object for interfacing with poetry will be returned.

Raises:

PoetryNotFound – poetry is not installed or not found in PATH.

property project_type: Literal['pip', 'pipenv', 'poetry']

Type of python project.

property requirements_txt: Path | None

Dependency file for the project.

property runtime: str

Runtime of the build system.

Value should be a valid Lambda Function runtime (https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).

property supported_metadata_files: set[str]

Names of all supported metadata files.

Returns:

Set of file names - not paths.

property tmp_requirements_txt: Path

Temporary requirements.txt file.

This path is only used when exporting from another format.