-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support use as pdm-backend plugin #37
base: main
Are you sure you want to change the base?
Conversation
Why don't you use PDM with the hatchling backend? Feels like a more composable solution. |
In simple cases, either |
0cb906c
to
7a6d075
Compare
Get configuration from "tool.pdm.build.hooks.fancy-pypi-readme" (rather than "tool.hatch.metadata.hooks.fancy-pypi-readme") when running as a pdm-backend plugin.
Fix CLI to change config source ("tools.pdm.build..." vs "tools.hatch.metadata...") when the build backend is set to pdm.backend.
7a6d075
to
c73f373
Compare
This feature has been percolating in my brain for months, but I've been hardcore procrastinating on it (as I've been on your PR – sorry). But I find it a bit ugly to have a package named hatch-fancy-pypi-readme with PDM support. I wonder if we could use your changes (sorry couldn't look closer yet, because I'm positively overwhelmed rn) to somehow extract a |
Yeah, that occurred to me, too...
That would definitely be cleaner. I didn't suggest it initially because I wasn't sure how receptive you'd be to splitting off a new distribution. If it weren't for the CLI, it would, I think, be pretty straight-forward. Here's an outline of what's in this PR and how involved each bit is. The Build HookImplementing the pdm build hook required minimal tweaks in the rest of the The only complication stems from the fact that (from what I can tell) hatchling prescribes the config key under which your hooks config table will be found ( This was simple and required zero change to any existing code. The pdm hook code fetches its config from the pyproject.toml dict that pdm passes it, passes it to The only issue is that any error message generated by The CLISo now with two different (three if you count I added a The changes are nothing complicated, but the diff line count is not insignificant. Other than just the mechanics of creating two new distributions, splitting this into three distribution would not be hard. The only real question is what to do about the CLI. Given that the CLI is pretty simple, and that the current one is already named If we do that, then I think the only code that needs any tweaking is in I can try, if you'd like. (Though it may be a little while before I get to it.) |
I did a quick job of splitting things into three separate dists. This is not done. In particular more thought needs to go into what API gets exported from Also, I haven't touched the READMEs, etc at all, so they obviously need work. This is more a proof of concept at this point. Anyhow, the three dists are in three branches of my forked repo:
It all splits out fairly logically. However, there is now more packaging than code! |
Having slept on it, here's another idea:
If we take this route, I propose adding a new function to the API which would be used to extract the fancy-readme config data from the (parsed) pyproject.toml (and possibly hatch.toml) data. This new function would be used by the CLI, and would replace most of the logic that's currently in @dataclass
ConfigData:
data: dict[str, Any]
# Information on where the config data was extracted from
source_key: str # e.g. "tool.pdm.build.hooks.fancy-pypi-readme"
source_filename: str | None # e.g. "pyproject.toml"
def find_config_data(
pyproject_toml: dict[str, Any], # parsed pyproject.toml data
build_backend: str | None = None,
*,
hatch_toml: dict[str, Any] | None = None, # parsed hatch.toml data (when appropriate)
) -> ConfigData:
... The This function would perform various sanity checks, then return the data from the appropriate fancy-pypi-readme config subtable. E.g. for The return value would also contain extra attribute(s) carrying metadata regarding where the config data was extracted from. This extra metadata would be used by try:
config_data = find_config_data(pyproject_toml, hatch_toml=hatch_toml, build_backend=build_backend)
config = load_and_validate_config(config_data)
except ConfigurationError as e:
# report error
print(build_text(config.fragments, config.substitutions), file=out) The new function would also be used by the PDM build hook to extract the readme config from the parsed pyproject.toml data. |
Ha you've been busy – sorry I can't quite keep up ATM! I'm currently mostly stuck in pondering how to separate them mechanically. I think I don't want to separate out more repositories… so I guess some kind of monorepo would be apt? I wonder what the most elegant way to achieve this would be. I almost suspect the most straight-forward way would be to make one |
If the plan is to (add pdm-backend compatibility and) rename the current
As far as the build backend hooks, that's pretty much how it works, automatically. The build backends find the hooks via declared entry-points. As long as those entry points point to different modules for the different build backends that's exactly what happens. |
FYI, you should look at my dynamic-metadata proposal and system. It's not finalized yet, but it would provide a way to make general plugins for any backend. This is already supported (via a bit of fragile usage of private APIs) in scikit-build-core. Making a plugin for each backend quickly becomes unmanageable! |
OK happy new year and sorry, I've come to the conclusion that I don't have the time and energy to do this properly. So, if you're willing to rebase and make it work again, I'm willing to take a closer look. If not, I understand. (Henry: I'm only entertaining this because I use PDM myself :)) |
This PR adds support for using hatch-fancy-pypi-readme as a PDM-backend plugin.
I was looking for a plugin exactly like this one, except to use with
pdm-backend
instead ofhatchling
. As it turns out, adding a pdm-backend plugin was pretty straight-forward.I also decided to dynamically switch the
pyproject.toml
key where the plugin finds its configuration table depending on the build backend. Now whenbuild-system.build-backend
is set topdm.backend
, the configuration now gets pulled fromtool.pdm.build.hooks.hatch-fancy-pypi-readme
(rather thantool.hatch.metadata.hooks.fancy-pypi-readme
).This switch markedly increases the diff count of the PR, however it seems to me that the potential for confusion if a pdm-backend plugin pulls its configuration from
tool.hatch.*
is large, so the extra mess is worth it.