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

Simplify longtest, which makes it support markdown #428

Closed reinout closed 11 months ago

reinout commented 11 months ago

Fixes #363

mauritsvanrees commented 11 months ago

I tried it out in the Plone package, which uses Markdown, and there it worked. This is in a checkout that already contains an egg-info directory, which makes it work.

And the good thing is, if I edit the readme and run longtest, the change gets picked up. Aha, and when I run longtest, Plone.egg-info/PKG-INFO and the other files get updated.

So why does this not work in my clone of Products.PlonePAS. I ran python3.11 setup.py egg_info, and then longtest, but that did not help, still showing the same traceback I pasted above.

Trying it with plone.memoize it works just fine, also when no egg-info directory exists at the start.

So: must be something specific in Products.PlonePAS. The new longtest command fails, even though it does create a correct egg-info directory. The old longtest command passed though, which is strange.

mauritsvanrees commented 11 months ago

It fails when I try it with Zope as well. Working theory: it fails when the code is in a src directory.

I have recent readme_renderer 40.0.0. I tried with the previous 37.3, but that gives an error in all packages:

(Pdb) print(html)
usage: __main__.py [-h] [-o OUTPUT] input
__main__.py: error: argument input: can't open 'plone.memoize': [Errno 2] No such file or directory: 'plone.memoize'

Ah, version 40 has this in the changelog: "Add CLI option to render package README." So we should require this as minimum version.

reinout commented 11 months ago

Yeah, the src dir seems to be the "problem". The egg-info isn't findable.

If I make a virtualenv, do a dev-install of plone.pas and add zest.releaser, then bin/longtest picks up the package just fine.

mauritsvanrees commented 11 months ago

It seems to be this PR that changed their use of pkg_resources into importlib.metadata. Trying it out in plone.memoize it works, as the distribution is found:

>>> from pprint import pprint
>>> import importlib.metadata
>>> pprint(importlib.metadata.packages_distributions())
...
 'plone': ['plone.memoize'],

In Products.PlonePAS the same command show no Products anywhere. When I do cd src, and try again, it does show up.

So a workaround/solution could be to do os.chdir("src") if that exists. Surprisingly this even works when no egg-info directory is there yet. Could be something that readme_render should fix though.

mauritsvanrees commented 11 months ago

I am creating an issue there, will let it link here.

reinout commented 11 months ago

So it is more importlib that cannot find the package metadata where pkg_resources can. Could it be a combination of a pkg_resources-style namespace package with the src dir?

mauritsvanrees commented 11 months ago

Actually, I see that pkg_resources has the same problem:

>>> import pkg_resources
>>> pkg_resources.get_distribution("Products.PlonePAS")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/maurits/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pkg_resources/__init__.py", line 478, in get_distribution
    dist = get_provider(dist)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/maurits/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pkg_resources/__init__.py", line 354, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maurits/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pkg_resources/__init__.py", line 909, in require
    needed = self.resolve(parse_requirements(requirements))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maurits/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pkg_resources/__init__.py", line 795, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'Products.PlonePAS' distribution was not found and is required by the application

If you first change directory, before calling pkg_resources, it works though:

>>> import os
>>> os.chdir("src")
>>> import pkg_resources
>>> pkg_resources.get_distribution("Products.PlonePAS")
Products.PlonePAS 8.0.3.dev0 (/Users/maurits/community/plone-coredev/6.0/src/Products.PlonePAS/src)
reinout commented 11 months ago

Works fine in my local Products.PlonePAS dir now.

mauritsvanrees commented 11 months ago

This works now for me.

It does seem that this still only works for projects that have a setup.py. In that case we get the name of the package by first calling python setup.py egg_info (when getting vcs.name). With only a setup.cfg or pyproject.toml, we parse those files, which means there is no egg_info directory, so rendering the readme fails.

But this is no worse than what we had before. And it now works with Markdown, which is what we were mostly after. I will merge. Thanks!

mauritsvanrees commented 11 months ago

I have released 9.0.0a2 with the latest changes.

reinout commented 11 months ago

yeah