Skip to content

CI: custom json formatter - #1501

Open
mgovers wants to merge 9 commits into
mainfrom
pgm/feature/custom-json-formatter
Open

CI: custom json formatter#1501
mgovers wants to merge 9 commits into
mainfrom
pgm/feature/custom-json-formatter

Conversation

@mgovers

@mgovers mgovers commented Jul 28, 2026

Copy link
Copy Markdown
Member

In light of recent events, we are aiming to reduce our amount of dependencies - in particular the npm ones. Unfortunately, that means we need to revert some of the changes in #1256 in favor of small custom scripts.

Relates to #1499

@mgovers mgovers self-assigned this Jul 28, 2026
@mgovers mgovers added dependencies Pull requests that update a dependency file improvement Improvement on internal implementation do-not-merge This should not be merged github_actions Pull requests that update GitHub Actions code labels Jul 28, 2026
Comment thread scripts/format_json.py
Comment on lines +20 to +30
REPO_PATH = Path(__file__).parent.parent.resolve()
EXCLUDE = [
re.compile(rf"{REPO_PATH}/docs/.*"),
re.compile(rf"{REPO_PATH}/package-lock\.json"),
re.compile(rf"{REPO_PATH}/\.vscode/.*"),
re.compile(rf"{REPO_PATH}/\.devcontainer/.*"),
re.compile(rf"{REPO_PATH}/tests/data/.*/input\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/.*_output.*\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/update_batch\.json"),
re.compile(rf"{REPO_PATH}/tests/unit/deprecated/data/."),
]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we need this, or there will be some ugly error-prone repeated code between the code quality workflow and this repo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd argue that if we add this custom formatter, let's also include the following three

re.compile(rf"{REPO_PATH}/tests/data/.*/input\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/.*_output.*\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/update_batch\.json"),

I don't see what's the problem. We would get a BIG PR but it's just formatting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

currently, we do a lot of compact formatting in our input/output/update. that would no longer be possible and also significantly increase test data size with literally only whitespaces due to indentation. this was also discussed when introducing biome

Comment thread .pre-commit-config.yaml
Comment thread .pre-commit-config.yaml.jinja
Comment thread package-lock.json
Comment thread package-lock.json.license
Comment thread package.json
Comment thread package.json.license
@kornerc

kornerc commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@mgovers I like to idea to get rid of npm.

One alternative came into my mind to a custom JSON formatter: Biome has standalone binaries (it’s written in Rust).
However, I think it’s unfortunately rather difficult to integrate this nicely into pre-commit and to manage the versions properly.

Unfortunately, this PR to publish Biome as Python package is currently not progressing biomejs/biome#8818

In summary I guess a custom JSON formatter - like your drafted one - might be the best solution (until there is a Python package for Biome).

@mgovers

mgovers commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

@mgovers I like to idea to get rid of npm.

One alternative came into my mind to a custom JSON formatter: Biome has standalone binaries (it’s written in Rust). However, I think it’s unfortunately rather difficult to integrate this nicely into pre-commit and to manage the versions properly.

Unfortunately, this PR to publish Biome as Python package is currently not progressing biomejs/biome#8818

In summary I guess a custom JSON formatter - like your drafted one - might be the best solution (until there is a Python package for Biome).

Hi @kornerc,

Thank you for the input. We really appreciate it, especially after the great in-depth investigation you have done so far. 🤞 fingers crossed that that PR for biome will be published soon...

@mgovers
mgovers force-pushed the pgm/feature/custom-json-formatter branch from ea9de81 to 881e110 Compare July 28, 2026 14:05
Comment thread scripts/format_json.py Outdated
Comment thread scripts/format_json.py Outdated
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

actually format json

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

update script to exclude some

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

cleanup

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

minor

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

exclude uv.lock, en/decode with utf-8-sig

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

fix ruff

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

re-add markdownlint-cli

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

Refresh lock and linter dependencies

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Apply suggestions from code review

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>

Co-authored-by: Martijn Govers <martygovers@hotmail.com>
Signed-off-by: Martijn Govers <martygovers@hotmail.com>

minor

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
@mgovers
mgovers force-pushed the pgm/feature/custom-json-formatter branch from 680e9f0 to 2489dd7 Compare July 28, 2026 14:12
@mgovers
mgovers marked this pull request as ready for review July 28, 2026 14:22
mgovers and others added 6 commits July 29, 2026 08:13
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…k-and-linter

Refresh lock and linter dependencies
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
…e/custom-json-formatter

Signed-off-by: Martijn Govers <martijn.govers@alliander.com>
@mgovers mgovers changed the title Pgm/feature/custom json formatter CI: custom json formatter Jul 29, 2026

@figueroa1395 figueroa1395 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is generally fine by me, but let's discuss with the rest of the team before proceeding.

Comment thread docs/advanced_documentation/build-guide.md
Comment thread code_generation/data/attribute_classes/input.json
Comment thread tests/data/power_flow/vision-validation-network/params.json
Comment thread scripts/format_json.py
Comment on lines +20 to +30
REPO_PATH = Path(__file__).parent.parent.resolve()
EXCLUDE = [
re.compile(rf"{REPO_PATH}/docs/.*"),
re.compile(rf"{REPO_PATH}/package-lock\.json"),
re.compile(rf"{REPO_PATH}/\.vscode/.*"),
re.compile(rf"{REPO_PATH}/\.devcontainer/.*"),
re.compile(rf"{REPO_PATH}/tests/data/.*/input\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/.*_output.*\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/update_batch\.json"),
re.compile(rf"{REPO_PATH}/tests/unit/deprecated/data/."),
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd argue that if we add this custom formatter, let's also include the following three

re.compile(rf"{REPO_PATH}/tests/data/.*/input\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/.*_output.*\.json"),
re.compile(rf"{REPO_PATH}/tests/data/.*/update_batch\.json"),

I don't see what's the problem. We would get a BIG PR but it's just formatting.

Comment thread scripts/format_json.py
echo "Running Biome"
npx biome format --write --files-ignore-unknown=true --no-errors-on-unmatched
echo "Running Json formatter"
git ls-files -z -- '*.json' '*.jsonc' | xargs -0 -r uv run --frozen scripts/format_json.py

@kornerc kornerc Jul 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

*.jsonc with comments or trailing commas cannot be loaded by json.loads().

Comment:

import json

print(json.loads(
"""
{
  // comment
  "a": 1
}
"""
))

Trailing comma:

import json

print(json.loads(
"""
{
  "a": 1,
}
"""
))

Even if json.loads() would be able to loads .jsonc files with comments, the comments would get lost.

Therefore, it might be a good decision to not format .*jsonc files

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good catch

mgovers added 2 commits August 3, 2026 09:13
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

Base automatically changed from pgm/feature/dependabot-on-specific-day to main August 3, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file do-not-merge This should not be merged github_actions Pull requests that update GitHub Actions code improvement Improvement on internal implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants