pdm-backend
pdm-backend copied to clipboard
Improve documentation on hooks flow - specifically when and how the dynamic version is written to a file
Hi. I'm trying to wrap my head around pdm, pdm-backend and, more generally, how the hooks works and how are they actually connected.
At the moment my goal is to understand how I can leverage pdm to create a python file with the scm version. I have looked at Writing dynamic version to file and at Lifecycle and Hooks but I have some questions:
- let's say that I set up correctly
dynamic = ["version"]
,source = "scm"
, andwrite_to = "foo/_version.py"
in the appropriatepyproject.toml
tables. What cli command(s) will trigger the creation of the file? is there an explicit way? - During the initializazion, I have set
distribution = false
(because I'm writing a application that is meant to be used internally and deployed via dockerfile where I just copy the sources) - is this choice relevant? - Can you confirm I do need to set
pdm-backend
asbuild-backend
? or is it apdm
feature that may work withsetuptools
or any other backend? - What happens if in my git repository there is no tag (at all, or that matches the
tag_regex
)? I haven't see any log/warning/error during my tests - What is the rule to "choose" an appropriate tag, assuming there are more than one that matches?
- On https://github.com/pdm-project/pdm-backend/blob/940d129ddda0e604b00831907069078bb8357c77/src/pdm/backend/hooks/version/init.py#L88-L94 I think I've found the relevant code, and it is in a
hooks.version
module, but I haven't found any reference to it in the docs. Is that related to the pdm hooks?
I'm having these doubts because I have a project that I've recently migrated to pdm, and I'm new to it, and I want to be sure to understand how it works
The dynamic version, and the whole backend, only take effect when distribution = true
.
And the hook will be triggered whenever a build
action is performed, that includes pdm build
, pdm sync
, pdm install
(if installing self is required, because installing from the source will build) etc.
You can even trigger the build hook with other build frontends, such as build, in this case distribution
won't be honored as it is a PDM-only config.
Yeah it would be great to see an explanation of how the tag is generated. I could pick out the commit hash and the current date but there seemed to be large differences depending on whether my working directory was dirty and I couldn't figure out whether the branch name had an impact. Thanks!
@IronFarm https://github.com/pdm-project/pdm-backend/blob/4f20cfd51928b9e4d8b1a941630865755b569b19/src/pdm/backend/hooks/version/scm.py#L312-L327