Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions build/generate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
from mako.template import Template
import pprint
import sys
import typing

pp = pprint.PrettyPrinter(indent=4)


def generate_template(template_name, template_params, dest_file, in_zip_file=False):
def generate_template(template_name: str, template_params: typing.Dict[str, typing.Any], dest_file: str, in_zip_file: bool = False):
try:
template_params['encoding_tag'] = '# -*- coding: utf-8 -*-'
module_name = template_params['metadata'].config['module_name']
module_name: str = template_params['metadata'].config['module_name']
lookup = TemplateLookup(directories=['build/templates', 'src/{0}/templates'.format(module_name)])
template = Template(filename=template_name, lookup=lookup)
rendered_template = template.render(template_parameters=template_params)
rendered_template: str = template.render(template_parameters=template_params)

except Exception:
# Because mako expands into python, we catch all errors, not just MakoException.
Expand Down Expand Up @@ -47,14 +48,9 @@ def generate_template(template_name, template_params, dest_file, in_zip_file=Fal
sys.exit(1)

logging.debug(rendered_template)
if sys.version_info.major < 3:
file_handle_public = codecs.open(dest_file, mode="w", encoding='utf-8')
file_handle_public.write(rendered_template)
file_handle_public.close()
else:
file_handle_public = open(dest_file, 'wb')
file_handle_public.write(bytes(rendered_template, "UTF-8"))
file_handle_public.close()
file_handle_public = codecs.open(dest_file, mode="w", encoding='utf-8')
file_handle_public.write(rendered_template)
file_handle_public.close()



26 changes: 14 additions & 12 deletions build/helper/documentation_snippets.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# Different documentation snippets we add to the generated documentation
import typing

rep_cap_method_desc = '''

rep_cap_method_desc: str = '''
This method requires repeated capabilities. If called directly on the
{0}.Session object, then the method will use all repeated capabilities in the session.
You can specify a subset of repeated capabilities using the Python index notation on an
{0}.Session repeated capabilities container, and calling this method on the result.
'''

rep_cap_attr_desc = '''
rep_cap_attr_desc: str = '''
This property can use repeated capabilities. If set or get directly on the
{0}.Session object, then the set/get will use all repeated capabilities in the session.
You can specify a subset of repeated capabilities using the Python index notation on an
{0}.Session repeated capabilities container, and calling set/get value on the result.
'''

func_note_text = '''
func_note_text: str = '''
One or more of the referenced functions are not in the Python API for this driver.
'''

attr_note_text = '''
attr_note_text: str = '''
One or more of the referenced attributes are not in the Python API for this driver.
'''

enum_note_text = '''
enum_note_text: str = '''
One or more of the referenced values are not in the Python API for this driver. Enums that only define values, or represent True/False, have been removed.
'''

session_return_text = '''
A session object representing the device.
'''

options_table_header = ['Attribute', 'Default']
options_table_body = [
options_table_header: typing.Sequence[str] = ['Attribute', 'Default']
options_table_body: typing.Sequence[typing.Sequence[str]] = [
['range_check', 'True'],
['query_instrument_status', 'False'],
['cache', 'True'],
Expand All @@ -40,7 +42,7 @@
['driver_setup', '{}'],
]

options_text = '''
options_text: str = '''
Specifies the initial value of certain attributes for the session. The
syntax for **options** is a dictionary of attributes with an assigned
value. For example:
Expand All @@ -54,20 +56,20 @@
{ 'simulate': True, 'driver_setup': { 'Model': '<model number>', 'BoardType': '<type>' } }
'''

default_close_function_doc = '''
default_close_function_doc: str = '''
Closes the driver session and cleans up. After calling this the Session object
is no longer valid and cannot be used.
'''

close_function_note = '''
close_function_note: str = '''
This function is not needed when using the session context manager
'''

default_initiate_function_doc = '''
default_initiate_function_doc: str = '''
Calls initiate
'''

initiate_function_note = '''
initiate_function_note: str = '''
This function will return a Python context manager that will initiate on entering and abort on exit.
'''

Expand Down
Loading