mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-09-02 03:12:34 +01:00
pluginloader: Replaced extension loader with WA3 plugin loader
In the process removed modules and boot_strap.py. Also Renamed extensions Plugins. Louie is now monkey patched rather than containing a modified version in external
This commit is contained in:
@@ -27,7 +27,7 @@ from collections import OrderedDict
|
||||
|
||||
import yaml
|
||||
|
||||
from wlauto import ExtensionLoader, Command, settings
|
||||
from wlauto import PluginLoader, Command, settings
|
||||
from wlauto.exceptions import CommandError, ConfigError
|
||||
from wlauto.utils.cli import init_argument_parser
|
||||
from wlauto.utils.misc import (capitalize, check_output,
|
||||
@@ -139,8 +139,8 @@ class CreateWorkloadSubcommand(CreateSubcommand):
|
||||
class CreatePackageSubcommand(CreateSubcommand):
|
||||
|
||||
name = 'package'
|
||||
description = '''Create a new empty Python package for WA extensions. On installation,
|
||||
this package will "advertise" itself to WA so that Extensions with in it will
|
||||
description = '''Create a new empty Python package for WA plugins. On installation,
|
||||
this package will "advertise" itself to WA so that Plugins with in it will
|
||||
be loaded by WA when it runs.'''
|
||||
|
||||
def initialize(self):
|
||||
@@ -156,9 +156,9 @@ class CreatePackageSubcommand(CreateSubcommand):
|
||||
def execute(self, args): # pylint: disable=R0201
|
||||
package_dir = args.path or os.path.abspath('.')
|
||||
template_path = os.path.join(TEMPLATES_DIR, 'setup.template')
|
||||
self.create_extensions_package(package_dir, args.name, template_path, args.force)
|
||||
self.create_plugins_package(package_dir, args.name, template_path, args.force)
|
||||
|
||||
def create_extensions_package(self, location, name, setup_template_path, overwrite=False):
|
||||
def create_plugins_package(self, location, name, setup_template_path, overwrite=False):
|
||||
package_path = os.path.join(location, name)
|
||||
if os.path.exists(package_path):
|
||||
if overwrite:
|
||||
@@ -178,13 +178,13 @@ class CreateAgendaSubcommand(CreateSubcommand):
|
||||
|
||||
name = 'agenda'
|
||||
description = """
|
||||
Create an agenda whith the specified extensions enabled. And parameters set to their
|
||||
Create an agenda whith the specified plugins enabled. And parameters set to their
|
||||
default values.
|
||||
"""
|
||||
|
||||
def initialize(self):
|
||||
self.parser.add_argument('extensions', nargs='+',
|
||||
help='Extensions to be added')
|
||||
self.parser.add_argument('plugins', nargs='+',
|
||||
help='Plugins to be added')
|
||||
self.parser.add_argument('-i', '--iterations', type=int, default=1,
|
||||
help='Sets the number of iterations for all workloads')
|
||||
self.parser.add_argument('-r', '--include-runtime-params', action='store_true',
|
||||
@@ -192,23 +192,23 @@ class CreateAgendaSubcommand(CreateSubcommand):
|
||||
Adds runtime parameters to the global section of the generated
|
||||
agenda. Note: these do not have default values, so only name
|
||||
will be added. Also, runtime parameters are devices-specific, so
|
||||
a device must be specified (either in the list of extensions,
|
||||
a device must be specified (either in the list of plugins,
|
||||
or in the existing config).
|
||||
""")
|
||||
self.parser.add_argument('-o', '--output', metavar='FILE',
|
||||
help='Output file. If not specfied, STDOUT will be used instead.')
|
||||
|
||||
def execute(self, args): # pylint: disable=no-self-use,too-many-branches,too-many-statements
|
||||
loader = ExtensionLoader(packages=settings.extension_packages,
|
||||
paths=settings.extension_paths)
|
||||
loader = PluginLoader(packages=settings.plugin_packages,
|
||||
paths=settings.plugin_paths)
|
||||
agenda = OrderedDict()
|
||||
agenda['config'] = OrderedDict(instrumentation=[], result_processors=[])
|
||||
agenda['global'] = OrderedDict(iterations=args.iterations)
|
||||
agenda['workloads'] = []
|
||||
device = None
|
||||
device_config = None
|
||||
for name in args.extensions:
|
||||
extcls = loader.get_extension_class(name)
|
||||
for name in args.plugins:
|
||||
extcls = loader.get_plugin_class(name)
|
||||
config = loader.get_default_config(name)
|
||||
del config['modules']
|
||||
|
||||
@@ -236,10 +236,10 @@ class CreateAgendaSubcommand(CreateSubcommand):
|
||||
if args.include_runtime_params:
|
||||
if not device:
|
||||
if settings.device:
|
||||
device = loader.get_extension_class(settings.device)
|
||||
device = loader.get_plugin_class(settings.device)
|
||||
device_config = loader.get_default_config(settings.device)
|
||||
else:
|
||||
raise ConfigError('-r option requires for a device to be in the list of extensions')
|
||||
raise ConfigError('-r option requires for a device to be in the list of plugins')
|
||||
rps = OrderedDict()
|
||||
for rp in device.runtime_parameters:
|
||||
if hasattr(rp, 'get_runtime_parameters'):
|
||||
@@ -290,7 +290,7 @@ class CreateCommand(Command):
|
||||
|
||||
def create_workload(name, kind='basic', where='local', check_name=True, **kwargs):
|
||||
if check_name:
|
||||
extloader = ExtensionLoader(packages=settings.extension_packages, paths=settings.extension_paths)
|
||||
extloader = PluginLoader(packages=settings.plugin_packages, paths=settings.plugin_paths)
|
||||
if name in [wl.name for wl in extloader.list_workloads()]:
|
||||
raise CommandError('Workload with name "{}" already exists.'.format(name))
|
||||
|
||||
|
@@ -14,26 +14,26 @@
|
||||
#
|
||||
|
||||
|
||||
from wlauto import ExtensionLoader, Command, settings
|
||||
from wlauto import PluginLoader, Command, settings
|
||||
from wlauto.utils.formatter import DescriptionListFormatter
|
||||
from wlauto.utils.doc import get_summary
|
||||
|
||||
from wlauto.core import pluginloader
|
||||
|
||||
class ListCommand(Command):
|
||||
|
||||
name = 'list'
|
||||
description = 'List available WA extensions with a short description of each.'
|
||||
description = 'List available WA plugins with a short description of each.'
|
||||
|
||||
def initialize(self, context):
|
||||
extension_types = ['{}s'.format(ext.name) for ext in settings.extensions]
|
||||
plugin_types = ['{}s'.format(name) for name in pluginloader.kinds]
|
||||
self.parser.add_argument('kind', metavar='KIND',
|
||||
help=('Specify the kind of extension to list. Must be '
|
||||
'one of: {}'.format(', '.join(extension_types))),
|
||||
choices=extension_types)
|
||||
help=('Specify the kind of plugin to list. Must be '
|
||||
'one of: {}'.format(', '.join(plugin_types))),
|
||||
choices=plugin_types)
|
||||
self.parser.add_argument('-n', '--name', help='Filter results by the name specified')
|
||||
self.parser.add_argument('-o', '--packaged-only', action='store_true',
|
||||
help='''
|
||||
Only list extensions packaged with WA itself. Do not list extensions
|
||||
Only list plugins packaged with WA itself. Do not list plugins
|
||||
installed locally or from other packages.
|
||||
''')
|
||||
self.parser.add_argument('-p', '--platform', help='Only list results that are supported by '
|
||||
@@ -44,12 +44,7 @@ class ListCommand(Command):
|
||||
if args.name:
|
||||
filters['name'] = args.name
|
||||
|
||||
if args.packaged_only:
|
||||
ext_loader = ExtensionLoader()
|
||||
else:
|
||||
ext_loader = ExtensionLoader(packages=settings.extension_packages,
|
||||
paths=settings.extension_paths)
|
||||
results = ext_loader.list_extensions(args.kind[:-1])
|
||||
results = pluginloader.list_plugins(args.kind[:-1])
|
||||
if filters or args.platform:
|
||||
filtered_results = []
|
||||
for result in results:
|
||||
@@ -72,8 +67,8 @@ class ListCommand(Command):
|
||||
print output.format_data()
|
||||
|
||||
|
||||
def check_platform(extension, platform):
|
||||
supported_platforms = getattr(extension, 'supported_platforms', [])
|
||||
def check_platform(plugin, platform):
|
||||
supported_platforms = getattr(plugin, 'supported_platforms', [])
|
||||
if supported_platforms:
|
||||
return platform in supported_platforms
|
||||
return True
|
||||
|
@@ -16,7 +16,7 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from wlauto import ExtensionLoader, Command, settings
|
||||
from wlauto import PluginLoader, Command, settings
|
||||
from wlauto.common.resources import Executable
|
||||
from wlauto.core.resource import NO_ONE
|
||||
from wlauto.core.resolver import ResourceResolver
|
||||
@@ -69,8 +69,8 @@ class RecordCommand(Command):
|
||||
self.validate_args(args)
|
||||
self.logger.info("Connecting to device...")
|
||||
|
||||
ext_loader = ExtensionLoader(packages=settings.extension_packages,
|
||||
paths=settings.extension_paths)
|
||||
ext_loader = PluginLoader(packages=settings.plugin_packages,
|
||||
paths=settings.plugin_paths)
|
||||
|
||||
# Setup config
|
||||
self.config = RunConfiguration(ext_loader)
|
||||
@@ -84,7 +84,6 @@ class RecordCommand(Command):
|
||||
# Setup device
|
||||
self.device = ext_loader.get_device(settings.device, **settings.device_config)
|
||||
self.device.validate()
|
||||
self.device.dynamic_modules = []
|
||||
self.device.connect()
|
||||
self.device.initialize(context)
|
||||
|
||||
|
@@ -23,7 +23,8 @@ from wlauto import Command, settings
|
||||
from wlauto.core.agenda import Agenda
|
||||
from wlauto.core.execution import Executor
|
||||
from wlauto.utils.log import add_log_file
|
||||
|
||||
from wlauto.core.configuration import RunConfiguration
|
||||
from wlauto.core import pluginloader
|
||||
|
||||
class RunCommand(Command):
|
||||
|
||||
@@ -45,7 +46,7 @@ class RunCommand(Command):
|
||||
option (see below) is used, in which case the contents of the
|
||||
directory will be overwritten. If this option is not specified,
|
||||
then {} will be used instead.
|
||||
""".format(settings.output_directory))
|
||||
""".format(settings.default_output_directory))
|
||||
self.parser.add_argument('-f', '--force', action='store_true',
|
||||
help="""
|
||||
Overwrite output directory if it exists. By default, the script
|
||||
@@ -69,18 +70,22 @@ class RunCommand(Command):
|
||||
""")
|
||||
|
||||
def execute(self, args): # NOQA
|
||||
self.set_up_output_directory(args)
|
||||
add_log_file(settings.log_file)
|
||||
output_directory = self.set_up_output_directory(args)
|
||||
add_log_file(os.path.join(output_directory, "run.log"))
|
||||
config = RunConfiguration(pluginloader)
|
||||
|
||||
if os.path.isfile(args.agenda):
|
||||
agenda = Agenda(args.agenda)
|
||||
settings.agenda = args.agenda
|
||||
shutil.copy(args.agenda, settings.meta_directory)
|
||||
shutil.copy(args.agenda, config.meta_directory)
|
||||
else:
|
||||
self.logger.debug('{} is not a file; assuming workload name.'.format(args.agenda))
|
||||
agenda = Agenda()
|
||||
agenda.add_workload_entry(args.agenda)
|
||||
|
||||
for filepath in settings.config_paths:
|
||||
config.load_config(filepath)
|
||||
|
||||
if args.instruments_to_disable:
|
||||
if 'instrumentation' not in agenda.config:
|
||||
agenda.config['instrumentation'] = []
|
||||
@@ -89,27 +94,29 @@ class RunCommand(Command):
|
||||
agenda.config['instrumentation'].append('~{}'.format(itd))
|
||||
|
||||
basename = 'config_'
|
||||
for file_number, path in enumerate(settings.get_config_paths(), 1):
|
||||
for file_number, path in enumerate(settings.config_paths, 1):
|
||||
file_ext = os.path.splitext(path)[1]
|
||||
shutil.copy(path, os.path.join(settings.meta_directory,
|
||||
shutil.copy(path, os.path.join(meta_directory,
|
||||
basename + str(file_number) + file_ext))
|
||||
|
||||
executor = Executor()
|
||||
executor = Executor(config)
|
||||
executor.execute(agenda, selectors={'ids': args.only_run_ids})
|
||||
|
||||
def set_up_output_directory(self, args):
|
||||
if args.output_directory:
|
||||
settings.output_directory = args.output_directory
|
||||
self.logger.debug('Using output directory: {}'.format(settings.output_directory))
|
||||
if os.path.exists(settings.output_directory):
|
||||
output_directory = args.output_directory
|
||||
else:
|
||||
output_directory = settings.default_output_directory
|
||||
self.logger.debug('Using output directory: {}'.format(output_directory))
|
||||
if os.path.exists(output_directory):
|
||||
if args.force:
|
||||
self.logger.info('Removing existing output directory.')
|
||||
shutil.rmtree(settings.output_directory)
|
||||
shutil.rmtree(os.path.abspath(output_directory))
|
||||
else:
|
||||
self.logger.error('Output directory {} exists.'.format(settings.output_directory))
|
||||
self.logger.error('Output directory {} exists.'.format(output_directory))
|
||||
self.logger.error('Please specify another location, or use -f option to overwrite.\n')
|
||||
sys.exit(1)
|
||||
|
||||
self.logger.info('Creating output directory.')
|
||||
os.makedirs(settings.output_directory)
|
||||
os.makedirs(settings.meta_directory)
|
||||
os.makedirs(output_directory)
|
||||
return output_directory
|
||||
|
@@ -18,7 +18,9 @@ import sys
|
||||
import subprocess
|
||||
from cStringIO import StringIO
|
||||
|
||||
from wlauto import Command, ExtensionLoader, settings
|
||||
from wlauto import Command
|
||||
from wlauto.core.config.core import settings
|
||||
from wlauto.core import pluginloader
|
||||
from wlauto.utils.doc import (get_summary, get_description, get_type_name, format_column, format_body,
|
||||
format_paragraph, indent, strip_inlined_text)
|
||||
from wlauto.utils.misc import get_pager
|
||||
@@ -30,21 +32,20 @@ class ShowCommand(Command):
|
||||
name = 'show'
|
||||
|
||||
description = """
|
||||
Display documentation for the specified extension (workload, instrument, etc.).
|
||||
Display documentation for the specified plugin (workload, instrument, etc.).
|
||||
"""
|
||||
|
||||
def initialize(self, context):
|
||||
self.parser.add_argument('name', metavar='EXTENSION',
|
||||
help='''The name of the extension for which information will
|
||||
help='''The name of the plugin for which information will
|
||||
be shown.''')
|
||||
|
||||
def execute(self, args):
|
||||
# pylint: disable=unpacking-non-sequence
|
||||
ext_loader = ExtensionLoader(packages=settings.extension_packages, paths=settings.extension_paths)
|
||||
extension = ext_loader.get_extension_class(args.name)
|
||||
plugin = pluginloader.get_plugin_class(args.name)
|
||||
out = StringIO()
|
||||
term_width, term_height = get_terminal_size()
|
||||
format_extension(extension, out, term_width)
|
||||
format_plugin(plugin, out, term_width)
|
||||
text = out.getvalue()
|
||||
pager = get_pager()
|
||||
if len(text.split('\n')) > term_height and pager:
|
||||
@@ -58,44 +59,44 @@ class ShowCommand(Command):
|
||||
sys.stdout.write(text)
|
||||
|
||||
|
||||
def format_extension(extension, out, width):
|
||||
format_extension_name(extension, out)
|
||||
def format_plugin(plugin, out, width):
|
||||
format_plugin_name(plugin, out)
|
||||
out.write('\n')
|
||||
format_extension_summary(extension, out, width)
|
||||
format_plugin_summary(plugin, out, width)
|
||||
out.write('\n')
|
||||
if hasattr(extension, 'supported_platforms'):
|
||||
format_supported_platforms(extension, out, width)
|
||||
if hasattr(plugin, 'supported_platforms'):
|
||||
format_supported_platforms(plugin, out, width)
|
||||
out.write('\n')
|
||||
if extension.parameters:
|
||||
format_extension_parameters(extension, out, width)
|
||||
if plugin.parameters:
|
||||
format_plugin_parameters(plugin, out, width)
|
||||
out.write('\n')
|
||||
format_extension_description(extension, out, width)
|
||||
format_plugin_description(plugin, out, width)
|
||||
|
||||
|
||||
def format_extension_name(extension, out):
|
||||
out.write('\n{}\n'.format(extension.name))
|
||||
def format_plugin_name(plugin, out):
|
||||
out.write('\n{}\n'.format(plugin.name))
|
||||
|
||||
|
||||
def format_extension_summary(extension, out, width):
|
||||
out.write('{}\n'.format(format_body(strip_inlined_text(get_summary(extension)), width)))
|
||||
def format_plugin_summary(plugin, out, width):
|
||||
out.write('{}\n'.format(format_body(strip_inlined_text(get_summary(plugin)), width)))
|
||||
|
||||
|
||||
def format_supported_platforms(extension, out, width):
|
||||
text = 'supported on: {}'.format(', '.join(extension.supported_platforms))
|
||||
def format_supported_platforms(plugin, out, width):
|
||||
text = 'supported on: {}'.format(', '.join(plugin.supported_platforms))
|
||||
out.write('{}\n'.format(format_body(text, width)))
|
||||
|
||||
|
||||
def format_extension_description(extension, out, width):
|
||||
def format_plugin_description(plugin, out, width):
|
||||
# skip the initial paragraph of multi-paragraph description, as already
|
||||
# listed above.
|
||||
description = get_description(extension).split('\n\n', 1)[-1]
|
||||
description = get_description(plugin).split('\n\n', 1)[-1]
|
||||
out.write('{}\n'.format(format_body(strip_inlined_text(description), width)))
|
||||
|
||||
|
||||
def format_extension_parameters(extension, out, width, shift=4):
|
||||
def format_plugin_parameters(plugin, out, width, shift=4):
|
||||
out.write('parameters:\n\n')
|
||||
param_texts = []
|
||||
for param in extension.parameters:
|
||||
for param in plugin.parameters:
|
||||
description = format_paragraph(strip_inlined_text(param.description or ''), width - shift)
|
||||
param_text = '{}'.format(param.name)
|
||||
if param.mandatory:
|
||||
@@ -111,4 +112,3 @@ def format_extension_parameters(extension, out, width, shift=4):
|
||||
param_texts.append(indent(param_text, shift))
|
||||
|
||||
out.write(format_column('\n'.join(param_texts), width))
|
||||
|
||||
|
Reference in New Issue
Block a user