Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify longtest, which makes it support markdown #428

Merged
merged 12 commits into from
Jul 18, 2023

Conversation

reinout
Copy link
Collaborator

@reinout reinout commented Jul 14, 2023

Fixes #363

Copy link
Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, this should be okay.
But I tried it and it failed:

(Pdb) print(html)
Traceback (most recent call last):
File "/Users/maurits/.pyenv/versions/3.11.4/lib/python3.11/importlib/metadata/__init__.py", line 563, in from_name
return next(cls.discover(name=name))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/maurits/community/zest.releaser/lib/python3.11/site-packages/readme_renderer/__main__.py", line 62, in <module>
main()
File "/Users/maurits/community/zest.releaser/lib/python3.11/site-packages/readme_renderer/__main__.py", line 26, in main
message = metadata(args.input)
^^^^^^^^^^^^^^^^^^^^
File "/Users/maurits/.pyenv/versions/3.11.4/lib/python3.11/importlib/metadata/__init__.py", line 998, in metadata
return Distribution.from_name(distribution_name).metadata
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/maurits/.pyenv/versions/3.11.4/lib/python3.11/importlib/metadata/__init__.py", line 565, in from_name
raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for Products.PlonePAS

So we would somehow need to build the package before calling this. Otherwise it will either fail, or it will show an outdated long description. Maybe run build?

CHANGES.rst Outdated Show resolved Hide resolved
@mauritsvanrees
Copy link
Member

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
Copy link
Member

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
Copy link
Collaborator Author

reinout commented Jul 14, 2023

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.

(Otherwise the package rendering isn't available)
@mauritsvanrees
Copy link
Member

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
Copy link
Member

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

@reinout
Copy link
Collaborator Author

reinout commented Jul 14, 2023

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
Copy link
Member

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
Copy link
Collaborator Author

reinout commented Jul 14, 2023

Works fine in my local Products.PlonePAS dir now.

@reinout reinout requested a review from mauritsvanrees July 14, 2023 18:50
@mauritsvanrees
Copy link
Member

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 mauritsvanrees merged commit d278743 into master Jul 18, 2023
@mauritsvanrees mauritsvanrees deleted the reinout-markdown-longtest branch July 18, 2023 12:39
@mauritsvanrees
Copy link
Member

I have released 9.0.0a2 with the latest changes.

@reinout
Copy link
Collaborator Author

reinout commented Jul 19, 2023

yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Markdown file validation under longtest
2 participants