Add parameter to call which allows passing configuration to the underlying ArgumentFormatter - #91
Add parameter to call which allows passing configuration to the underlying ArgumentFormatter#91plazer1 wants to merge 11 commits into
call which allows passing configuration to the underlying ArgumentFormatter#91Conversation
|
The problem is Hyrum’s Law - we really don't want to alter how plac works, we don't know what might break down the line:
|
|
I would be happy if I could pass my custom formatter to |
|
yes, that might work, that being said we have to keep backward and python 2.7(!) compatibility |
HelpFormatter instead of RawDescriptionHelpFormatterHelpFormatter instead of RawDescriptionHelpFormatter; add a way to pass custom help formatter to call
HelpFormatter instead of RawDescriptionHelpFormatter; add a way to pass custom help formatter to callcall; add a multi-line HelpFormatter
Hmmm.... According to the readme the lowest supported version is 2.6; however, according to the source code it's actually 2.3. So which is it: 2.3, 2.6 or 2.7? |
Add mention of the new functionality to readme
Python 2 compat
…d in more complex cases
|
My implementation of the custom formatter has gotten quite complex and fragile as I kept finding more and more issues with it. After (hopefully) solving them all and working around the quirks of |
|
Thanks for following up and all the efforts and being transparent about the challenges. It may be that the tradeoffs here do warrant a merge into the main library. Adding a new feature seems attractive, but it can also lead to headaches down the line. So perhaps it would be best to keep this on the backburner for a while, let you explore this funcionality for a while, then revisit if it ends up being so useful. The best think about plac is that it is so easy to hack and vendor your private version of it. |
|
To be frank I do not understand what are you trying to tell me 😅 Are you saying you do not want to merge the PR as it currently is? Just to be clear, I already removed the new functionality. All that's left in this PR right now is the addition of keyword arguments to If you're worried about potential future clashes between arguments of |
|
What I mean is that adding just the option doesn't seem to warrant a new release. It is an interesting feature, but since we can't make a new formatter the default without potentially breaking tests, and you also noted that formatting is not that easy to implement correctly, thus making this customization relevant to only a small group, it may be best to err on the side of caution and leave things as they are. |
Not to sound spiteful, but the changes I propose here pose no risk -- there is virtually zero chance of breaking anything -- unlike the changes of 1.4.6 which completely broke I understand the position you're in -- maintaining a project you did not author. But if you don't intend to make any improvements, sooner or later somebody is going to fork and do it for you, and your project will become irrelevant. (And I had another improvement idea in mind but seeing as reluctant you are to make even such a simple, non-invasive change, I don't think I'll invest my time in opening another PR.) Addendum to the above:
I understand that. But you have to understand that this trivial code change, which allows the user to customize the behavior, is the difference between me having to maintain my fork of |
call; add a multi-line HelpFormattercall which allows passing configuration to the underlying ArgumentFormatter
|
For me backward compatibility is very important, as is keeping code as simple as possible. I do agree that the entire plac_ext might be rarely used; I have never needed it myself. But one of my greatest annoyances is when an upstream package makes gratuitous changes that break my code for reasons like cleanup, formatting, or adhering to new conventions. These shouldn't be necessary because plac isn't a library meant to gain new functionality and features. I'd like to keep plac as close to the original vision as possible. Minimal features, clean documentation; for those who need fancier features, another option may be better. The current codebase is meant to be kept functional. Over the past five years, all changes were necessary primarily because of changes in Python itself. We always respond promptly to valid problems; we fixed the one you experienced within hours. But changing things up is a much bigger ask. |
Generating parser automatically from code is a fancy feature. Possibly the fanciest feature of any argument parser, so I don't intend to switch to any other; I'd rather fork, add my functionality, get rid of "junk" I don't need ( For your reference, here is my improved interface which I made on top of mainline |
|
I think these are all interesting ideas, and perhaps the best home for them is a new package or fork that builds on the prior work. It sounds like you have a clear vision for how plac could evolve, but that vision doesn't fully align with what I'm trying to do as its maintainer. My goal is deliberately conservative: preserve backwards compatibility, keep the implementation simple, and keep plac as close as practical to its original scope and design. That means the bar for adding new functionality is intentionally quite high, even when a particular change is small or unlikely to cause breakage. That's not a judgment on the usefulness of the features you're proposing. In fact, a fork may give you much more freedom to pursue these ideas without having to repeatedly reconcile them with the constraints I've chosen for this package. I appreciate the time you've put into the proposal and the discussion, but given that difference in direction, I don't think this is something I want to merge into plac. I'm going to close this PR, and I wish you well if you decide to develop these ideas further in a fork or a separate package. |
|
After perusing through an ancient version of the documentation (is there any current documentation besides the very limited README?) I realized the functionality I am asking for has already been implemented pretty much from the beginning, albeit in a rather unconventional and currently undocumented way: It's a shame the old documentation was (seemingly?) lost to time, because it contained lots of information that is still relevant to the current version but not present in the README. Quoting from the (14 years old!) documentation:
Another currently-undocumented cool feature, used by my
|
This PR adds the possibility to use a custom help formatter via
plac.call(..., formatter_class=MyCustomFormatter). By using a custom formatter, users can e.g. preserve newlines in help strings of arguments (as well as the main program description, which is currently already possible).This PR also adds
__pycache__to.gitignore.Code:
Current output with
RawDescriptionHelpFormatter:Example output with
RawTextHelpFormatter: it preserves the text verbatim -- does not strip and de-dent the description text, nor replace newlines with spaces: