-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathupdate-from-nuitka-options.py
executable file
·97 lines (68 loc) · 2.54 KB
/
update-from-nuitka-options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
import os
import textwrap
from nuitka.OptionParsing import SUPPRESS_HELP, parser
from nuitka.utils.CommandLineOptions import OurOptionParser
from nuitka.utils.FileOperations import changeTextFileContents
from nuitka.utils.Jinja2 import getTemplate
template = getTemplate(
package_name=None,
template_subdir=os.path.dirname(__file__) or ".",
template_name="action.yml.j2",
extensions=("jinja2.ext.do",),
)
def getOptions():
for option in parser.iterateOptions():
# Help option
if "--help" in option._long_opts:
continue
# Main option is currently not done like this
if "--main" in option._long_opts:
continue
if not hasattr(option, "require_compiling"):
continue
# Non-compiling options do not belong into Nuitka-Action
if not option.require_compiling or not option.github_action:
continue
if option.help is SUPPRESS_HELP:
continue
yield option
def getTopOptions():
for option in getOptions():
container = getattr(option, "container", None)
if isinstance(container, OurOptionParser):
yield option
def getGroupOptions(group_name):
for option in getOptions():
container = getattr(option, "container", None)
if isinstance(container, OurOptionParser):
continue
if container.title == group_name:
yield option
def formatOption(option):
result = (
option._long_opts[0].lstrip("-")
+ ":\n description: |\n"
+ textwrap.indent(option.help, prefix=" ")
)
if option.github_action_default is not None:
if type(option.github_action_default) is bool:
option.github_action_default = "true" if option.github_action_default else "false"
assert type(option.github_action_default) is str, option
result += "\n default: " + option.github_action_default
return result
def get_top_options():
result = []
for option in getTopOptions():
result.append(formatOption(option))
return textwrap.indent("\n".join(result), " ")
def get_group_options(group_caption):
result = []
for option in getGroupOptions(group_caption):
result.append(formatOption(option))
return textwrap.indent("\n".join(result), " ")
action_yaml = template.render(get_top_options=get_top_options, get_group_options=get_group_options,)
if changeTextFileContents("action.yml", action_yaml):
print("Updated.")
else:
print("Already up to date.")