-
Notifications
You must be signed in to change notification settings - Fork 131
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
pyproject.toml (PEP 518) support #42
Comments
Just spent some time reading the PEP and I'm open to adding it to the project at some point. |
To clarify what you meant is bumpversion reading pyproject.toml for its configuration? |
Yes. Read config from pyproject.toml instead of setup.cfg or .bumpversion.cfg. :) |
Though its your call, I would suggest dropping support for |
This is the case for Python projects. However, pojects done in another language can also benefit from bumpversion, and there it does not make sense to have either |
Did a bit of hacking on this, it's a little awkward to fit in with the current scheme of looking in multiple places, having to use separate parsers for different configs etc.. Found that TOML is a much better fit than INI in general, because it natively supports booleans, arrays, nested tables and so on, rather than having to hack in equivalents. For this reason, I would recommend supporting a That said, we need to be cautious about writing back to |
I agree with the suggestion of |
I like @clbarnes's suggestion -- support for TOML (in general) with |
Has there been any update on this? |
Having thought about it, I don't think this is a good idea under bump2version's current mode of operation. It rewrites the config file every time, and when you have a lot of tools which depend on the same config, that's not necessarily desirable. TOML is much more flexible in layout than INI, and supports comments - you'll want to keep that if you have a big complex pyproject file. The tomlkit library can persist formatting and comments but is a bit awkward for everything else. In an ideal world, a tool like bumpversion could store the current version in an external file, and only store config (which arguably the current version is not) in the config file. But that's possibly too major a departure. |
Here is the awesome-pyproject list. It would be helpful if and when bump2version supports pyproject.toml to notify the list maintainer or submitting a PR to update the list indicating that bump2version supports the file now. Just FYI. :) |
Any updates on this? |
Why don't we use bump2version to update the .toml then? With this, it is not rewriting everything but only updating/string-replacing the version. |
To me, that strays into parsing HTML with regex territory. I wouldn't want to bet that no tool will ever use a key ambiguous with our query. |
Sorry for derailing the discussion with my comment. I was not talking about parsing. I see the danger in rewriting the toml by parsing and then pretty-printing everything just to write the version.. But actually I found already a PR for this: #90 (where it's also explained why this is bad). |
To clarify, has |
@adam-grant-hendry I don't think that it is already merged. As @clbarnes states:
In most cases, using pyproject.toml with a PEP517 build backend and other options might not be a good idea. In addtion to that, PEP621 must be taken into account, which implies a PEP440 version identifier called The basic problem here is, that configuration file is re-used, which must be abstracted. Next what must be concerned is the configuration file format. [bump2version:file:src/main.py]
search = __VERSION__ = {current_version}
replace = __VERSION__ = {new_version} might become [tool.bump2version.file."src/main.py"]
search = "__VERSION__ = {current_version}"
replace = "__VERSION__ = {new_version}" or [[tool.bump2version.file]]
file="src/main.py"
search = "__VERSION__ = {current_version}"
replace = "__VERSION__ = {new_version}" The first one is more straight forward, but the last one offers the ability to do as follows: [[tool.bump2version.file]]
glob="**/__init__.py"
search = "__VERSION__ = {current_version}"
replace = "__VERSION__ = {new_version}" which is more intuitive. I'll try create a refactoring of the configuration within the next days which might enable the on-going development and discussion. |
I'd advise against adding
|
While I have nothing against a project specific toml file, much of the appeal of pyproject.toml support is to avoid having a separate config file for each tool in a project. Perhaps a compromise would be to (by default) support a specifically named toml file, and then provide a command-line option to override. Ex: maybe by default it looks for |
IMO this appeal only applies to, as the name |
Regarding the TOML file format, we could allow the files = [
"src/main.py",
"pyproject.toml",
{ path="foo.json", search = 'version: "{current_version}"', replace = 'version: "{new_version}"' },
] as alternative to [[files]]
path="src/main.py"
[[files]]
path="pyproject.toml"
[[files]]
path="foo.json"
search = 'version: "{current_version}"'
replace = 'version: "{new_version}"' |
I do see your point that bump2version is not a Python-specific tool, having said that, all of those examples you gave (except If my project is a Python project then I'd like to configure all my tools in a single file. This is why I suggest having the option to support either |
I think we shouldn't mix things up. Though mentioned otherwise, adding support for If you do not (wish to) use Although, there might be a tendency to use a toml-based configurattion file over So I think we should consider adding support for Using an ini-based, toml-based, yaml-based or json-based configuration will result in python always in So, if we just imagine, the support for What I've seen so far is that implementations vary. Some prefer the usage of pyproject.toml over their own configuration, some prefer their own configuration. My gut instincts tend to tell my the letter should be the preferred way. In short, the following sequence of searching / reading configuration should be used:
In order to make things more easy for the user, the configuration files 1-3 should be written back. If a pyproject.toml is used. the configuration entries for modifying the version numbers should be added automatically unless the user configures it differently. This will help, keeping the PEP621 entries PEP440 compliant. This should be easy to implement, if I understand the existing implementation correctly. |
Just a minor point:
I'd suggest a minor tweak to the resolution order above: bumpversion-specific files should always be sought before generic files, because plenty of projects could have a
Having had a couple of years to mull over this issue, I think I too am personally coming down on the side of a specific config file rather than writing back to the pyproject.toml, especially as all of bumpversion's config would be nested pretty deep into the pyproject, and deep nesting is not handled very ergonomically by TOML. Certainly that would be the easiest first pass, and it helps establish bumpversion as a project-agnostic tool (albeit one with a particularly strong relationship with python). But there seems to be a fair amount of appetite for building it into a shared config file and it may not be all that difficult.
I do have an opinion on this: moving from INI to TOML is strictly an upgrade which drastically improves the complexity and maintainability of the tool (once INI support is actually deprecated, of course). INI was a mistake (globally, that is; not one made specifically by bumpversion). That there will be a transition period where both forms is supported is IMO merely an unfortunate hangover from those dark days; not a design goal. I think that supporting multiple config formats as a feature would complicate the lives of contributors, maintainers, and users for very little benefit: sure, there are YAML enthusiasts out there and javascripters inexplicably love hand-writing JSON, but I don't think supporting them all really makes bumpversion any more attractive a solution. "There should be one-- and preferably only one --obvious way to do it." |
With these two updates,
|
Thanks @adam-grant-hendry for pointing out all the recent development around version management. It looks like it become more and more standardized by the day. I also recently discovered Poetry's For instance, how do you manage a set of version upgrade rules? In my project I have a special rule in my [bumpversion:file:./changelog.md]
search = {{gh}}`{current_version} (unreleased)
replace = {{gh}}`{new_version} (unreleased) Do you suggest to replace these rules with a custom Python script? Why not. After all, I ended up writing my own changelog version management code and a quite convoluted GitHub workflow, as nowadays, version management is a complex mix of version bump, tagging, building, packaging and publishing (on PyPi). |
@kdeldycke Unfortunately (I say this because I have loved Had If any work is to be done, I recommend it be toward using a plugin or creating one that suites your needs. Sadly, there's not much of a selling point for me to use
I might've kept |
https://github.com/monim67/poetry-bumpversion is a much neatier solution. |
FYI, Good new, the last For more information, see: #268 |
- Use [`poetry-bumpversion`](https://pypi.org/project/poetry-bumpversion/) for version number updates instead of bump2version as bump2version is no longer being maintained c4urself/bump2version#42 (comment). ------ Co-authored-by: Shan Raza <13048456+shaneahmed@users.noreply.github.com> Co-authored-by: John Pocock <John-P@users.noreply.github.com>
Hi, I was wondering if there were plans for
pyproject.toml
support.see: peritus/bumpversion#192, PEP 518
The text was updated successfully, but these errors were encountered: