Skip to content

Commit 4319321

Browse files
authored
Merge pull request #607 from veselypeta/petr/add-exp-feature-template
[UR] Add script to generate experimental feature template files
2 parents 7b96d40 + ef437fb commit 4319321

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

scripts/add_experimental_feature.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
import subprocess
14+
15+
def verify_kebab_case(input: str) -> bool:
16+
# kebab case regex from https://github.com/expandjs/expandjs/blob/master/lib/kebabCaseRegex.js
17+
kebab_case_re = r"^([a-z](?![\d])|[\d](?![a-z]))+(-?([a-z](?![\d])|[\d](?![a-z])))*$|^$"
18+
pattern = re.compile(kebab_case_re)
19+
if pattern.match(input) is None:
20+
return False
21+
return True
22+
23+
24+
def get_user_name_email_from_git_config():
25+
proc = subprocess.run(["git", "config", "user.name"], stdout=subprocess.PIPE)
26+
if proc.returncode != 0:
27+
raise Exception("Failed to get user name from git config.")
28+
user_name = proc.stdout.decode().strip()
29+
30+
proc = subprocess.run(["git", "config", "user.email"], stdout=subprocess.PIPE)
31+
if proc.returncode != 0:
32+
raise Exception("Failed to get user email from git config.")
33+
user_email = proc.stdout.decode().strip()
34+
35+
return user_name, user_email
36+
37+
38+
def main():
39+
40+
argParser = argparse.ArgumentParser()
41+
argParser.add_argument("name", help="must be lowercase and kebab case i.e. command-buffer", type=str)
42+
argParser.add_argument("--dry_run", help="run the script without generating any files", action='store_true')
43+
args = argParser.parse_args()
44+
45+
if not verify_kebab_case(args.name):
46+
print("Name must be lowercase and kebab-case i.e. command-buffer.")
47+
sys.exit(1)
48+
49+
user_name, user_email = get_user_name_email_from_git_config()
50+
user = {'email':user_email, 'name': user_name}
51+
52+
exp_feat_name = args.name
53+
54+
out_yml_name = f"exp-{exp_feat_name}.yml"
55+
out_rst_name = f"EXP-{exp_feat_name.upper()}.rst"
56+
57+
yaml_template_path = "./scripts/templates/exp_feat.yml.mako"
58+
rst_template_path = "./scripts/templates/exp_feat.rst.mako"
59+
out_yml_path = f"./scripts/core/{out_yml_name}"
60+
out_rst_path = f"./scripts/core/{out_rst_name}"
61+
62+
if not args.dry_run:
63+
makoWrite(yaml_template_path, out_yml_path, name=exp_feat_name)
64+
makoWrite(rst_template_path, out_rst_path, name=exp_feat_name, user=user)
65+
66+
67+
print(f"""\
68+
Successfully generated the template files needed for {exp_feat_name}.
69+
70+
You can now implement your feature in the following files:
71+
* {out_yml_name}
72+
* {out_rst_name}
73+
""")
74+
75+
76+
if __name__ == "__main__":
77+
try:
78+
main()
79+
except KeyboardInterrupt:
80+
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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
.. warning::
14+
15+
Experimental features:
16+
17+
* May be replaced, updated, or removed at any time.
18+
* Do not require maintaining API/ABI stability of their own additions over
19+
time.
20+
* Do not require conformance testing of their own additions.
21+
22+
23+
Terminology
24+
--------------------------------------------------------------------------------
25+
.. comment:
26+
If your experimental feature introduces a new concept or terminology. Please
27+
provide a detailed explanation in this section. If this does not apply to
28+
your feature you may freely delete this section.
29+
30+
Motivation
31+
--------------------------------------------------------------------------------
32+
.. comment:
33+
In this section you *must* justify your motivation for adding this
34+
experimental feature. You should also state at least one adapter upon which
35+
this feature can be supported.
36+
37+
API
38+
--------------------------------------------------------------------------------
39+
.. comment:
40+
In this section you *must* list all additions your experimental feature will
41+
make to the Unified Runtime specification. If your experimental feature does
42+
not include additions from one or more of the sections listed below, you may
43+
freely remove them.
44+
45+
Macros
46+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47+
* <%text>${x}</%text>_EXP_MACRO
48+
49+
Enums
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
* <%text>${x}</%text>_exp_enum_t
52+
53+
Structs
54+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55+
* <%text>${x}</%text>_exp_struct_t
56+
57+
Functions
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
* <%text>${x}</%text>FunctionExp
60+
61+
Changelog
62+
--------------------------------------------------------------------------------
63+
.. comment:
64+
When making a change to an experimental feature, increment the version and
65+
provide a brief description of the change in the table below.
66+
67+
+-----------+------------------------+
68+
| Revision | Changes |
69+
+===========+========================+
70+
| 1.0 | Intial Draft |
71+
+-----------+------------------------+
72+
73+
Contributors
74+
--------------------------------------------------------------------------------
75+
.. comment:
76+
Please list all people who wish to be credited for contribution to this
77+
experimental feature.
78+
79+
* ${user['name']} `${user['email']} <${user['email']}>`_

scripts/templates/exp_feat.yml.mako

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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"

0 commit comments

Comments
 (0)