Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/misc/scripts/dotnet_format.py
9896 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import glob
5
import os
6
import sys
7
8
if len(sys.argv) < 2:
9
print("Invalid usage of dotnet_format.py, it should be called with a path to one or multiple files.")
10
sys.exit(1)
11
12
# Create dummy generated files, if needed.
13
for path in [
14
"modules/mono/SdkPackageVersions.props",
15
]:
16
if os.path.exists(path):
17
continue
18
os.makedirs(os.path.dirname(path), exist_ok=True)
19
with open(path, "w", encoding="utf-8", newline="\n") as f:
20
f.write("<Project />")
21
22
# Avoid importing GeneratedIncludes.props.
23
os.environ["GodotSkipGenerated"] = "true"
24
25
# Match all the input files to their respective C# project.
26
projects = {
27
path: " ".join([f for f in sys.argv[1:] if os.path.commonpath([f, path]) == path])
28
for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
29
}
30
31
# Run dotnet format on all projects with more than 0 modified files.
32
for path, files in projects.items():
33
if files:
34
os.system(f"dotnet format {path} --include {files}")
35
36