Principle:Langchain ai Langchain Distribution Building
Overview
Distribution Building is the process of compiling a Python package's source code and metadata into standardized distribution artifacts (wheel and sdist) suitable for upload to a package index.
Description
Python packages are distributed in two primary formats:
- Wheel (
.whl) -- A pre-built binary distribution format that installs quickly because it does not require a build step on the consumer's machine. - Source distribution (
.tar.gz/ sdist) -- A compressed archive of the source tree that allows the consumer to build the package locally.
The build step reads the project metadata (name, version, dependencies) from the package's configuration file and produces these artifacts in a dist/ directory. In a CI pipeline, the build step is intentionally isolated from the publish step so that the build environment never has access to publishing credentials. This separation is a security best practice recommended by PyPI's trusted publishing documentation.
After building, the CI pipeline typically extracts the package name and version from the metadata for use by downstream jobs (tagging, release notes, publishing).
Usage
Use distribution building when:
- Preparing a release for upload to PyPI or Test PyPI.
- Creating artifacts for local testing or validation before a release.
- Generating wheels for consumption by dependent packages in the same monorepo.
Practical Guide
1. Navigate to the target package directory.
2. Run the build command to produce .whl and .tar.gz in dist/.
3. Upload the artifacts for downstream consumption (CI artifact store or direct use).
4. Extract package name and version from the metadata for downstream jobs.
Pseudocode:
cd package_directory
build_tool build # produces dist/*.whl and dist/*.tar.gz
# Extract metadata
metadata = read_project_metadata("pyproject.toml")
pkg_name = metadata["project"]["name"]
version = metadata["project"]["version"]
upload_artifacts("dist/", name="dist")
set_output("pkg-name", pkg_name)
set_output("version", version)