if not os.path.isfile(args.config):
_print_error(f'`{args.config}` is not an existing, regular file')
- # Load configuration file to get its major version in order to
- # append the correct implicit inclusion directory.
- try:
- with open(args.config) as f:
- config_major_version = barectf.configuration_file_major_version(f)
- except barectf._ConfigurationParseError as exc:
- _print_config_error(exc)
- except Exception as exc:
- _print_unknown_exc(exc)
-
- # append current working directory and implicit inclusion directory
- args.include_dir += [
- os.getcwd(),
- pkg_resources.resource_filename(__name__, f'include/{config_major_version}')
- ]
+ # append current working directory
+ args.include_dir.append(os.getcwd())
return args
with open(args.config) as f:
if args.dump_config:
# print effective configuration file
- print(barectf.effective_configuration_file(f, args.include_dir,
+ print(barectf.effective_configuration_file(f, True, args.include_dir,
args.ignore_include_not_found))
# barectf.configuration_from_file() reads the file again
# below: rewind.
f.seek(0)
- config = barectf.configuration_from_file(f, args.include_dir,
+ config = barectf.configuration_from_file(f, True, args.include_dir,
args.ignore_include_not_found)
except barectf._ConfigurationParseError as exc:
_print_config_error(exc)
return self._options
-def effective_configuration_file(file, inclusion_dirs, ignore_inclusion_not_found,
+def effective_configuration_file(file, with_package_inclusion_directory=True,
+ inclusion_directories=None, ignore_inclusion_not_found=False,
indent_space_count=2):
- return barectf_config_parse._effective_config_file(file, inclusion_dirs,
+ if inclusion_directories is None:
+ inclusion_directories = []
+
+ return barectf_config_parse._effective_config_file(file, with_package_inclusion_directory,
+ inclusion_directories,
ignore_inclusion_not_found,
indent_space_count)
-def configuration_from_file(file, inclusion_dirs, ignore_inclusion_not_found):
- return barectf_config_parse._from_file(file, inclusion_dirs, ignore_inclusion_not_found)
+def configuration_from_file(file, with_package_inclusion_directory=True, inclusion_directories=None,
+ ignore_inclusion_not_found=False):
+ if inclusion_directories is None:
+ inclusion_directories = []
+
+ return barectf_config_parse._from_file(file, with_package_inclusion_directory,
+ inclusion_directories, ignore_inclusion_not_found)
def configuration_file_major_version(file):
# parse the file-like object `file`.
#
# `file` can be a barectf 2 or 3 configuration file.
-def _create_v3_parser(file, include_dirs, ignore_include_not_found):
+def _create_v3_parser(file, with_pkg_include_dir, include_dirs, ignore_include_not_found):
try:
root_node = barectf_config_parse_common._yaml_load(file)
if type(root_node) is barectf_config_parse_common._ConfigNodeV3:
# barectf 3 configuration file
- return barectf_config_parse_v3._Parser(file, root_node, include_dirs,
- ignore_include_not_found)
+ return barectf_config_parse_v3._Parser(file, root_node, with_pkg_include_dir,
+ include_dirs, ignore_include_not_found)
elif type(root_node) is collections.OrderedDict:
# barectf 2 configuration file
- v2_parser = barectf_config_parse_v2._Parser(file, root_node, include_dirs,
- ignore_include_not_found)
- return barectf_config_parse_v3._Parser(file, v2_parser.config_node, include_dirs,
+ v2_parser = barectf_config_parse_v2._Parser(file, root_node, with_pkg_include_dir,
+ include_dirs, ignore_include_not_found)
+ return barectf_config_parse_v3._Parser(file, v2_parser.config_node,
+ with_pkg_include_dir, include_dirs,
ignore_include_not_found)
else:
raise _ConfigurationParseError('Configuration',
'Cannot create configuration from YAML file')
-def _from_file(file, include_dirs, ignore_include_not_found):
- return _create_v3_parser(file, include_dirs, ignore_include_not_found).config
+def _from_file(file, with_pkg_include_dir, include_dirs, ignore_include_not_found):
+ return _create_v3_parser(file, with_pkg_include_dir, include_dirs, ignore_include_not_found).config
-def _effective_config_file(file, include_dirs, ignore_include_not_found, indent_space_count=2):
- config_node = _create_v3_parser(file, include_dirs, ignore_include_not_found).config_node
+def _effective_config_file(file, with_pkg_include_dir, include_dirs, ignore_include_not_found,
+ indent_space_count):
+ config_node = _create_v3_parser(file, with_pkg_include_dir, include_dirs,
+ ignore_include_not_found).config_node
return barectf_config_parse_common._yaml_dump(config_node, indent=indent_space_count,
default_flow_style=False, explicit_start=True,
explicit_end=True)
# path `path`).
#
# For its _process_node_include() method, the parser considers the
- # inclusion directories `include_dirs` and ignores nonexistent
- # inclusion files if `ignore_include_not_found` is `True`.
- def __init__(self, path, node, include_dirs, ignore_include_not_found, major_version):
+ # package inclusion directory as well as `include_dirs`, and ignores
+ # nonexistent inclusion files if `ignore_include_not_found` is
+ # `True`.
+ def __init__(self, path, node, with_pkg_include_dir, include_dirs, ignore_include_not_found,
+ major_version):
self._root_path = path
self._root_node = node
self._ft_prop_names = [
# barectf 3
'element-field-type',
]
- self._include_dirs = include_dirs
+
+ self._include_dirs = copy.copy(include_dirs)
+
+ if with_pkg_include_dir:
+ self._include_dirs.append(pkg_resources.resource_filename(__name__, f'include/{major_version}'))
+
self._ignore_include_not_found = ignore_include_not_found
self._include_stack = []
self._resolved_ft_aliases = set()
class _Parser(config_parse_common._Parser):
# Builds a barectf 2 YAML configuration parser and parses the root
# configuration node `node` (already loaded from `path`).
- def __init__(self, path, node, include_dirs, ignore_include_not_found):
- super().__init__(path, node, include_dirs, ignore_include_not_found, 2)
+ def __init__(self, path, node, with_pkg_include_dir, include_dirs, ignore_include_not_found):
+ super().__init__(path, node, with_pkg_include_dir, include_dirs, ignore_include_not_found, 2)
self._ft_cls_name_to_conv_method = {
'int': self._conv_int_ft_node,
'integer': self._conv_int_ft_node,
class _Parser(barectf_config_parse_common._Parser):
# Builds a barectf 3 YAML configuration parser and parses the root
# configuration node `node` (already loaded from `path`).
- def __init__(self, path, node, inclusion_dirs, ignore_include_not_found):
- super().__init__(path, node, inclusion_dirs, ignore_include_not_found, 3)
+ def __init__(self, path, node, with_pkg_include_dir, inclusion_dirs, ignore_include_not_found):
+ super().__init__(path, node, with_pkg_include_dir, inclusion_dirs,
+ ignore_include_not_found, 3)
self._ft_cls_name_to_create_method = {
'unsigned-integer': self._create_int_ft,
'signed-integer': self._create_int_ft,
except _ConfigurationParseError as exc:
_append_error_ctx(exc, f'Structure field type member `{member_name}`')
- default_byte_order_prop_name = '$default-byte-order'
- default_byte_order_node = self._trace_type_node.get(default_byte_order_prop_name)
-
- if default_byte_order_prop_name in self._trace_type_node:
- del self._trace_type_node[default_byte_order_prop_name]
+ default_byte_order_node = self._trace_type_node.get('$default-byte-order')
self._default_byte_order = None