changelog-cli
changelog-cli copied to clipboard
Change the version number in custom files as well
changelog-cli tries to determine the appropriate next version number for the project. But the changelog is never (?) the only place in the repo that stores the version number.
There's often a VERSION or a _version.py, setup.py etc. file that actually stores the machine-readable version number.
changelog-cli could be configured to update these locations at the same time, so all the copies of the version number stay consistent.
How could it work?
We could have a .changelog-cli config file in the root of the repo.
Inside, we could have a mapping of filepaths to regexes.
Each filepath would be a file that contains a version that needs updating, and the regex would tell changelog-cli where to find the version number within the filepath. Something like:
[Version Files]
src/changelog/_version.py: '__version__\s*=\s*(\S*)'
setup.py: 'version=(\S*)'
In this example (using Python's configparser format) changelog-cli release would not only modify the CHANGELOG, but also src/changelog/_version.py and setup.py. In each, it would use the regex to find the version. The contents of the "group 1" of each match would be replaced with the new version number.
The exact file format of the .changelog-cli file could be something that Python supports in the standard library (json or configparser), so there would be no additional dependencies needed and we wouldn't need to implement a new parser.
Another nice benefit of having a config file would be having a place to include other settings, like one for controlling the creation of a table of contents within the CHANGELOG (#14) (Although there are probably easier ways to do that).
I love this idea.
Currently, most of my uses of the tool are in bash files that do that update outside of the tool (using the cl suggest command and sed). This worked well for doing _version.py or __init__.py replacements of __version__, but I never considered adding it directly to the cli tool. Few other places to look out for would be things like README.md for badges and other docs.
As somewhat of a minimalist, I hate requiring more rc files for users. So while I am all for supporting things like a .changelog-cli for a project, I would ask that it supports the python communities shared configuration of also looking at a setup.cfg. A lot of the other tools in my toolchains these days (mypy, pylint, pep8, yapf, pytest) all honor either RC files or setup.cfg so picking whatever hierarchical config reader from one of those would be preferable.