Skip to content

Commit aae37fd

Browse files
author
Petr Vesely
committed
[UR] Add script to generate experimental feature template files
1 parent 7b96d40 commit aae37fd

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

scripts/add_experimental_feature.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Copyright (C) 2023 Intel Corporation
3+
4+
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
5+
See LICENSE.TXT
6+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
8+
"""
9+
import argparse
10+
import sys
11+
from util import makoWrite
12+
import re
13+
14+
def verify_kebab_case(input: str) -> bool:
15+
# kebab case regex from https://github.com/expandjs/expandjs/blob/master/lib/kebabCaseRegex.js
16+
kebab_case_re = r"^([a-z](?![\d])|[\d](?![a-z]))+(-?([a-z](?![\d])|[\d](?![a-z])))*$|^$"
17+
pattern = re.compile(kebab_case_re)
18+
if pattern.match(input) is None:
19+
return False
20+
return True
21+
22+
23+
def main():
24+
25+
argParser = argparse.ArgumentParser()
26+
argParser.add_argument("name", help="must be lowercase and kebab case i.e. command-buffer", type=str)
27+
args = argParser.parse_args()
28+
29+
if not verify_kebab_case(args.name):
30+
print("Name must be lowercase and kebab-case i.e. command-buffer.")
31+
sys.exit(1)
32+
33+
exp_feat_name = args.name
34+
35+
out_yml_name = "exp-%s.yml" % exp_feat_name
36+
out_rst_name = "EXP-%s.rst" % exp_feat_name.upper()
37+
38+
yaml_template_path = "./scripts/templates/%s" % "exp_feat.yml.mako"
39+
rst_template_path = "./scripts/templates/%s" % "exp_feat.rst.mako"
40+
out_yml_path = "./scripts/core/%s" % out_yml_name
41+
out_rst_path = "./scripts/core/%s" % out_rst_name
42+
43+
makoWrite(yaml_template_path, out_yml_path, name=exp_feat_name)
44+
makoWrite(rst_template_path, out_rst_path, name=exp_feat_name)
45+
46+
47+
print("Successfully generated the template files needed for %s." % exp_feat_name)
48+
print("""
49+
You can now implement your feature in the following files:
50+
* %s
51+
* %s
52+
""" % (out_yml_name, out_rst_name))
53+
54+
55+
if __name__ == "__main__":
56+
try:
57+
main()
58+
except KeyboardInterrupt:
59+
exit(130)

scripts/core/CONTRIB.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ Experimental features *must* be defined in two new files, where
207207
* ``scripts/core/exp-<feature>.yml`` defines the interface as an input to
208208
`Generating Source`_.
209209

210+
To simplify this process please use the provided python script which will create
211+
these template files for you. You can then freely modify these files to
212+
implement your experimental feature.
213+
214+
.. code-block:: console
215+
216+
$ python scripts/add_experimental_feature.py <name-of-your-experimental-feature>
217+
218+
210219
Naming Convention
211220
-----------------
212221

scripts/templates/exp_feat.rst.mako

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<%text><%
2+
OneApi=tags['$OneApi']
3+
x=tags['$x']
4+
X=x.upper()
5+
%>
6+
</%text>
7+
.. _experimental-${name}
8+
9+
================================================================================
10+
${" ".join(name.split("-")).title()}
11+
================================================================================
12+
13+
14+
.. warning:
15+
16+
Experimental features:
17+
18+
* May be replaced, updated, or removed at any time.
19+
* Do not require maintaining API/ABI stability of their own additions over
20+
time.
21+
* Do not require conformance testing of their own additions.
22+
23+
24+
.. todo::
25+
26+
In the following sections you should explain and document the motivation of
27+
the experimental feature, the additions made to the specification along with
28+
its valid usage.

scripts/templates/exp_feat.yml.mako

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<%
2+
import re
3+
from templates import helper as th
4+
import datetime
5+
%><%
6+
year_now=datetime.date.today().year
7+
%>#
8+
# Copyright (C) ${year_now} Intel Corporation
9+
#
10+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
11+
# See LICENSE.TXT
12+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13+
#
14+
# See YaML.md for syntax definition
15+
#
16+
--- #--------------------------------------------------------------------------
17+
type: header
18+
desc: "Intel $OneApi Unified Runtime Experimental APIs for ${" ".join(name.split("-")).title()}"
19+
ordinal: "99"
20+
--- #--------------------------------------------------------------------------
21+
## TODO - Add you experimental feature additions here
22+
## - refer to YaML.md for the syntax defintion

0 commit comments

Comments
 (0)