Build Process for OpenMed: Complete Packaging and Distribution Guide
The OpenMed build process uses Hatchling as the build backend and a Makefile to automate the creation of source distributions and wheels via python3 -m build, with optional publishing to PyPI through hatch publish.
OpenMed is a Python package managed in the maziyarpanahi/openmed repository that adheres to modern Python packaging standards. The build process for OpenMed relies on Hatchling as the build backend, orchestrated through a convenient Makefile that handles everything from environment setup to PyPI publication.
Prerequisites and Environment Setup
Before building OpenMed, ensure you have Python 3.10 or higher installed. The project recommends using the uv package manager for fast, reproducible environment management.
-
Install
uvif you haven't already:pip install uv -
Create a clean virtual environment:
uv venv source .venv/bin/activate -
Install build-time dependencies:
uv pip install hatchling build
Build System Configuration
The build configuration resides in pyproject.toml at the repository root. According to the OpenMed source code, the file declares hatchling as the build backend:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Version tracking is handled dynamically. Hatch reads the version from openmed/__about__.py as specified in the pyproject.toml:
[tool.hatch.version]
path = "openmed/__about__.py"
Building the Package
The Makefile provides the primary interface for building. To create both a source distribution (.tar.gz) and a wheel (.whl), run:
make build
This command invokes python3 -m build, which generates the distribution artifacts in the dist/ directory. You can verify the output:
ls dist/
# ├── openmed-0.1.0-py3-none-any.whl
# └── openmed-0.1.0.tar.gz
Alternatively, you can run the build command directly without Make:
python3 -m build
Makefile Targets and Build Automation
The Makefile in the repository root defines several targets that streamline the build process for OpenMed:
make build– Executespython3 -m buildto generate distribution filesmake clean– Removesdist/,build/, and*.egg-info/directoriesmake publish– Callshatch publishto upload artifacts to PyPImake release– Chainsclean,build, andpublishfor a full release cycle
The relevant Makefile definitions are:
build: ## Build the package
@echo "🔨 Building package..."
python3 -m build
publish: ## Publish to PyPI using Hatch
@echo "📤 Publishing to PyPI..."
hatch publish
release: clean build publish ## Full release cycle: clean, build, publish
clean: ## Clean build artifacts
@echo "🧹 Cleaning build artifacts..."
rm -rf dist/ build/ *.egg-info/
Publishing to PyPI
To publish a release, ensure you have built the package first and have PyPI credentials configured in ~/.pypirc. The make publish target wraps the Hatch publishing command:
make publish
For a complete release workflow that includes cleaning old artifacts, building fresh ones, and publishing, use:
make release
This executes the full pipeline: clean → build → publish.
Documentation Build
OpenMed uses MkDocs for documentation. The Makefile includes helpers for building and serving documentation locally:
make docs-serve– Runsuv run mkdocs serve -a 127.0.0.1:8008for live previewmake docs-build– Runsuv run mkdocs build --strictto generate static files
These commands rely on the docs extra defined in pyproject.toml, which includes mkdocs and mkdocs-material.
Key Files in the Build Process
Understanding these files helps when modifying the build process for OpenMed:
pyproject.toml– Declares thehatchling.buildbackend, dependencies, and version pathopenmed/__about__.py– Stores the current version string read by Hatch during buildsMakefile– Provides thebuild,publish,release, andcleanautomation targetsscripts/release/release.py– Helper script for version bumping invoked by Makefile targets
Summary
- Build backend: OpenMed uses
hatchlingas specified inpyproject.tomlwith thehatchling.buildbackend - Build command: Run
make buildorpython3 -m buildto generate wheels and source distributions indist/ - Version location: The version is defined in
openmed/__about__.pyand read dynamically by Hatch - Publishing: Use
make publish(which callshatch publish) ormake releasefor the full cycle - Documentation: Build docs with
make docs-buildor preview withmake docs-serve
Frequently Asked Questions
What build backend does OpenMed use?
OpenMed uses Hatchling as its build backend. The configuration in pyproject.toml specifies build-backend = "hatchling.build" and uses Hatch's versioning system to read from openmed/__about__.py.
How do I build OpenMed from source without Make?
If you prefer not to use the Makefile, activate your virtual environment and run python3 -m build directly. This requires the build package to be installed (pip install build). The command creates both the wheel and source distribution in the dist/ directory.
Where does OpenMed store its version number?
The package version is stored in openmed/__about__.py. Hatch reads this file dynamically during the build process according to the [tool.hatch.version] configuration in pyproject.toml, eliminating the need to hardcode versions in multiple locations.
How do I publish a new release to PyPI?
Run make release from the repository root. This executes the full pipeline: cleaning old artifacts, building fresh distributions with python3 -m build, and publishing to PyPI via hatch publish. Ensure you have PyPI credentials configured in ~/.pypirc or set as environment variables.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →