Skip to content
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

Fix invalid newline inside inline-table #12

Merged
merged 3 commits into from
Mar 1, 2022

Conversation

abravalheri
Copy link
Contributor

Hello, this is a possible approach to fix #11.

The approach I took here was to pass the entire table object to the order_keys function, so it can be inspected to determine when it is appropriate (or not) to add an empty line.

I understand that the changes here might not be exactly what you have in mind, so please feel free to close this PR or ask for changes, I will be happy to implement them.

@@ -30,18 +30,18 @@ def fmt_project(parsed: TOMLDocument, conf: Config) -> None:
opt_deps = cast(Table, project["optional-dependencies"])
for value in opt_deps.values():
normalize_pep508_array(cast(Array, value), conf.indent)
order_keys(opt_deps.value.body, (), sort_key=lambda k: k[0])
order_keys(opt_deps, (), sort_key=lambda k: k[0])

for of_type in ("scripts", "gui-scripts", "entry-points", "urls"):
if of_type in project:
table = cast(Table, project[of_type])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a completely side-note here, you can also use AbstractTable in the places you are not sure if you are handling Table or InlineTable.

}
beta = {C = "c",D = "d"
}
alpha = {"A.A" = "a",B = "b"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads badly, can we add a space between , for inline tables? 🤔 while we're at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I was about to ask if that was an stylistic decision, but I suppose it was not 😄

I can give it a try, but currently tomlkit does not support that. So any solution I propose might sound hacky (I am afraid).

Copy link
Contributor Author

@abravalheri abravalheri Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat, I gave it a try in abravalheri#2, but the outcome was not very good.

Indeed, when I solve this problem, I introduce a different one.

I think the best course of action here is to add the sorting capability directly in tomlkit (or fixing its issue with the reminiscent whitespaces), then proceed doing the change here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to follow-up on that then, let's accept this as is, one bugfix at a time.

Signed-off-by: Bernát Gábor <[email protected]>
@gaborbernat gaborbernat merged commit 7e56eb2 into tox-dev:main Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pyproject-fmt adding new line to inline-table
2 participants