Skip to content

Commit 652e249

Browse files
committed
[GR-59702] Generate markdown docs for stable, non-internal graalpy context options
1 parent b165f5d commit 652e249

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

docs/site/01-docs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ permalink: docs/
88
{% gfm_docs ../user/Python-Runtime.md %}
99
{% gfm_docs ../user/Performance.md %}
1010
{% gfm_docs ../user/Python-on-JVM.md %}
11+
12+
<h3 id="python-context-options">
13+
<a href="#python-context-options" class="anchor-link">Python Context Options</a>
14+
</h3>
15+
Below are the options you can set on contexts for GraalPy.
16+
{% python_options ../../graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java %}
17+
1118
{% gfm_docs ../user/Native-Images-with-Python.md %}
1219
{% gfm_docs ../user/Python-Standalone-Applications.md %}
1320
{% gfm_docs ../user/Interoperability.md %}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require 'cgi'
2+
require 'kramdown'
3+
require 'kramdown-parser-gfm'
4+
5+
module GraalPy
6+
class PythonOptions < Liquid::Tag
7+
def initialize(tag_name, text, tokens)
8+
super
9+
@text = text.strip
10+
end
11+
12+
def render(context)
13+
content = File.read(@text)
14+
options = {}
15+
16+
regexp = /
17+
^(\s*@EngineOption\s*)? # Optional @EngineOption
18+
\s*@Option\s*\( # @Option(
19+
(.*?) # non-greedy match content
20+
\)\s*(?:\/\/)?\s* # )
21+
public\s+static\s+final\s+OptionKey<[^>]+>\s+(\w+) # field name (e.g. InitialLocale)
22+
/mx
23+
24+
help_regexp = /
25+
help\s*=\s*((?:"[^"]*"\s*(?:\+\s*"[^"]*"\s*)*)) # help = "..."+ "...",
26+
/mx
27+
28+
stability_regexp = /stability\s*=\s*OptionStability\.(\w+)/
29+
30+
category_regexp = /category\s*=\s*OptionCategory\.(\w+)/
31+
32+
usage_regexp = /usageSyntax\s*=\s*((?:"[^"]*"\s*(?:\+\s*"[^"]*"\s*)*))/
33+
34+
content.scan(regexp) do |engine_option, content, field|
35+
engine_option = !!engine_option
36+
37+
help = content.match(help_regexp)
38+
help = help[1].scan(/"([^"]*)"/).flatten.join(" ").gsub(/\s+/, " ").strip if help
39+
40+
stable = content.match(stability_regexp)
41+
stable = stable[1] == "STABLE" if stable
42+
43+
category = content.match(category_regexp)
44+
category = category[1] if category
45+
46+
usage = content.match(usage_regexp)
47+
usage = usage[1].scan(/"([^"]*)"/).flatten.join(" ").gsub(/\s+/, " ").strip if usage
48+
49+
if help && !help.empty?
50+
help << "." unless help.end_with? "."
51+
help = CGI::escapeHTML help
52+
help << " Accepts: <code>#{CGI::escapeHTML usage}</code>" if usage and !usage.empty?
53+
options[field] = { help: help, category: category, stable: stable, engine_option: engine_option }
54+
end
55+
end
56+
57+
doc_content = options.select do |name, opt|
58+
opt[:stable] && ["USER", "EXPERT"].include?(opt[:category])
59+
end.sort_by do |name, opt|
60+
[opt[:category] == "USER" ? 0 : 1, name.downcase]
61+
end.map do |name, opt|
62+
<<~HTML
63+
<p>
64+
<strong>#{name}</strong>
65+
#{' (Has to be the same for all Contexts in an Engine)' if opt[:engine_option]}
66+
</p>
67+
<p>
68+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#{opt[:help]}
69+
</p>
70+
HTML
71+
end.join("\n")
72+
end
73+
end
74+
end
75+
76+
Liquid::Template.register_tag('python_options', GraalPy::PythonOptions)

0 commit comments

Comments
 (0)