-
Notifications
You must be signed in to change notification settings - Fork 59
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
Max Line Length for Pretty-Format-ToML / Don't reformat multiline strings? #39
Comments
@Skylion007 thanks a lot for the reporting. I'm mentioning the "if" because we depend on an external library for doing the toml parsing and formatting and I'm not sure that the library supports it (or if there are other libraries that do it). Side note: While checking #26 I've also noticed that the current |
@macisamuele Seems like there is a quick and dirty fix here: uiri/toml#236 (comment) |
This one also seems like it could do the job: https://github.com/jumpscale7/python-pretty-toml/ |
This is also a blocker for adoption for me, since pretty much all of the TOML files I use are heavily commented. Like on #26 , both problems should be pretty neatly solved by switching to tomlkit which has preserving comments, order, indentation and line breaks as its primary design goal. Its actively maintained, supports the latest 1.0.0 draft spec and seems to be pretty well-regarded ( I couldn't find an explicit feature for reflowing line length automatically at least after skimming the code, but you can use it for interactive editing so its possible that could be added or done with some work, but at least it will respect your existing multi-line strings and other formatting (important for me). The API should be identical or nearly so, so it should be close to a drop-in with at most a few lines of changes, and has pretty minimal dependencies. I'd be happy to go ahead with it, though if @Skylion007 you want to take it that's fine too of course. |
@Skylion007 That looks like a really interesting option that seems to do a lot more explict prettifying than a straight parser like toml or tomlkit. However, it only has 8 stars, no releases and hasn't been touched in over two years, since shortly before 0.4.0 was first released (two major versions behind the current 1.0.0rc2 spec), and implements a number of somewhat idiosyncratic rules with no apparent customizability (e.g. tabs for separating comments, hardcoded 2 space indents, hardcoded 120 character line length, mandatory key ordering, etc) which will likely be problematic for many users since there is no accepted style standard to TOML that would justify a Black-like approach. So, it certainly might be something to base future work on, but as-is I would recommend dropping in tomlkit for now and considering perhaps adding something like that for the future. What are your thoughts? |
@CAM-Gerlach Yeah, probably right. Might be something to consider forking and fixing up though. As an end user, all I care is that it works and is customizable (or at the very least has sensible defaults / hard coding). |
@CAM-Gerlach Feel free to go ahead and tackle it and switcher over to tomlkit. |
@Skylion007 @CAM-Gerlach about TOML support comments, the About the multiline issue, my 2cents would be:
Again (as in #40) I'd like to limit as much as possible the amount of customisation on the provided tool |
I checked tomlkit and seems promising. This night/tomorrow I'll try to publish a PR addressing the different concerns. I'll keep you posted |
@macisamuele Thanks. AFAIK comments are still unsupported in uiri/toml , per uiri/toml#77 and empirical testing. They appear open to a PR, but it appears to be a pretty substantial change vs. switching to a drop-in replacement package. It also doesn't preserve indentation as does tomlkit, which is commonly used (as suggested in the spec) to make TOML easier to read, especially with nested tables. Ideally it would conform indentation to a specific standard automatically instead of just preserving it, but you should be able to use tomlkit's API to enforce that on the "AST" equivalent rather than with manual string munging, either now or at some point in the future. |
About comments, toml kinda support the but in a very very limited and bugged fashion. I've tried to fix it in the code but feels way far from easy. A substantial change does not concern me too much as far as maintainable. About table indentation is not clear to me what you mean. My opinion is that we should force indentation to not be present or always present (accordingly to what is easier except if we have stronger arguments) |
I'm talking about using indents to make the hierarchical table structure clear, just as its used in most/all other config formats and programming languages. E.g. [general]
spam = "eggs"
[subtable]
sub_item = "foo"
sub_item_2 = "bar" Automatically applying the correct indentation is the "prettyfying" task that in my experience takes the most effort by hand, and it would be a big win to include it, but if that's out of scope here, it should at least be preserved for now (as tomlkit does by default) to avoid making existing TOML files less readable, as removing all indentation would. For a small, flat config file, it doesn't matter so much, but it makes a huge difference on larger ones with more nesting; e.g. this one would be much harder to understand without it. The only things that need be customizable, IMO, are the indentation character and a |
#46 has been merged and released in v2.0.0 Closing this for now. |
I tried running it on my project and it made my toml file very difficult to read with it's long exclude pattern.: facebookresearch/habitat-sim@91f8ea5
Enforcing a max line length would do wonders for readability in this case or at least not collapsing multiline strings like that.
Alternative not destroying multiline strings woudl also be helpful.
The text was updated successfully, but these errors were encountered: