• pybuild and setuptools_scm

    From Paul Boddie@21:1/5 to All on Thu Jul 11 16:20:02 2024
    Hello,

    I wonder if anyone can provide some advice about setuptools_scm interactions with pybuild.

    I have been struggling to get some software packaged that relies on setuptools_scm. It seems to effectively ignore the package data section in a pyproject.toml file and to include a broader collection of files when being built using "python3 -m build".

    (Obviously, such practices are less than helpful: why bother with declarations of packaged files if something is going to magically "discover" the files, anyway? Why use magical "do what I mean" tooling in the first place? That
    might be the more awkward question, I suppose.)

    Since setuptools_scm is integrated into pyproject.toml so as to be invoked
    with the appropriate incantations present in that file, I assumed that pybuild might cause it to be invoked, too. However, what I see is that the files that should supposedly be included in the package are missing.

    Running the command that pybuild invokes from within the source distribution for the software...

    python3 -m build --skip-dependency-check --no-isolation --wheel --outdir dist

    ...yields a wheel with all the missing files. But when invoked by pybuild, itself invoked by gbp build-package, only the declared files seem to be included. I can obviously work around this by patching pyproject.toml, but upstream seems to be uninterested in supporting anyone not invoking the setuptools_scm magic.

    I added python3-setuptools-scm to Build-Depends. Can anyone explain why this doesn't work?

    Thanks in advance,

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefano Rivera@21:1/5 to All on Fri Jul 12 01:10:01 2024
    Hi Paul (2024.07.11_14:01:01_+0000)

    I have been struggling to get some software packaged that relies on setuptools_scm. It seems to effectively ignore the package data section in a pyproject.toml file and to include a broader collection of files when being

    Which source package is this?
    Where did the source come from? Git or PyPI tarball?

    setuptools_scm gets stuff from SCM and uses it for metadata. During the
    package build, the SCM isn't available (no .git directory in the source package). So, it falls back to alternate modes:
    1. The version gets put in an environment variable by pybuild.
    2. The list of known files comes from the SOURCES.txt in egg-info. If
    you are using the upstream git for your source, you may be missing
    this. Try switching to a PyPI sdist.

    Stefano

    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Boddie@21:1/5 to All on Fri Jul 12 02:10:01 2024
    On Friday, 12 July 2024 01:01:14 CEST Stefano Rivera wrote:

    Which source package is this?

    This is the source for MoinMoin 2.0 which is currently unpackaged in Debian.

    Where did the source come from? Git or PyPI tarball?

    It is actually an archive from the GitHub release page, integrated into my packaging repository using the gbp import-orig command, although I have previously tried the Git packaging approach using an upstream branch.

    The weird thing is that I can run "python3 -m build", even with the options that pybuild introduces, outside the gbp buildpackage environment, and it
    seems that the package data is obtained using setuptools_scm. But as part of the gbp invocation, the package data is limited to that mentioned in the deficient pyproject.toml file.

    setuptools_scm gets stuff from SCM and uses it for metadata. During the package build, the SCM isn't available (no .git directory in the source package). So, it falls back to alternate modes:
    1. The version gets put in an environment variable by pybuild.
    2. The list of known files comes from the SOURCES.txt in egg-info. If
    you are using the upstream git for your source, you may be missing
    this. Try switching to a PyPI sdist.

    This is very helpful to know! I had noticed that the egg-info metadata from
    the PyPI source distribution might have been able to help the process along, but I didn't know the mechanism through which that might occur. At one point, the Debian tools were objecting to superfluous files that might have included the egg-info metadata, but I imagine that if it is imported in the right way, the tools are able to take advantage of it correctly.

    Having tried to build once again, importing the PyPI sources instead, I see that the missing files are now included in the package, so this is encouraging progress.

    Many thanks for the guidance!

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefano Rivera@21:1/5 to All on Fri Jul 12 07:20:01 2024
    Hi Paul (2024.07.12_00:05:03_+0000)
    The weird thing is that I can run "python3 -m build", even with the options that pybuild introduces, outside the gbp buildpackage environment, and it seems that the package data is obtained using setuptools_scm. But as part of the gbp invocation, the package data is limited to that mentioned in the deficient pyproject.toml file.

    Is your packaging in git? It'll be finding the list of files tracked by
    git, from git.

    That won't be there when building from a Debian source package,
    extracted from a .dsc.

    Stefano

    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mathias Behrle@21:1/5 to All on Fri Jul 12 09:10:01 2024
    * Stefano Rivera: " Re: pybuild and setuptools_scm" (Thu, 11 Jul 2024 23:01:14
    +0000):

    Hi Stefano,

    I have been struggling to get some software packaged that relies on setuptools_scm. It seems to effectively ignore the package data section in a pyproject.toml file and to include a broader collection of files when being

    Which source package is this?
    Where did the source come from? Git or PyPI tarball?

    setuptools_scm gets stuff from SCM and uses it for metadata. During the package build, the SCM isn't available (no .git directory in the source package). So, it falls back to alternate modes:
    1. The version gets put in an environment variable by pybuild.
    2. The list of known files comes from the SOURCES.txt in egg-info. If
    you are using the upstream git for your source, you may be missing
    this. Try switching to a PyPI sdist.

    I had a similar problem when setuptools_scm kicked in during the build process and produced versions different from the orig tarball. Packaging is in git and tarballs are imported from PyPI.

    I disabled the automatic versioning with

    https://salsa.debian.org/tryton-team/python-csb43/-/commit/e8788e09818948231a48cc1472a5f54444b65fcc

    Could you confirm this is the right approach or is there a more elegant way?

    Thanks,
    Mathias



    --

    Mathias Behrle
    PGP/GnuPG key availabable from any keyserver, ID: 0xD6D09BE48405BBF6
    AC29 7E5C 46B9 D0B6 1C71 7681 D6D0 9BE4 8405 BBF6

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Boddie@21:1/5 to All on Fri Jul 12 13:10:01 2024
    On Friday, 12 July 2024 07:17:27 CEST Stefano Rivera wrote:
    Hi Paul (2024.07.12_00:05:03_+0000)

    The weird thing is that I can run "python3 -m build", even with the
    options that pybuild introduces, outside the gbp buildpackage environment, and it seems that the package data is obtained using setuptools_scm. But
    as part of the gbp invocation, the package data is limited to that mentioned in the deficient pyproject.toml file.

    Is your packaging in git? It'll be finding the list of files tracked by
    git, from git.

    The packaging is in git, yes. I suppose what I don't understand is the role of setuptools_scm in building a package for installation (or the construction of
    a binary package). A source package will aim to incorporate all of the tracked files, but a built/binary package may not.

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry Shachnev@21:1/5 to Paul Boddie on Fri Jul 12 22:30:02 2024
    Hi Paul!

    On Fri, Jul 12, 2024 at 12:59:43PM +0200, Paul Boddie wrote:
    The packaging is in git, yes. I suppose what I don't understand is the role of
    setuptools_scm in building a package for installation (or the construction of
    a binary package). A source package will aim to incorporate all of the tracked
    files, but a built/binary package may not.

    setuptools_scm ships an entry point in [setuptools.file_finders] group,
    so when you are building a package from a git checkout, it automatically includes all files which are tracked in git.

    In one of my packages, I had a similar situation that some files were missing when not building from git. At first I wanted to fix it by adding the missing files to MANIFEST.in [1]. But then upstream suggested a different approach, using setuptools_scm's support for git archives [2]. So we went this way [3]. Maybe you can use any of these two approaches in your package, too.

    [1]: https://github.com/Python-SIP/sip/pull/28
    [2]: https://setuptools-scm.readthedocs.io/en/latest/usage/#git-archives
    [3]: https://github.com/Python-SIP/sip/pull/30

    --
    Dmitry Shachnev

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEq2sdvrA0LydXHe1qsmYUtFL0RrYFAmaRkRAACgkQsmYUtFL0 RrboFw/+LH5cgEwFCFKU72kiJDnjHKZPms9UQcADk1VPDDzCnFwe6RDmd4ZSpSYx DFkPN3X7QgZzcX+VUzO5S+XaaIUJJKDe05k8f/hj0Uz/8PSip1JYgzR3efdLrcA3 r8FAoOYVLR63xRWj8it2fz2ZWtOoceBLfdKGL3g/RKPplD8gsYObtDPEMSRAGWxX jGmOCdbKpD9sdV5tcJuJyf18xuaLn9V1miRu60Xe09r9XbH/CTSUBEnsXpazscPr Us6hsL8gCBdckyLcfDj5wTUsnOEMcOKHug153t4BGKKZ8N8BpTDEc1ps+zvazdqy EqxsfJd4Wdo4GYToJlX1CbdH4o/YDi4ZwXARbPCz/2+NFUOxxmoLRJEL2QgSKmp9 U9KxW0zn5IeJfqMuFETzIl2XxVM9wRnEnqj/rUP5Nf3uzY13FD9E0BRcEOPlYb59 aCd0VAT/CwzuXz5XOhIzPMH7dImYffql0xC2soU9uFY1OFizWR8s/SDYiK9iyCvZ O4xT1TzRGJkz434KjlBhd5XQ00Kl/gsVOHsU8sbu/7YBodMQujS3+BAPLzi1SoyM Aeyyw3DE7g72p1b1ZzTOVHL9kupFNJtC+7LQe2wXiDJROGvSIY2CxbZNZYMI+s2+ PNbuS+aookrlvf5JhTkZ3XYKr5EHPGsyTB9vcOP4FMivEP0I9G8=
    =VaTE
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefano Rivera@21:1/5 to All on Sat Jul 13 01:40:01 2024
    Hi Thomas (2024.07.12_12:53:54_+0000)
    The way to deal with it, is simply something like this:

    export SETUPTOOLS_SCM_PRETEND_VERSION=$(shell dpkg-parsechangelog -SVersion
    | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~git.*//' -e 's/~/.0/' -e 's/+dfsg1//' -e 's/+ds1//' | head -n 1)

    and then setuptools-scm knows what version to use without using the Git history.

    Probably pybuild does that automatically under the hood (I tend to not use pybuild, and so I do the above ...).

    It does.

    Stefano

    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julian Gilbey@21:1/5 to Stefano Rivera on Sun Jul 14 09:00:02 2024
    On Fri, Jul 12, 2024 at 11:29:51PM +0000, Stefano Rivera wrote:
    Hi Thomas (2024.07.12_12:53:54_+0000)
    The way to deal with it, is simply something like this:

    export SETUPTOOLS_SCM_PRETEND_VERSION=$(shell dpkg-parsechangelog -SVersion | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~git.*//' -e 's/~/.0/' -e
    's/+dfsg1//' -e 's/+ds1//' | head -n 1)

    and then setuptools-scm knows what version to use without using the Git history.

    Probably pybuild does that automatically under the hood (I tend to not use pybuild, and so I do the above ...).

    It does.

    Assuming your package Build-Depends: python3-setuptools-scm

    Julian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefano Rivera@21:1/5 to All on Tue Jul 16 05:10:01 2024
    Hi Mathias (2024.07.12_06:47:39_+0000)
    I had a similar problem when setuptools_scm kicked in during the build process
    and produced versions different from the orig tarball. Packaging is in git and
    tarballs are imported from PyPI.

    I disabled the automatic versioning with

    https://salsa.debian.org/tryton-team/python-csb43/-/commit/e8788e09818948231a48cc1472a5f54444b65fcc

    Could you confirm this is the right approach or is there a more elegant way?

    That approach doesn't look great.

    Instead of that patch, just Build-Depend on python3-setuptools-cm, so
    that it can do its magic. In my testing it works just fine on your
    package.

    Oh, you're also missing pytest, so the package tests are failing.

    Stefano

    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Boddie@21:1/5 to All on Thu Jul 18 11:50:02 2024
    On Thursday, 18 July 2024 11:10:01 CEST Mathias Behrle wrote:

    I have no clue why this is working for you.

    I removed the patch, tried your proposal and the build just fails because setuptools-scm writes again a dev version to src/csb43/_version.py:

    https://salsa.debian.org/tryton-team/python-csb43/-/jobs/5988081
    dpkg-source: info: local changes detected, the modified files are:
    source_dir/src/csb43/_version.py

    For what it is worth, I also mention the generated file in debian/clean.

    Another thing that the code I am packaging does is to dynamically look up version information in its documentation script:

    from pkg_resources import get_distribution
    release = get_distribution('moin').version

    I have found that this doesn't tend to work when building the package, so I have a patch that manually defines this information instead. Maybe there is a better way of dealing with this, too.

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mathias Behrle@21:1/5 to All on Thu Jul 18 11:30:01 2024
    * Stefano Rivera: " Re: pybuild and setuptools_scm" (Tue, 16 Jul 2024 03:06:53
    +0000):

    Hi Stefano,

    thanks for looking into it.


    I had a similar problem when setuptools_scm kicked in during the build process and produced versions different from the orig tarball. Packaging is in git and tarballs are imported from PyPI.

    I disabled the automatic versioning with

    https://salsa.debian.org/tryton-team/python-csb43/-/commit/e8788e09818948231a48cc1472a5f54444b65fcc

    Could you confirm this is the right approach or is there a more elegant way?

    That approach doesn't look great.

    Instead of that patch, just Build-Depend on python3-setuptools-cm, so
    that it can do its magic. In my testing it works just fine on your
    package.

    I have no clue why this is working for you.

    I removed the patch, tried your proposal and the build just fails because setuptools-scm writes again a dev version to src/csb43/_version.py:

    https://salsa.debian.org/tryton-team/python-csb43/-/jobs/5988081
    dpkg-source: info: local changes detected, the modified files are:
    source_dir/src/csb43/_version.py


    But SETUPTOOLS_SCM_PRETEND_VERSION like proposed by Thomas did the trick. https://salsa.debian.org/tryton-team/python-csb43/-/pipelines/703025

    May be pybuild doesn't handle correctly a version string like 0.10.0+dfsg-1?

    Oh, you're also missing pytest, so the package tests are failing.

    Thanks!

    Mathias



    --

    Mathias Behrle
    PGP/GnuPG key availabable from any keyserver, ID: 0xD6D09BE48405BBF6
    AC29 7E5C 46B9 D0B6 1C71 7681 D6D0 9BE4 8405 BBF6

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefano Rivera@21:1/5 to All on Fri Jul 19 13:10:01 2024
    Hi Mathias (2024.07.18_09:10:01_+0000)
    I have no clue why this is working for you.

    I was testing locally, not in salsa CI. So I ran into the thing you ran
    into after the build, not before it.

    I removed the patch, tried your proposal and the build just fails because setuptools-scm writes again a dev version to src/csb43/_version.py:

    Yes, you need to add that to debian/clean. Sorry, I didn't mention that, because it's the next step after getting the package to build.

    But SETUPTOOLS_SCM_PRETEND_VERSION like proposed by Thomas did the trick. https://salsa.debian.org/tryton-team/python-csb43/-/pipelines/703025
    ...
    May be pybuild doesn't handle correctly a version string like 0.10.0+dfsg-1?

    Yeah, you shouldn't have to export that because pybuild does. But,
    right, it's not removing +dfsg. Now that PEP-440 versions are strongly enforced, that's no good.

    Committed: https://salsa.debian.org/python-team/tools/dh-python/-/commit/ae0facfd1216fd25185aa5f1db9f12b26e3dbcf1

    Some more suggestions for your package:

    You can use pybuild-plugin-pyproject. (just build-depend on it)

    Something like this in debian/clean:
    doc/build/
    src/csb43.egg-info/
    src/csb43/_version.py

    And in debian/rules:
    export PYBUILD_AFTER_BUILD=cd $(CURDIR); PYTHONPATH={build_dir} sphinx-build doc/source build/html
    export PYBUILD_TEST_ARGS=$(CURDIR)/src/csb43/tests

    Stefano

    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julian Gilbey@21:1/5 to Stefano Rivera on Fri Jul 19 15:20:01 2024
    On Fri, Jul 19, 2024 at 11:06:46AM +0000, Stefano Rivera wrote:
    [...]
    May be pybuild doesn't handle correctly a version string like 0.10.0+dfsg-1?

    Yeah, you shouldn't have to export that because pybuild does. But,
    right, it's not removing +dfsg. Now that PEP-440 versions are strongly enforced, that's no good.

    Committed: https://salsa.debian.org/python-team/tools/dh-python/-/commit/ae0facfd1216fd25185aa5f1db9f12b26e3dbcf1

    But PEP-440 allows "+dfsg" as the "Local version identifier", so I
    don't understand why this must be removed.

    Best wishes,

    Julian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefano Rivera@21:1/5 to All on Sun Jul 21 13:10:01 2024
    Hi Julian (2024.07.19_13:16:02_+0000)

    On Fri, Jul 19, 2024 at 11:06:46AM +0000, Stefano Rivera wrote:
    [...]
    May be pybuild doesn't handle correctly a version string like 0.10.0+dfsg-1?

    Yeah, you shouldn't have to export that because pybuild does. But,
    right, it's not removing +dfsg. Now that PEP-440 versions are strongly enforced, that's no good.

    Committed: https://salsa.debian.org/python-team/tools/dh-python/-/commit/ae0facfd1216fd25185aa5f1db9f12b26e3dbcf1

    But PEP-440 allows "+dfsg" as the "Local version identifier", so I
    don't understand why this must be removed.

    Good point, I'll revert that.

    Stefano

    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

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