zestsoftware / zest.releaser

Python software releasing made easy and repeatable
https://zestreleaser.readthedocs.io
GNU General Public License v2.0
198 stars 62 forks source link

Use native namespace packages for zest.releaser. #422

Closed mauritsvanrees closed 12 months ago

mauritsvanrees commented 12 months ago

This is instead of deprecated pkg_resources based ones.

Note that this can be a problem in case zest.releaser is installed in combination with other packages in the zest namespace. But there are only a few such Plone related packages, so they won't usually be installed in the same virtual environment. And otherwise I can make new releases of those packages. Now seems a good time to do this.

Note that this needed a change in tox.ini, otherwise no tests were found.

mauritsvanrees commented 12 months ago

I got a warning during release, about the tests directory. Fixed in commit 41e4e62808d27fad11998c8ef21230c8aa9ffe85. Read the commit message for details. We may want to fix this differently at some point, but for now it works.

@gforcada If we are going to move Plone packages to native namespaces, I have some more learning to do. :-) If a package has a src-layout, it seems easier though.

For reference here is a tryout of find_namespace_packages in our repo:

$ bin/python
>>> from setuptools import find_namespace_packages
>>> find_namespace_packages()
['bin', 'dist', 'include', 'zest', 'lib', 'doc', 'zest.releaser', 'zest.releaser.tests', 'doc.source']
>>> find_namespace_packages(where="zest")
['releaser', 'releaser.tests']
>>> find_namespace_packages(exclude=['bin', 'dist', 'include', 'lib'])
['zest', 'doc', 'zest.releaser', 'zest.releaser.tests', 'doc.source']

When I move zest to src/zest (and update MANIFEST.in to recursively include src instead of zest), then the following two approaches both seem to work:

from setuptools import setup

setup(
    include_package_data=True,
    zip_safe=False,
)

and

from setuptools import find_namespace_packages
from setuptools import setup

setup(
    packages=find_namespace_packages(where="src"),
    package_dir={"": "src"},
    include_package_data=True,
    zip_safe=False,
)

Not sure if include_package_data is needed.

mauritsvanrees commented 12 months ago

I forgot that we have zest.pocompile which hooks into zest.releaser to compile .po files to .mo files during release. This combination failed, at least in the Plone core development buildout. The fullrelease script was created, but using it gave an error:

ModuleNotFoundError: No module named 'zest.releaser'

So I made an alpha version for zest.pocompile with native namespaces: https://github.com/zestsoftware/zest.pocompile/pull/2 Then it works.

reinout commented 11 months ago

Totally unrelated, but when I looked at the pocompile diff: I normally use a double \n\n to separate the readme and changelog, just in case someone managed to produce a readme without a trailing space.

Shouldn't be a problem with properly set up editors and pre-commit hooks, but... I'm so used to it that I thought it to be an error to have a single \n :-) Everything is fine :-)

reinout commented 11 months ago

Oh, one other problem that might be related: if I run "dependencychecker" it doesn't find the python files. It only finds the doctest files. I'm looking into this further.