Skip to content

pdm_configure hook method - #310

Draft
sneakers-the-rat wants to merge 2 commits into
pdm-project:mainfrom
sneakers-the-rat:pre-config-hook
Draft

pdm_configure hook method#310
sneakers-the-rat wants to merge 2 commits into
pdm-project:mainfrom
sneakers-the-rat:pre-config-hook

Conversation

@sneakers-the-rat

Copy link
Copy Markdown
Contributor

Fix: pdm-project/pdm#3824

This problem has blocked me so i had some time to work on it:

There is a problem with the packaging spec such that it is ambiguous what to do with a '../../README.md' outside of the path of the package root. this is common in monorepos. However

  • having the readme in the repo root and using a ../../ relative path breaks builds, as the tarfile library refuses to unpack files outside of the directory
  • having the configuration use readme="README.md" and then copying from the repo root is impossible, because the Config object fails validation since the readme file doesn't exist.

however, rather than making some unspec'd behavior a part of the builder, @frostming suggested that a configuration hook might be an acceptable fix to the problem. This is a more generally useful change, as currently all the hooks run after the configuration has been validated. If there is any customization that needs to happen that relates to the configuration, i.e. avoiding the above configuration error, copying a file so the configuration is valid, then it can use this hook. This effectively makes any field dynamic if people want it to be.

Other parts of the builder need the config (including getting the hooks itself), so I couldn't just have a hook that happens entirely before the configuration is loaded. That would also make it impossible to mutate the config, which sort of defeats the purpose of the hook. So I split the validation phase of the Config object out of its __init__ method, and it is called after the hook is called.

I just wanted to open this as a draft at first to see if it would be acceptable, and if it is I can also update the docs to match. I didn't see other hooks having specific behavioral tests so I didn't add them, but if we want to have a test that the hook can mutate and correct an invalid pyproject.toml config, just let me know.

happy to make any changes!

@netlify

netlify Bot commented Jul 25, 2026

Copy link
Copy Markdown

Deploy Preview for pdm-backend-docs ready!

Name Link
🔨 Latest commit bdf7688
🔍 Latest deploy log https://app.netlify.com/projects/pdm-backend-docs/deploys/6a641ad4f0843a0008774da6
😎 Deploy Preview https://deploy-preview-310--pdm-backend-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@frostming

Copy link
Copy Markdown
Contributor

See #309

@sneakers-the-rat

Copy link
Copy Markdown
Contributor Author

Oh cool! Thanks. That seems like it will probably meet my need in the original issue. If this PR would be something you'd be interested in as well, I can finish it by adding docs for it, otherwise feel free to close. I can see it being independently useful for anyone who wants to do something else with the config before it's validated, but also wouldn't be offended if you decide it's not useful.

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.

readme entries in pyproject.toml can't refer to files in parent directories with relative paths

2 participants