Skip to content

Commit 3ee5ae5

Browse files
authored
Fixes (#155)
* Remove unused OpenAI code conversion script The script was a one-off helper for porting SDK examples between languages. It was never wired into any generate script or workflow and required an openai package that the repo never declared. * Add "make mypy" to type check own Python scripts Run mypy in strict mode over everything except submodules, which are generated SDKs checked in their own repos, and annotate the scripts that were still untyped so the target passes. Switch black to --extend-exclude, since --exclude replaces its default exclude list and would make it walk the new .mypy_cache directory. * Fix version bump leaving the SDKs on mixed versions Match changelog headers on whole lines. "## 4.26.4" is a substring of both "## 4.26.4+1" and "## 4.26.41", so a patch release or a double-digit month silently suppressed the next entry, leaving a Dart package version with no matching CHANGELOG entry. Validate year, month and patch in argparse and check every file the release touches exists before the first write. "new-version.py 26 13" used to rewrite two configs and then die on ValueError, leaving the remaining seven SDKs on the old version. Update the Swift changelog alongside the Dart one. It had already fallen a release behind the Swift config. * Fail file splitters when no parts match The C# and Java splitters exited 0 having split nothing when the copyright banner regex found no matches, so a changed banner would ship un-split API files and surface much later as a compile error. Raise instead, and replace the equivalent assert in the PHP splitter so python -O cannot strip it. * Drive the version bump from a single SDK table The config paths, the release file list and the nine set_*_version functions repeated the same nine SDKs four times over. Adding an SDK meant touching all four. Collapse them into one SDKS tuple. The config is always codegen/config-<name>.json and the changelog, where there is one, is always submodules/<name>/CHANGELOG.md, so the name derives both, and the version format defaults to the plain YY.M.P that seven of the nine use. Adding an SDK is now one line.
1 parent 43cb632 commit 3ee5ae5

8 files changed

Lines changed: 150 additions & 202 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ bin/
1010
codegen/.generated/
1111
codegen/debug*.json
1212
obj/
13+
.mypy_cache/

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ format: format-black
66

77
.PHONY: format-black
88
format-black:
9-
python -m black --line-length=120 --exclude submodules -v .
9+
python -m black --line-length=120 --extend-exclude submodules -v .
10+
11+
# Type check our own scripts, SDKs in submodules have their own checks
12+
.PHONY: mypy
13+
mypy:
14+
python -m mypy --config-file $(CURDIR)/mypy.ini .
1015

1116
.PHONY: update
1217
update:

codegen/Tools/split-cs-file.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import errno
55
import os
66
import re
7+
import typing
78

89
SPLIT_RE = re.compile(
910
r'//\s+[-]+\n//\s+<copyright company="Aspose" file="(?P<file>.+?\.cs)">',
1011
re.MULTILINE,
1112
)
1213

1314

14-
def main(src_file, dst_dir):
15+
def main(src_file: typing.IO[str], dst_dir: str) -> None:
1516
remaining = src_file.read()
1617
try:
1718
os.makedirs(dst_dir)
@@ -20,7 +21,10 @@ def main(src_file, dst_dir):
2021
if e.errno != errno.EEXIST:
2122
raise
2223

23-
for match in reversed(list(SPLIT_RE.finditer(remaining))[1:]):
24+
found = list(reversed(list(SPLIT_RE.finditer(remaining))[1:]))
25+
if not found:
26+
raise SystemExit("No parts matching regex '%s' found in %s" % (SPLIT_RE.pattern, src_file.name))
27+
for match in found:
2428
start_pos = match.span()[0]
2529

2630
with open(os.path.join(dst_dir, match.groupdict()["file"]), "wt") as out_f:
@@ -34,14 +38,14 @@ def main(src_file, dst_dir):
3438
src_file.close()
3539

3640

37-
def parse_args():
41+
def parse_args() -> argparse.Namespace:
3842
parser = argparse.ArgumentParser()
3943
parser.add_argument("src_file", type=argparse.FileType("rt+"))
4044
parser.add_argument("dst_dir", type=str)
41-
args = parser.parse_args()
4245

43-
return vars(args)
46+
return parser.parse_args()
4447

4548

4649
if __name__ == "__main__":
47-
main(**parse_args())
50+
parsed_args = parse_args()
51+
main(parsed_args.src_file, parsed_args.dst_dir)

codegen/Tools/split-java-file.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import errno
55
import os
66
import re
7+
import typing
78

89
SPLIT_RE = re.compile(
910
r'//\s+[-]+\n//\s+<copyright company="Aspose" file="(?P<file>.+?\.java)">',
1011
re.MULTILINE,
1112
)
1213

1314

14-
def main(src_file, dst_dir):
15+
def main(src_file: typing.IO[str], dst_dir: str) -> None:
1516
remaining = src_file.read()
1617
try:
1718
os.makedirs(dst_dir)
@@ -20,7 +21,10 @@ def main(src_file, dst_dir):
2021
if e.errno != errno.EEXIST:
2122
raise
2223

23-
for match in reversed(list(SPLIT_RE.finditer(remaining))[1:]):
24+
found = list(reversed(list(SPLIT_RE.finditer(remaining))[1:]))
25+
if not found:
26+
raise SystemExit("No parts matching regex '%s' found in %s" % (SPLIT_RE.pattern, src_file.name))
27+
for match in found:
2428
start_pos = match.span()[0]
2529

2630
with open(os.path.join(dst_dir, match.groupdict()["file"]), "wt") as out_f:
@@ -34,14 +38,14 @@ def main(src_file, dst_dir):
3438
src_file.close()
3539

3640

37-
def parse_args():
41+
def parse_args() -> argparse.Namespace:
3842
parser = argparse.ArgumentParser()
3943
parser.add_argument("src_file", type=argparse.FileType("rt+"))
4044
parser.add_argument("dst_dir", type=str)
41-
args = parser.parse_args()
4245

43-
return vars(args)
46+
return parser.parse_args()
4447

4548

4649
if __name__ == "__main__":
47-
main(**parse_args())
50+
parsed_args = parse_args()
51+
main(parsed_args.src_file, parsed_args.dst_dir)

codegen/Tools/split-php-file.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import errno
55
import os
66
import re
7+
import typing
78

89
SPLIT_RE = re.compile(
910
r'/[\*]+\s*\n\s\*\s+[-]+\n\s*\*\s+<copyright company="Aspose" file="(?P<file>.+?\.php)">',
1011
re.MULTILINE,
1112
)
1213

1314

14-
def main(src_file, dst_dir):
15+
def main(src_file: typing.IO[str], dst_dir: str) -> None:
1516
remaining = src_file.read()
1617
try:
1718
os.makedirs(dst_dir)
@@ -21,7 +22,8 @@ def main(src_file, dst_dir):
2122
raise
2223

2324
found = list(reversed(list(SPLIT_RE.finditer(remaining))[1:]))
24-
assert found, "No parts matching regex '%s' found" % SPLIT_RE.pattern
25+
if not found:
26+
raise SystemExit("No parts matching regex '%s' found in %s" % (SPLIT_RE.pattern, src_file.name))
2527
for match in found:
2628
filename = match.groupdict()["file"]
2729
classname = os.path.splitext(filename)[0]
@@ -44,14 +46,14 @@ def main(src_file, dst_dir):
4446
src_file.close()
4547

4648

47-
def parse_args():
49+
def parse_args() -> argparse.Namespace:
4850
parser = argparse.ArgumentParser()
4951
parser.add_argument("src_file", type=argparse.FileType("rt+"))
5052
parser.add_argument("dst_dir", type=str)
51-
args = parser.parse_args()
5253

53-
return vars(args)
54+
return parser.parse_args()
5455

5556

5657
if __name__ == "__main__":
57-
main(**parse_args())
58+
parsed_args = parse_args()
59+
main(parsed_args.src_file, parsed_args.dst_dir)

mypy.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[mypy]
2+
python_version = 3.12
3+
strict = True
4+
# SDKs are generated code with their own type checks in their own repos
5+
exclude = (^|/)submodules/

0 commit comments

Comments
 (0)