Skip to content

Commit 8f50b18

Browse files
committed
update and improve scripts
1 parent 3deffd2 commit 8f50b18

File tree

5 files changed

+91
-60
lines changed

5 files changed

+91
-60
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
commit 3deffd2602e6c1cdc1debd5ece0a161096339a85
2+
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
3+
Date: Mon Aug 4 06:34:31 2025 +0700
4+
5+
add new scripts for get version and create headers
6+
17
commit 3be5a1951f352b20d1eb404d01400d565c1b37fd
28
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
39
Date: Mon Aug 4 06:24:33 2025 +0700

format-code.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,60 @@
22
import subprocess
33
import argparse
44

5+
56
def find_source_files(root_dir, ignore_dirs):
67
source_files = []
78
for dirpath, dirnames, filenames in os.walk(root_dir):
89
# Remove ignored directories from dirnames to prevent walking into them
910
dirnames[:] = [d for d in dirnames if d not in ignore_dirs]
10-
11+
1112
for filename in filenames:
12-
if filename.endswith(('.c', '.cpp', '.h', '.hpp', '.cc', '.cxx', '.hh')):
13+
if filename.endswith((".c", ".cpp", ".h", ".hpp", ".cc", ".cxx", ".hh")):
1314
source_files.append(os.path.join(dirpath, filename))
1415
return source_files
1516

17+
1618
def format_files(files, clang_format, style):
1719
for file in files:
1820
try:
19-
cmd = [clang_format, '-i', '--style', style, file]
21+
cmd = [clang_format, "-i", "--style", style, file]
2022
subprocess.run(cmd, check=True)
2123
print(f"\033[32mFormatted:\033[0m {file}")
2224
except subprocess.CalledProcessError as e:
2325
print(f"\033[31mError formatting {file}:\033[0m {e}")
2426

27+
2528
def main():
26-
parser = argparse.ArgumentParser(description="Recursively format C/C++ files with clang-format")
29+
parser = argparse.ArgumentParser(
30+
description="Recursively format C/C++ files with clang-format"
31+
)
2732
parser.add_argument("root_dir", help="Root directory to search for source files")
2833
parser.add_argument("--ignore", nargs="+", default=[], help="Directories to ignore")
29-
parser.add_argument("--clang-format", default="clang-format", help="Path to clang-format executable")
30-
parser.add_argument("--style", default="file", help="Formatting style (file/Google/LLVM/etc.)")
31-
34+
parser.add_argument(
35+
"--clang-format", default="clang-format", help="Path to clang-format executable"
36+
)
37+
parser.add_argument(
38+
"--style", default="file", help="Formatting style (file/Google/LLVM/etc.)"
39+
)
40+
3241
args = parser.parse_args()
33-
42+
3443
print("\033[36m=== C/C++ Source Formatter ===\033[0m")
3544
print(f"\033[33mRoot directory:\033[0m {args.root_dir}")
3645
print(f"\033[33mIgnored directories:\033[0m {args.ignore or 'None'}")
3746
print(f"\033[33mStyle:\033[0m {args.style}")
3847
print("\033[36m" + "=" * 30 + "\033[0m")
39-
48+
4049
source_files = find_source_files(args.root_dir, args.ignore)
41-
50+
4251
if not source_files:
4352
print("\033[33mNo C/C++ files found to format.\033[0m")
4453
return
45-
54+
4655
print(f"\033[33mFound {len(source_files)} files to format:\033[0m")
4756
format_files(source_files, args.clang_format, args.style)
4857
print("\033[32mFormatting complete!\033[0m")
4958

59+
5060
if __name__ == "__main__":
5161
main()

getversion.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,86 @@
33
import re
44

55

6-
class GitVersion():
6+
class GitVersion:
77
def __init__(self):
8-
self._default_version = '0.1.0'
8+
self._default_version = "0.1.0"
99
os.chdir(os.path.dirname(os.path.realpath(__file__)))
10-
10+
1111
@property
1212
def tag(self):
1313
stream = os.popen("git describe --match v[0-9]* --abbrev=0 --tags")
1414
return stream.read().strip()
1515

16+
@property
17+
def nightfreeze(self):
18+
stream = os.popen("git describe --match night-freeze* --abbrev=0 --tags")
19+
return stream.read().strip()
20+
1621
@property
1722
def version(self):
1823
version = f"{self.tag[1:]}.{self.build}"
19-
20-
if version == '.':
24+
25+
if version == ".":
2126
return self._default_version
22-
27+
2328
return version
24-
29+
2530
@property
2631
def default_branch(self):
27-
stream = os.popen('git config --get init.defaultBranch')
32+
stream = os.popen("git config --get init.defaultBranch")
2833
result = stream.read().strip()
29-
34+
3035
if not result:
3136
result = "main"
32-
37+
3338
return result
34-
39+
3540
@property
3641
def build(self):
3742
stream = os.popen("git rev-list {}.. --count".format(self.tag))
3843
return stream.read().strip()
39-
44+
4045
@property
4146
def branch(self):
42-
stream = os.popen('git branch --show-current')
47+
stream = os.popen("git branch --show-current")
4348
return stream.read().strip()
44-
49+
4550
@property
4651
def full(self):
4752
return f"{self.version}-{self.branch}"
48-
53+
4954
@property
5055
def standard(self):
51-
standard = f'{self.version}-{self.branch}'
56+
standard = f"{self.version}-{self.branch}"
5257
if self.branch == self.default_branch or re.match("release/.*", self.branch):
53-
standard = f'{self.version}'
58+
standard = f"{self.version}"
5459
return standard
55-
60+
5661
@property
5762
def commit(self):
5863
stream = os.popen("git rev-parse HEAD")
5964
return stream.read().strip()
60-
65+
6166
@property
6267
def commit_hash(self):
6368
stream = os.popen("git rev-parse --short HEAD")
6469
return stream.read().strip()
65-
70+
6671
def __str__(self):
67-
return f'''
72+
return f"""
6873
Tag: {self.tag}
6974
Version: {self.version}
7075
Full: {self.full}
7176
Branch: {self.branch}
7277
Build: {self.build}
7378
Standard: {self.standard}
7479
Commit: {self.commit}
80+
Night freeze: {self.nightfreeze}
7581
7682
SLeaf-LLVM {self.full} {self.commit_hash}
77-
'''
83+
"""
7884

7985

80-
if __name__ == '__main__':
86+
if __name__ == "__main__":
8187
git_version = GitVersion()
8288
print(git_version)

scripts/create_headers.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@
33
import sys
44

55

6+
def create_h_for_c_file(cpp_path):
7+
hpp_path = cpp_path.with_suffix(".hpp")
8+
if not hpp_path.exists():
9+
hpp_path.touch()
10+
11+
612
def create_hpp_for_cpp_file(cpp_path):
7-
hpp_path = cpp_path.with_suffix('.hpp')
13+
hpp_path = cpp_path.with_suffix(".hpp")
814
if not hpp_path.exists():
915
hpp_path.touch()
1016

1117

1218
def process_directory(source_dir):
1319
for root, _, files in os.walk(source_dir):
1420
for file in files:
15-
if file.endswith(('.cpp', '.cxx')):
21+
if file.endswith((".cpp", ".cxx")):
1622
cpp_path = Path(root) / file
1723
create_hpp_for_cpp_file(cpp_path)
24+
if file.endswith((".c",)):
25+
c_path = Path(root) / file
26+
create_h_for_c_file(c_path)
1827

1928

20-
if __name__ == '__main__':
29+
if __name__ == "__main__":
2130
source_directory = Path(sys.argv[1])
2231
process_directory(source_directory)

scripts/getversion.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import re
44

55

6-
class GitVersion():
6+
class GitVersion:
77
def __init__(self):
8-
self._default_version = '0.1.0'
8+
self._default_version = "0.1.0"
99
os.chdir(os.path.dirname(os.path.realpath(__file__)))
10-
10+
1111
@property
1212
def tag(self):
1313
stream = os.popen("git describe --match v[0-9]* --abbrev=0 --tags")
@@ -16,55 +16,55 @@ def tag(self):
1616
@property
1717
def version(self):
1818
version = f"{self.tag[1:]}.{self.build}"
19-
20-
if version == '.':
19+
20+
if version == ".":
2121
return self._default_version
22-
22+
2323
return version
24-
24+
2525
@property
2626
def default_branch(self):
27-
stream = os.popen('git config --get init.defaultBranch')
27+
stream = os.popen("git config --get init.defaultBranch")
2828
result = stream.read().strip()
29-
29+
3030
if not result:
3131
result = "main"
32-
32+
3333
return result
34-
34+
3535
@property
3636
def build(self):
3737
stream = os.popen("git rev-list {}.. --count".format(self.tag))
3838
return stream.read().strip()
39-
39+
4040
@property
4141
def branch(self):
42-
stream = os.popen('git branch --show-current')
42+
stream = os.popen("git branch --show-current")
4343
return stream.read().strip()
44-
44+
4545
@property
4646
def full(self):
4747
return f"{self.version}-{self.branch}"
48-
48+
4949
@property
5050
def standard(self):
51-
standard = f'{self.version}-{self.branch}'
51+
standard = f"{self.version}-{self.branch}"
5252
if self.branch == self.default_branch or re.match("release/.*", self.branch):
53-
standard = f'{self.version}'
53+
standard = f"{self.version}"
5454
return standard
55-
55+
5656
@property
5757
def commit(self):
5858
stream = os.popen("git rev-parse HEAD")
5959
return stream.read().strip()
60-
60+
6161
@property
6262
def commit_hash(self):
6363
stream = os.popen("git rev-parse --short HEAD")
6464
return stream.read().strip()
65-
65+
6666
def __str__(self):
67-
return f'''
67+
return f"""
6868
Tag: {self.tag}
6969
Version: {self.version}
7070
Full: {self.full}
@@ -74,9 +74,9 @@ def __str__(self):
7474
Commit: {self.commit}
7575
7676
Domkrat3D {self.full} {self.commit_hash}
77-
'''
77+
"""
7878

7979

80-
if __name__ == '__main__':
80+
if __name__ == "__main__":
8181
git_version = GitVersion()
8282
print(git_version)

0 commit comments

Comments
 (0)