Quality: Added option for automatic download for autoformat too

* We now download "biome" standalone binaries for use on some files files, JSON now, and that breaks the check to not have it.
This commit is contained in:
Kay Hayen
2025-09-18 10:48:03 +02:00
parent 2888795573
commit 9ed85d76fd
5 changed files with 23 additions and 10 deletions

View File

@@ -29,11 +29,13 @@ fi
# Autoformat the files.
if [ "$COMMIT_UNCHECKED" != "1" ]
then
OPTIONS="--from-commit --assume-yes-for-downloads"
if [ -f "bin/autoformat-nuitka-source" ]
then
exec ./bin/autoformat-nuitka-source --from-commit
exec ./bin/autoformat-nuitka-source $OPTIONS
else
exec python -m pipenv run python Nuitka-develop/bin/autoformat-nuitka-source --from-commit
exec python -m pipenv run python Nuitka-develop/bin/autoformat-nuitka-source $OPTIONS
fi
fi

View File

@@ -109,7 +109,7 @@ jobs:
sudo apt-get update
sudo apt-get install clang-format-21
python ./bin/autoformat-nuitka-source --check-only
python ./bin/autoformat-nuitka-source --check-only --assume-yes-for-downloads
if: matrix.python_version == '3.9'
mac-python3:

View File

@@ -46,7 +46,7 @@ from nuitka.utils.FileOperations import (
)
from nuitka.utils.Utils import isWin32OrPosixWindows
from .BiomeFormatter import cleanupJsonFile
from .BiomeFormatter import formatJsonFile
from .YamlFormatter import formatYaml
# black no longer supports Python 2 syntax, and sometimes removes import
@@ -618,6 +618,7 @@ def autoFormatFile(
limit_json=False,
ignore_errors=False,
ignore_yaml_diff=True,
assume_yes_for_downloads=False,
): # a bit many knobs but that's fine, pylint: disable=too-many-arguments
"""Format source code with external tools
@@ -830,7 +831,9 @@ def autoFormatFile(
elif is_jpeg:
_cleanupJpegImage(tmp_filename)
elif is_json:
cleanupJsonFile(tmp_filename)
formatJsonFile(
tmp_filename, assume_yes_for_downloads=assume_yes_for_downloads
)
_cleanupTrailingWhitespace(tmp_filename)
_transferBOM(filename, tmp_filename)

View File

@@ -10,7 +10,6 @@
import os
from nuitka.Options import assumeYesForDownloads
from nuitka.utils.Download import getCachedDownload
from nuitka.utils.Execution import check_call
from nuitka.utils.FileOperations import addFileExecutablePermission
@@ -19,7 +18,7 @@ from nuitka.utils.Utils import getArchitecture, getOS
_biome_path = None
def getBiomeBinaryPath():
def getBiomeBinaryPath(assume_yes_for_downloads=False):
"""
Downloads and returns the path to the biome executable.
"""
@@ -82,7 +81,7 @@ def getBiomeBinaryPath():
flatten=False,
message="Nuitka will make use of 'biome' to format JSON files.",
reject=None,
assume_yes_for_downloads=assumeYesForDownloads(),
assume_yes_for_downloads=assume_yes_for_downloads,
download_ok=True,
)
@@ -91,10 +90,10 @@ def getBiomeBinaryPath():
return _biome_path
def cleanupJsonFile(filename):
def formatJsonFile(filename, assume_yes_for_downloads):
# Many tools work on files, and when they do, they need to be told to
# treat it as a JSON file.
biome_path = getBiomeBinaryPath()
biome_path = getBiomeBinaryPath(assume_yes_for_downloads=assume_yes_for_downloads)
if biome_path:
command = (

View File

@@ -52,6 +52,14 @@ def main():
Defaults to off.""",
)
parser.add_option(
"--assume-yes-for-downloads",
action="store_true",
dest="assume_yes_for_downloads",
default=False,
help="""Allow download and execution of tools if needed. Default is %default.""",
)
parser.add_option(
"--yaml",
action="store_true",
@@ -179,6 +187,7 @@ Defaults to off.""",
limit_rst=options.rst,
limit_md=options.md,
limit_json=options.json,
assume_yes_for_downloads=options.assume_yes_for_downloads,
):
result += 1