summaryrefslogtreecommitdiffstats
path: root/misc/scripts/dotnet_format.py
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-05-08 18:22:59 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-05-08 18:22:59 +0200
commit4778b24366fbcc216d9d59fafbbb7505c371dd1d (patch)
tree50aacf8bab9ce654952356dff875084bd9af7d03 /misc/scripts/dotnet_format.py
parent15d20000fafeb511e34f1687e5a1b68ace60b226 (diff)
parentdf969ff7426d61c8d32f3a89ec461b47b34e83b2 (diff)
downloadredot-engine-4778b24366fbcc216d9d59fafbbb7505c371dd1d.tar.gz
Merge pull request #91597 from Repiteo/ci/pre-commit-handle-everything
CI: Overhaul static checks to use `pre-commit`
Diffstat (limited to 'misc/scripts/dotnet_format.py')
-rw-r--r--misc/scripts/dotnet_format.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/misc/scripts/dotnet_format.py b/misc/scripts/dotnet_format.py
index 83265be7c5..51fd7a1223 100644
--- a/misc/scripts/dotnet_format.py
+++ b/misc/scripts/dotnet_format.py
@@ -5,10 +5,16 @@ import glob
import os
import sys
-# Create dummy generated files.
+if len(sys.argv) < 2:
+ print("Invalid usage of dotnet_format.py, it should be called with a path to one or multiple files.")
+ sys.exit(1)
+
+# Create dummy generated files, if needed.
for path in [
"modules/mono/SdkPackageVersions.props",
]:
+ if os.path.exists(path):
+ continue
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w", encoding="utf-8", newline="\n") as f:
f.write("<Project />")
@@ -17,14 +23,12 @@ for path in [
os.environ["GodotSkipGenerated"] = "true"
# Match all the input files to their respective C# project.
-input_files = [os.path.normpath(x) for x in sys.argv]
projects = {
- path: [f for f in sys.argv if os.path.commonpath([f, path]) == path]
+ path: " ".join([f for f in sys.argv[1:] if os.path.commonpath([f, path]) == path])
for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
}
# Run dotnet format on all projects with more than 0 modified files.
for path, files in projects.items():
- if len(files) > 0:
- command = f"dotnet format {path} --include {' '.join(files)}"
- os.system(command)
+ if files:
+ os.system(f"dotnet format {path} --include {files}")