Pack python project as debian package
To pack python as debian package i found two method that work
- using stdeb
- Build manual
In both of the method i use debuild util
Create Minimal python project and create debian package from it
First step: Python project
Create python project struct - venv - setup.py - project module - register the project in the venv
| my_python_app/app.py | |
|---|---|
Step2: using stdeb
The command create deb_dist folder under application root
copy postinst and other scripts from project debian to deb_dist/<application name> folder
| build deb | |
|---|---|
Check deb file
using dpkg -I to get package info and the for script existing
dpkg -eto extract control script from deb file to target folderdpkg -xextract all deb files.
Step2a: Manual create Debian
TODO: finish
Create debian folder with this files
- debian/control
- debian/rules
- debian/changelog
- debian/postinst (optional)
- debian/postrm (optional)
control
rules
executable permission
changelog
Format
| template | |
|---|---|
| example | |
|---|---|
my-python-app (1.0-1) unstable; urgency=medium - package name: my-python-app - version: (1.0-1) - 1.0: upstream (code version) - -1: Debian version (change in the rules and control files) - distribution: - unstable → Default for new packages. - stable → For official stable releases. - testing → For testing before stable. - experimental → For experimental features. - urgency: - low → No hurry. - medium → Normal (default). - high → Important security fixes. - emergency → Critical fixes, immediate attention.
compat
postinst
postrm
Step3: build the package
deb files
The deb file create in the parent folder
Step4: Add user input during installation
TODO
debian/changelog?
The debian/changelog file is a required part of a Debian package. It’s a human-readable log of changes made to the package across its versions. It follows a specific format and is used by tools like dpkg and apt to display package history and determine version ordering. It’s also critical for maintaining a package in a Debian repository. Format of debian/changelog
-
First Line: my-python-app: Package name. (0.1-1): Version (explained below). unstable: Target distribution (e.g., unstable, stable, or a codename like bookworm). urgency=medium: Priority of the update (e.g., low, medium, high, critical).
-
Change List: Bullet points (*) describing what changed in this version.
- Signature Line: Author’s name, email, and timestamp.
What is dch?
dch (Debian CHangelog) is a command-line tool from the devscripts package that simplifies editing debian/changelog. It helps you:
- Create a new changelog file.
- Add new version entries.
- Update timestamps and metadata.
Create a New Changelog:
Edit Manually:
Versioning: What Does -[number] Mean?
The version in debian/changelog (e.g., 0.1-1) follows Debian’s versioning scheme: [upstream_version]-[debian_revision].
- Upstream Version (0.1): This is the version of your software (e.g., from setup.py in your Python project). You increment this when you make changes to the actual code (e.g., 0.1 to 0.2 for a new feature).
- Debian Revision (-1): This is the packaging version, incremented when you change the Debian packaging (e.g., fix a bug in debian/rules or postinst) without changing the upstream code. Example: If you release 0.1-1 and later fix a packaging issue, the next version would be 0.1-2.
Rules for the - and Number
1 2 3 4 | |
Examples
1 2 3 | |
Git and debian package
- --release: Marks this as a full release.
- --auto: Generates entries from commit messages since the last tag.
- --git-author: Uses Git commit authors in the changelog.