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

Extra spaces are added at the beginning of sub tables #256

Closed
Prudvi-data opened this issue Jan 10, 2023 · 1 comment
Closed

Extra spaces are added at the beginning of sub tables #256

Prudvi-data opened this issue Jan 10, 2023 · 1 comment

Comments

@Prudvi-data
Copy link

If a TOML file has two or more sub-tables then a simple re-write of TOML file is adding extra spaces to sub-tables.

Here is an sample tomlfile:

PlayerName = "Magnus"
PlayerAge = "31"
PlayerCountry = "Norway"

[World-Championships]
    TotalPlayed = "100"
    TotalWon = "90"
    TotalLost = "10"

    [World-Championships.Format.Classical]
        TotalPlayed = "20"
        TotalWon = "18"
        TotalLost = "2"

    [World-Championships.Format.Rapid]
        TotalPlayed = "30"
        TotalWon = "27"
        TotalLost = "3"

    [World-Championships.Format.Biltz]
        TotalPlayed = "50"
        TotalWon = "45"
        TotalLost = "5"

I am reading it and writing back with no additional changes.

from tomlkit.toml_file import TOMLFile

file_cont = TOMLFile('tomlfile').read()
TOMLFile('tomlfile').write(file_cont)

Here is the output of tomlfile after rewrite using above script.

PlayerName = "Magnus"
PlayerAge = "31"
PlayerCountry = "Norway"

[World-Championships]
    TotalPlayed = "100"
    TotalWon = "90"
    TotalLost = "10"

    [World-Championships.Format.Classical]
        TotalPlayed = "20"
        TotalWon = "18"
        TotalLost = "2"

        [World-Championships.Format.Rapid]
        TotalPlayed = "30"
        TotalWon = "27"
        TotalLost = "3"

        [World-Championships.Format.Biltz]
        TotalPlayed = "50"
        TotalWon = "45"
        TotalLost = "5"

So the last two subtables are extra indented, I see from where it is coming, will file a PR to fix it.

@ViolationHandler-exe
Copy link

ViolationHandler-exe commented Mar 1, 2023

It looks like it could be an issue with your TOML file itself, or at least how its displayed on GitHub, it displays what should be tabs as individual spaces to get to the distance it should be. Using tabs and proper tabbing in a TOML file seems to let it save perfectly fine for me. I pasted the version of the TOML file I am using, which is using specifically tabs rather than any spaces. Hope this helps 😄

PlayerName = "Magnus"
PlayerAge = "31"
PlayerCountry = "Norway"

[World-Championships]
	TotalPlayed = "100"
	TotalWon = "90"
	TotalLost = "10"

	[World-Championships.Format.Classical]
		TotalPlayed = "20"
		TotalWon = "18"
		TotalLost = "2"

	[World-Championships.Format.Rapid]
		TotalPlayed = "30"
		TotalWon = "27"
		TotalLost = "3"

	[World-Championships.Format.Biltz]
		TotalPlayed = "50"
		TotalWon = "45"
		TotalLost = "5"

frostming added a commit that referenced this issue Apr 27, 2023
Close #2576

Signed-off-by: Frost Ming <me@frostming.com>
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 a pull request may close this issue.

3 participants