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

Add CLI option to render package README. #271

Merged
merged 5 commits into from Jan 5, 2023

Conversation

tillahoffmann
Copy link
Contributor

This PR adds an option --package to the CLI such that the README of a package can be rendered as it would on pypi.org. Using this option, package authors can preview READMEs in addition to checking their validity using twine check. Rendering the README based on the package metadata is important because a number of packages strip out roles and directives that are not supported by pypi.org in their setup.py. Publishing to test.pypi.org, as discussed in pypa/twine#875, is an alternative, but having a local preview would be desirable (at least for myself). This PR also adds tests for the existing CLI.

@miketheman
Copy link
Member

@tillahoffmann Thanks! We removed the documented example of using the CLI in #197 - since the interface doesn't currently render Markdown. Before introducing a CLI that we'd expect to support, would you consider adding that behavior?

Please also update your branch from main as it includes some test fixes.

Comment on lines +32 to +42
if not content_format:
content_type = message.get("Description-Content-Type", "text/x-rst")
if content_type == "text/x-rst":
content_format = "rst"
elif content_type == "text/markdown":
content_format = "md"
elif content_type == "text/plain":
content_format = "txt"
else:
raise ValueError(f"invalid content type {content_type} for package "
"`long_description`")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part isn't particularly well tested because we'd have to install a bunch of dummy packages for the tests to run. Or we could mock out get_distribution to return the right data (not quite as reliable a test if we get the mocking wrong).

@tillahoffmann
Copy link
Contributor Author

Hm, interesting, any idea why pypy might fail while the others succeed? I can also mock out writing to the file rather than using a temporary directory.

Copy link
Member

@miketheman miketheman left a comment

Choose a reason for hiding this comment

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

Thanks for working through this!

@miketheman miketheman merged commit 0824eca into pypa:main Jan 5, 2023
@tillahoffmann tillahoffmann deleted the package branch January 5, 2023 20:33
@tillahoffmann
Copy link
Contributor Author

Thanks for working through this!

Thanks for the speedy review!

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

Successfully merging this pull request may close these issues.

None yet

2 participants