Build a wheel from a GitHub repository¶
Sometimes the version of a package you need is on GitHub but not on PyPI: a
fix on the main branch, a fork, or a project that rarely publishes a release.
kivyforge installs only wheels, so it refuses a source URL such as
kivymd @ https://github.com/.../master.zip or a git+https:// URL at lock
time. Instead, use pip to build a wheel from the repository once, keep it in
your project, and lock it like any other package. This page uses KivyMD's
master branch as the example.
The lock pins the wheel by its path and SHA-256 hash, so every build installs exactly the wheel you built, not whatever the branch holds that day.
Before you begin¶
- A project with an overlay for each target you build. See Project configuration.
- Python with pip on your development machine. Any version that can build the package works. It does not need to match your app's Python.
- Git on your
PATH, to build from agit+https://URL. Without Git, build from an archive URL instead. See Build without Git. - A pure-Python package. pip builds the wheel for the machine it runs on. A pure-Python wheel works on every target. A package with compiled code gives you a wheel for your development machine only, which an Android or iOS app can't use. See Prebuilt runtimes and wheels. For Kivy itself, see Package your app with a Kivy development build.
Build the wheel¶
-
From your project's root directory, build the wheel into
wheels/:python -m pip wheel --no-deps --wheel-dir wheels git+https://github.com/kivymd/KivyMD.gitpip clones the repository, builds a wheel from its packaging configuration, and writes the wheel to
wheels/.--no-depsbuilds only KivyMD. Its dependencies come from your indexes when you lock.To build one commit, tag, or branch, add it after
@:python -m pip wheel --no-deps --wheel-dir wheels "git+https://github.com/kivymd/KivyMD.git@COMMIT_SHA"Replace
COMMIT_SHAwith the full commit hash, a tag, or a branch name. A commit hash lets you rebuild the same code later. -
Check the wheel's filename:
wheels/kivymd-2.0.1.dev0-py3-none-any.whlThe filename gives the version,
2.0.1.dev0, and the tagpy3-none-any, which means the wheel is pure Python. If the tag names a platform, such aswin_amd64ormacosx_14_0_arm64, the package has compiled code and the wheel works only on that platform.The version comes from the repository's source. Every commit on KivyMD's
masterbuilds as2.0.1.dev0until KivyMD changes it.
Build without Git¶
GitHub serves every commit, tag, and branch as a .zip archive. pip can build
a wheel from the archive without Git:
python -m pip wheel --no-deps --wheel-dir wheels https://github.com/kivymd/KivyMD/archive/COMMIT_SHA.zip
Replace COMMIT_SHA with a commit hash, a tag, or a branch name.
The wheel has the same code. A package that records its Git commit at build
time can't find it in an archive. KivyMD stores "Unknown" in
kivymd._version.__hash__ instead of the commit hash.
Lock the wheel¶
-
Depend on the package by name and exact version, not by URL:
[project] dependencies = [ "kivy", "kivymd==2.0.1.dev0", ]2.0.1.dev0is a pre-release, so the specifier has to name it. With==,locktakes that version and no other. -
List the wheel directory in
find_linksin each target's overlay:[tool.kivy.android] find_links = ["wheels"] [tool.kivy.windows] find_links = ["wheels"]A package with a wheel in
find_linkscomes only from there, so a newer KivyMD release on PyPI doesn't replace your wheel. See Use your own wheels. -
Make sure every dependency of the package has a wheel for each target.
lockresolves KivyMD's dependencies from your indexes, the same way it resolves your own. On Android,pycairoandpillowhave no wheel, so exclude them:[tool.kivy.android] exclude = [ # keep the entries that `kivyforge init` seeded "pycairo", # only KivyMD's MDLoadingIndicator uses it "pillow", ]Excluding a package removes it from the app. Your app fails if it uses the feature that needs the package. With
pycairoexcluded, don't use KivyMD'sMDLoadingIndicator. -
Lock each target:
kivyforge lock -p android kivyforge lock -p windows -
Commit
wheels/together with the lockfiles.buildinstalls the wheel from the path the lock records.
Warning
Don't rebuild the wheel on another machine or in CI. Two builds of the
same commit usually have different hashes. A rebuilt wheel no longer
matches the lock, and build fails with a hash mismatch. Commit the wheel
you locked.
Update to a newer commit¶
- Delete the old wheel from
wheels/. - Build the new commit, as in Build the wheel.
- If the version changed, update the
==specifier in[project].dependencies. -
Re-lock each target:
kivyforge lock -p androidlocksees that the wheel changed, names it, and resolves KivyMD again. Every other package keeps its locked version.
Verify¶
-
Check that the lock pins your wheel by path and hash. In
pylock.android.toml, thekivymdentry looks like this:[[packages.wheels]] name = "kivymd-2.0.1.dev0-py3-none-any.whl" path = "wheels/kivymd-2.0.1.dev0-py3-none-any.whl" hashes = { sha256 = "..." }A
pathinstead of aurlmeans the package comes from your wheel. -
Check that the lock still matches the wheel on disk:
kivyforge lock -p android --checkThe command exits
0. If you replaced the wheel since you locked, it exits4and names the wheel that changed. -
Build the app:
kivyforge build -p androidbuildverifies the wheel's hash before it installs it.
To confirm which commit is in the running app, read the version module KivyMD generates when it builds from Git:
from kivymd import _version
print(_version.__version__, _version.__hash__)