Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.maint.python > #16945 > unrolled thread

Re: need help for my first python package

Started bySoren Stoutner <soren@debian.org>
First post2025-06-23 22:00 +0200
Last post2025-06-24 10:40 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.debian.maint.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: need help for my first python package Soren Stoutner <soren@debian.org> - 2025-06-23 22:00 +0200
    Re: need help for my first python package Marc Haber <mh+debian-mentors@zugschlus.de> - 2025-06-24 10:40 +0200

#16945 — Re: need help for my first python package

FromSoren Stoutner <soren@debian.org>
Date2025-06-23 22:00 +0200
SubjectRe: need help for my first python package
Message-ID<L0VuF-cEOw-1@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [next] | [standalone]


#16946

FromMarc Haber <mh+debian-mentors@zugschlus.de>
Date2025-06-24 10:40 +0200
Message-ID<L17m9-cMt6-1@gated-at.bofh.it>
In reply to#16945
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.maint.python


csiph-web