poetryinstall

package module
v0.3.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

Poetry Install Cloud Native Buildpack

gcr.io/paketo-buildpacks/poetry-install

The Paketo Buildpack for Poetry Install is a Cloud Native Buildpack that installs packages using Poetry and makes the installed packages available to the application.

The buildpack is published for consumption at gcr.io/paketo-buildpacks/poetry-install and paketobuildpacks/poetry-install.

Behavior

This buildpack participates if pyproject.toml exists at the root the app.

The buildpack will do the following:

  • At build time:
    • Creates a virtual environment, installs the application packages to it, and makes this virtual environment available to the app via a layer called poetry-venv.
    • Configures poetry to locate this virtual environment via the environment variable POETRY_VIRTUAL_ENVS_PATH.
    • Prepends the layer poetry-venv onto PYTHONPATH.
    • Prepends the bin directory of the poetry-venv layer to the PATH environment variable.
  • At run time:
    • Does nothing

Integration

The Poetry Install CNB provides poetry-venv as a dependency. Downstream buildpacks can require the poetry-venv dependency by generating a Build Plan TOML file that looks like the following:

[[requires]]

  # The name of the dependency provided by the Poetry Install Buildpack is
  # "poetry-venv". This value is considered part of the public API for the
  # buildpack and will not change without a plan for deprecation.
  name = "poetry-venv"

  # The Poetry Install buildpack supports some non-required metadata options.
  [requires.metadata]

    # Setting the build flag to true will ensure that the poetry-venv
    # dependency is available on the $PYTHONPATH for subsequent
    # buildpacks during their build phase. If you are writing a buildpack that
    # needs poetry-venv during its build process, this flag should be
    # set to true.
    build = true

    # Setting the launch flag to true will ensure that the poetry-venv
    # dependency is available on the $PYTHONPATH for the running
    # application. If you are writing an application that needs poetry-venv
    # at runtime, this flag should be set to true.
    launch = true

Usage

To package this buildpack for consumption:

$ ./scripts/package.sh --version x.x.x

This will create a buildpackage.cnb file under the build directory which you can use to build your app as follows: pack build <app-name> -p <path-to-app> -b <cpython buildpack> -b <poetry buildpack> -b build/buildpackage.cnb -b <other-buildpacks..>.

To run the unit and integration tests for this buildpack:

$ ./scripts/unit.sh && ./scripts/integration.sh

Known issues and limitations

  • This buildpack will not work in an offline/air-gapped environment: vendoring of dependencies is not supported. This is a limitation of poetry - which itself does not support vendoring dependencies.

Documentation

Index

Constants

View Source
const CPython = "cpython"

CPython is the name of the python runtime dependency provided by the CPython buildpack: https://github.com/paketo-buildpacks/cpython.

View Source
const CacheLayerName = "cache"

CacheLayerName holds the poetry cache.

View Source
const Poetry = "poetry"

Poetry is the name of the dependency provided by the Poetry buildpack: https://github.com/paketo-buildpacks/poetry.

View Source
const PoetryVenv = "poetry-venv"

PoetryVenv is the name of the dependency provided by the Poetry Install buildpack.

View Source
const VenvLayerName = "poetry-venv"

VenvLayerName is the name of the layer where the venv dependencies are installed to.

Variables

This section is empty.

Functions

func Build

func Build(entryResolver EntryResolver, installProcess InstallProcess, pythonPathProcess PythonPathLookupProcess, sbomGenerator SBOMGenerator, clock chronos.Clock, logger scribe.Emitter) packit.BuildFunc

Build will return a packit.BuildFunc that will be invoked during the build phase of the buildpack lifecycle.

Build will install the poetry dependencies by using the pyproject.toml file to a virtual environment layer.

func Detect

func Detect() packit.DetectFunc

Detect will return a packit.DetectFunc that will be invoked during the detect phase of the buildpack lifecycle.

Detection will contribute a Build Plan that provides poetry-venv, and requires cpython, pip, and poetry at build.

Types

type BuildPlanMetadata

type BuildPlanMetadata struct {
	// Build denotes the dependency is needed at build-time.
	Build bool `toml:"build"`
}

BuildPlanMetadata is the buildpack specific data included in build plan requirements.

type EntryResolver

type EntryResolver interface {
	MergeLayerTypes(name string, entries []packit.BuildpackPlanEntry) (launch, build bool)
}

EntryResolver defines the interface for picking the most relevant entry from the Buildpack Plan entries.

type Executable

type Executable interface {
	Execute(pexec.Execution) error
}

Executable defines the interface for invoking an executable.

type InstallProcess

type InstallProcess interface {
	Execute(workingDir, targetDir, cacheDir string) (string, error)
}

InstallProcess defines the interface for installing the poetry dependencies. It returns the location of the virtual env directory.

type PoetryInstallProcess

type PoetryInstallProcess struct {
	// contains filtered or unexported fields
}

PoetryInstallProcess implements the InstallProcess interface.

func NewPoetryInstallProcess

func NewPoetryInstallProcess(executable Executable, logger scribe.Emitter) PoetryInstallProcess

NewPoetryInstallProcess creates an instance of the PoetryInstallProcess given an Executable.

func (PoetryInstallProcess) Execute

func (p PoetryInstallProcess) Execute(workingDir, targetPath, cachePath string) (string, error)

Execute installs the poetry dependencies from workingDir/pyproject.toml into a virtual env in the targetPath.

type PythonPathLookupProcess

type PythonPathLookupProcess interface {
	Execute(venvDir string) (string, error)
}

PythonPathProcess defines the interface for finding the PYTHONPATH (AKA the site-packages directory)

type PythonPathProcess

type PythonPathProcess struct {
}

PythonPathProcess implements the Executable interface.

func NewPythonPathProcess

func NewPythonPathProcess() PythonPathProcess

NewPythonPathProcess creates an instance of the PythonPathProcess.

func (PythonPathProcess) Execute

func (p PythonPathProcess) Execute(venvDir string) (string, error)

Execute locates the Python path (AKA site-packages directory) within the poetry targetLayerPath.

type SBOMGenerator added in v0.2.0

type SBOMGenerator interface {
	Generate(dir string) (sbom.SBOM, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL