nedbat / scriv

Changelog management tool
https://scriv.readthedocs.io
Apache License 2.0
256 stars 28 forks source link

Get version from an entrypoint #109

Open nedbat opened 11 months ago

nedbat commented 11 months ago

From a discussion in Discord with @RonnyPfannschmidt:

RonnyPfannschmidt: @nedbat does scriv have any way to get the next version from something like setuptools_scm ?

nedbat: Nothing built-in, and I don't know anything about setuptools_scm, but maybe we can figure something out.
nedbat: scriv collect --version=$(setuptools_scm something?)

RonnyPfannschmidt: that works out - also wondering if perhaps a cli command could be used as default version source like (python -m setuptools_scm --strip-dev)

nedbat: you mean, we could add a setting to scriv that is the command to run to get the version?  That could work.
nedbat: I like the nature of that: nothing hard-coded, but easy to configure the connections you want. The docs could include example commands for other tools.

RonnyPfannschmidt: or a entrypoint to call

nedbat: yes
nedbat: We already have a setting: version = literal: pyproject.toml: project.version  It could be extended:
    version = command: setuptools_scm something
    or
    version = call: setuptools_scm.main(strip_dev=True)

nedbat: (maybe full python there is weird)

RonnyPfannschmidt: lets not go there, - if its a command, its a string and fair game, if its a "entrypint" it should be pre-configred for scriv

nedbat: what's an example of an entrypoint? A named entrypoint, or module.callable ?

RonnyPfannschmidt: aka there should be a entrypoint like "scriv.get_version" and importlib metadata should be used to fetch a name of that group, no parameters should be passed
RonnyPfannschmidt: lets not go down the path of random pythonpath modification and module lookup, its a can of killer worms

nedbat: I'm assuming you want to use a setuptools_scm entrypoint?  What from here would be useful? https://github.com/pypa/setuptools_scm/blob/main/pyproject.toml#L69-L101

RonnyPfannschmidt: @nedbat i think you misunderstood me - i would add a scriv.get_version entrypoint to setuptools_scm like setuptools_scm = setuptools_scm._integration.scriv:return_version_for_scriv - and then people could configure that in their scriv config

nedbat: ok, so it would be an entrypoint from setuptools_scm, that's fine if it doesn't exist yet.
nedbat: i think setuptools_scm is well ahead of the curve in terms of exporting many entrypoints, so I'm not sure I would limit the callability to only entrypoints.

RonnyPfannschmidt: @nedbat i an understand the sentiment, unfortunately that opens up the failure vector of having to manage pythonpath ^^ based on year of suffering its not something a tool wants tobe in charge of

nedbat: I will keep an eye out for that.
nedbat commented 11 months ago

I understand it now better than I did in Discord! :)

A scriv-specific entrypoint seems esoteric to me, I'm not sure many tools would implement one. Running a command would let individual adopters plug tools together without the other tool needing to provide a scriv endpoint. But is it safe to have a config file in your repo with command: run_untrusted_code blah blah as a setting?

RonnyPfannschmidt commented 11 months ago

the ux would be better than having a RELEASING.md that tell people to copy&paste sciv ... --version $(...) or a extra integration script

personally i'd prefer a entrypoint or actually using build

i recently learned that build has a entrypoint to get the project metadata, so perhaps it wouldbe a acceptable comprmise to ask build as opposed to all/random tools

nedbat commented 11 months ago

I realized that a shell command in a scriv setting is no worse than a Makefile or tox.ini full of shell commands, or any other way we have to automate local execution.

But tell me more about using build. What's the invocation, and what would that look like?

RonnyPfannschmidt commented 11 months ago

https://pypa-build.readthedocs.io/en/latest/api.html#build.util.project_wheel_metadata is the api I believe ought to be used

Once I'm back to the computer I can do a example call

nedbat commented 11 months ago

I added command: syntax in commit 951c0f8.

nedbat commented 11 months ago

command: is now released as part of scriv 1.4.0.