• need help for my first python package

    From Marc Haber@21:1/5 to All on Mon Jun 23 21:40:01 2025
    Hi,

    I am re-working my first Debian package, console-log, which I wrote back
    two decades ago. The rewrite is going to be in python, and I have never packaged python code before. The code is not yet in git.

    What I have:
    .
    ├── debian
    │   ├── changelog
    │   ├── control
    │   ├── copyright
    │   ├── rules
    │   └── source
    │   └── format
    ├── pyproject.toml
    └── src
    ├── console_log
    │   ├── base.py
    │   ├── config.py
    │   ├── __init__.py
    │   └── pagers
    │   ├── __init__.py
    │   └── less.py
    ├── console-log.generator
    └── do_console_log

    console-log.generator will go to
    /usr/lib/systemd/system-generators; do_console_log ends up in /usr/share/console-log. Both programs are not supposed to be called from
    a user. do_console_log imports from console-log/pagers. There will be
    other modules at the side of less.py. I am moving both from debian/console-log.install.

    Google tells me that I am supposed to use dh-python and pyproject. Here
    is what I coughed up:

    [206/6622]mh@swivel:~/packages/console-log/console-log (wip-systemd *+%) $ cat debian/rules
    #!/usr/bin/make -f

    %:
    dh $@ --with python3 --buildsystem=pybuild [207/6622]mh@swivel:~/packages/console-log/console-log (wip-systemd *+%) $ cat pyproject.toml
    [build-system]
    requires = ["setuptools>=61.0", "wheel"]
    build-backend = "setuptools.build_meta"

    [project]
    name = "console-log"
    version = "2.0"
    description = "Console Log - Displays Logs on Virtual Consoles"
    authors = [
    { name = "Marc Haber", email = "mh+debian-packages@zugschlus.de" }
    ]
    license = "GPL-2.0"
    requires-python = ">=3.7"
    dependencies = [
    ]

    [tool.setuptools.packages.find]
    where = ["src"]
    [208/6623]mh@swivel:~/packages/console-log/console-log (wip-systemd *+%) $

    However, building this does not seem to give the desired results:

    (1)
    My package contains /usr/lib/python3/console_log-2.0.dist-info, and
    lintian doesn't like that. How can I preent that from being installed?

    (2)
    Additionally, the package doesn't build twice in a row since .pybuild
    and build directories are generated and not cleaned up on package clean.

    Am I supposed to clean those two directories up in dh_override_auto_clean?

    (3)
    Is it okay to move the two binaries from src/ to the respective
    directories in the package via debian/console-log.install or, how would I
    tell setuptools to install those files to their targets?

    Greetings
    Marc

    -- ----------------------------------------------------------------------------- Marc Haber | "I don't trust Computers. They | Mailadresse im Header Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402 Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Soren Stoutner@21:1/5 to All on Mon Jun 23 12:59:03 2025
    XPost: linux.debian.maint.python

    Marc,

    I am CCing debian-python as that mailing list often fields Python related packaging questions, and you are more likely to get good Python related responses there than debian-mentors.

    Most Python packages are maintained in the Python team namespace, which is a very active team. I would recommend you consider joining the team.

    https://salsa.debian.org/python-team/tools/python-modules/blob/master/ policy.rst

    I don’t really know very much Python, but I have ended up maintaining a lot of
    Python packages, mostly by accident. So, take everything I say here with a grain of salt and I am happy to have anyone on debian-python correct me if I am wrong.

    On Monday, June 23, 2025 12:38:08 PM Mountain Standard Time Marc Haber wrote:
    Hi,

    I am re-working my first Debian package, console-log, which I wrote back
    two decades ago. The rewrite is going to be in python, and I have never packaged python code before. The code is not yet in git.

    What I have:
    .
    ├── debian
    │ ├── changelog
    │ ├── control
    │ ├── copyright
    │ ├── rules
    │ └── source
    │ └── format
    ├── pyproject.toml
    └── src
    ├── console_log
    │ ├── base.py
    │ ├── config.py
    │ ├── __init__.py
    │ └── pagers
    │ ├── __init__.py
    │ └── less.py
    ├── console-log.generator
    └── do_console_log

    console-log.generator will go to
    /usr/lib/systemd/system-generators; do_console_log ends up in /usr/share/console-log. Both programs are not supposed to be called from
    a user. do_console_log imports from console-log/pagers. There will be
    other modules at the side of less.py. I am moving both from debian/console-log.install.

    Google tells me that I am supposed to use dh-python and pyproject. Here
    is what I coughed up:

    [206/6622]mh@swivel:~/packages/console-log/console-log (wip-systemd *+%) $
    cat
    debian/rules #!/usr/bin/make -f

    %:
    dh $@ --with python3 --buildsystem=pybuild

    “--with python3” is considered deprecated syntax, although it still works.
    The replacement is to build-depend on “dh-sequence-python3”. Here is an example:

    https://salsa.debian.org/python-team/packages/python-construct-classes/-/blob/ debian/master/debian/control?ref_type=heads#L7

    [207/6622]mh@swivel:~/packages/console-log/console-log (wip-systemd *+%) $
    cat
    pyproject.toml [build-system]
    requires = ["setuptools>=61.0", "wheel"]
    build-backend = "setuptools.build_meta"

    [project]
    name = "console-log"
    version = "2.0"
    description = "Console Log - Displays Logs on Virtual Consoles"
    authors = [
    { name = "Marc Haber", email = "mh+debian-packages@zugschlus.de" }
    ]
    license = "GPL-2.0"
    requires-python = ">=3.7"
    dependencies = [
    ]

    [tool.setuptools.packages.find]
    where = ["src"]
    [208/6623]mh@swivel:~/packages/console-log/console-log (wip-systemd *+%) $

    However, building this does not seem to give the desired results:

    (1)
    My package contains /usr/lib/python3/console_log-2.0.dist-info, and
    lintian doesn't like that. How can I preent that from being installed?

    Nothing should be installed directly into /usr/lib/python3/. Rather, all your Python modules and dist-info should be installed into /usr/lib/python3/dist- packages.

    (2)
    Additionally, the package doesn't build twice in a row since .pybuild
    and build directories are generated and not cleaned up on package clean.

    Am I supposed to clean those two directories up in dh_override_auto_clean?

    Not typically. I have never had to do that with a Python package. Perhaps there is something you are missing that someone on debian-python can point out.

    From a big picture, if your source package is only building one binary package, you can include the following in debian/rules and a lot of the packaging is automatic:

    export PYBUILD_NAME=package-class-name

    This generates a binary package named python3-package-class-name and puts things in the right place. For example:

    https://salsa.debian.org/python-team/packages/python-construct-classes/-/blob/ debian/master/debian/rules?ref_type=heads#L3

    There are ways to make this work if you have more than one binary package, but I find those things to be a bit complex. In that case, you can leave out the PYBUILD_NAME variable and use debian/*.install files.

    (3)
    Is it okay to move the two binaries from src/ to the respective
    directories in the package via debian/console-log.install or, how would I tell setuptools to install those files to their targets?

    Any way that works is probably fine. In looking at other packages, I have seen it done with debian/*.install or in debian/rules with execute_after_dh_auto_install. Note that if you go the PYBUILD_NAME route I think you need to use debian/rules.

    --
    Soren Stoutner
    soren@debian.org
    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJKVN2yNUZnlcqOI+wufLJ66wtgMFAmhZsgcACgkQwufLJ66w tgNPYRAAg1YSHHdDIUTr0OCdH/9I0hrriQgIIErZ1Z4tmscB9t0XO2OS7rTJ7tJZ yQc/Bb3eXs2tp2/eNPAeJCr5FjE3kMkJCu8R0NVpZoV+JGKsFHuU1VTd01UpA/cE gDu8fS2IuCUPhTcUSkLjKCeynt/0UnC+ZnwH+T5Vt1+oLJolj2F1fCcWysGB91/K ulNwoE+xrruEAjpET3hWIpCmP1cJik8LbN+WkuXRayUhiuxVkUp2XiK7wH7KBe8n HJcppVdZ36ZJIRx5iPQ/8evvhJFSWqIbsAqM77AqCEoGXLrTNyHkI6lFHhkrybid dFof1kjUiekTi/VNdpiy1qfDvCLRqU2mc7XifR2sacVht35Wwm7ZNF4b5kAGTD5T 4AgjVn5g26Df9ytd9GAWx7d4lz2Q79WzkOeXVw1OWu1ugaU7ZkJPhGSjyjmH5UR/ KMktxVatb5dZERN4En+WpqUCg6g6bLd0MqugnK5Kqc7cNr0ZlmawdAUsS45v3Seg IUtUjq+PaYUMbvmpCeGleXcxE0l5NUsA4yQQym+PR/i02Fv+qDhAnRdibhV5vA+6 BGLSTkSPAl9huDkdjIaX8vacyX6LskiyPO+ZclXftiEdBSrtUzA5ZCRgZe9/lUrg iH0bMKtPYTGMCEmhX0wcPPYads/Tgk4LU3iPP1usH5CQ0gyAs58=
    =UrSV
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to Soren Stoutner on Tue Jun 24 10:40:01 2025
    XPost: linux.debian.maint.python

    Hi Soren, Hi lists,

    On Mon, Jun 23, 2025 at 12:59:03PM -0700, Soren Stoutner wrote:
    I am CCing debian-python as that mailing list often fields Python related >packaging questions, and you are more likely to get good Python related >responses there than debian-mentors.

    I hope that my questions are not too basic-beginnerish for the python
    mailing list. I think that having a simply package that contains a
    python program might help.

    Most Python packages are maintained in the Python team namespace, which is a >very active team. I would recommend you consider joining the team.

    It is unlikely that I will package python modules in the forseeable
    future. I just happen to use the language.

    On Monday, June 23, 2025 12:38:08 PM Mountain Standard Time Marc Haber wrote:
    dh $@ --with python3 --buildsystem=pybuild

    “--with python3” is considered deprecated syntax, although it still works. >The replacement is to build-depend on “dh-sequence-python3”. Here is an >example:

    https://salsa.debian.org/python-team/packages/python-construct-classes/-/blob/ >debian/master/debian/control?ref_type=heads#L7

    Thank you that's helpful.

    I now have:

    Build-Depends: debhelper-compat (=13),
    python3-all,
    dh-sequence-python3

    and my debian/rules just has

    %:
    dh $@ --buildsystem=pybuild

    This seems to have solved the clean issue.

    cat
    pyproject.toml [build-system]
    requires = ["setuptools>=61.0", "wheel"]
    build-backend = "setuptools.build_meta"

    [project]
    name = "console-log"
    version = "2.0"
    description = "Console Log - Displays Logs on Virtual Consoles"
    authors = [
    { name = "Marc Haber", email = "mh+debian-packages@zugschlus.de" }
    ]
    license = "GPL-2.0"
    requires-python = ">=3.7"
    dependencies = [
    ]

    [tool.setuptools.packages.find]
    where = ["src"]
    [208/6623]mh@swivel:~/packages/console-log/console-log (wip-systemd *+%) $ >>
    However, building this does not seem to give the desired results:

    (1)
    My package contains /usr/lib/python3/console_log-2.0.dist-info, and
    lintian doesn't like that. How can I preent that from being installed?

    Nothing should be installed directly into /usr/lib/python3/. Rather, all your >Python modules and dist-info should be installed into /usr/lib/python3/dist- >packages.

    Now, what would I write in my pyproject.toml to achieve that?

    (2)
    Additionally, the package doesn't build twice in a row since .pybuild
    and build directories are generated and not cleaned up on package clean.

    Am I supposed to clean those two directories up in dh_override_auto_clean?

    Not typically. I have never had to do that with a Python package. Perhaps >there is something you are missing that someone on debian-python can point >out.

    Using dh-sequence-python3 seems to have solved that.

    From a big picture, if your source package is only building one binary >package, you can include the following in debian/rules and a lot of the >packaging is automatic:

    export PYBUILD_NAME=package-class-name

    This generates a binary package named python3-package-class-name and puts >things in the right place.

    But my package doesn't publish a class. It is a self-contained program
    that could be written in any language and it happens to use an internal
    class hierarchy to support different pagers.

    (3)
    Is it okay to move the two binaries from src/ to the respective
    directories in the package via debian/console-log.install or, how would I
    tell setuptools to install those files to their targets?

    Any way that works is probably fine. In looking at other packages, I have >seen it done with debian/*.install or in debian/rules with >execute_after_dh_auto_install.

    I have it in install and it looks like it does the right thing. That
    also means that my pyproject.toml doesn't tell the python side of the
    build to install the programs, which might be wrong.

    Greetings
    Marc

    -- ----------------------------------------------------------------------------- Marc Haber | "I don't trust Computers. They | Mailadresse im Header Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402 Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)