Example #1
0
    def initialize(self, argv: List[str]) -> None:
        """Initialize the application to be run.

        This finds the plugins, registers their options, and parses the
        command-line arguments.
        """
        # NOTE(sigmavirus24): When updating this, make sure you also update
        # our legacy API calls to these same methods.
        prelim_opts, remaining_args = self.parse_preliminary_options(argv)
        flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
        config_finder = config.ConfigFileFinder(
            self.program,
            prelim_opts.append_config,
            config_file=prelim_opts.config,
            ignore_config_files=prelim_opts.isolated,
        )
        self.find_plugins(config_finder)
        self.register_plugin_options()
        self.parse_configuration_and_cli(
            config_finder,
            remaining_args,
        )
        self.make_formatter()
        self.make_guide()
        self.make_file_checker_manager()
Example #2
0
def get_style_guide(**kwargs):
    r"""Provision a StyleGuide for use.

    :param \*\*kwargs:
        Keyword arguments that provide some options for the StyleGuide.
    :returns:
        An initialized StyleGuide
    :rtype:
        :class:`StyleGuide`
    """
    application = app.Application()
    application.parse_preliminary_options_and_args([])
    flake8.configure_logging(
        application.prelim_opts.verbose, application.prelim_opts.output_file
    )
    application.make_config_finder()
    application.find_plugins()
    application.register_plugin_options()
    application.parse_configuration_and_cli([])
    # We basically want application.initialize to be called but with these
    # options set instead before we make our formatter, notifier, internal
    # style guide and file checker manager.
    options = application.options
    for key, value in kwargs.items():
        try:
            getattr(options, key)
            setattr(options, key, value)
        except AttributeError:
            LOG.error('Could not update option "%s"', key)
    application.make_formatter()
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
Example #3
0
def get_style_guide(**kwargs):
    r"""Provision a StyleGuide for use.

    :param \*\*kwargs:
        Keyword arguments that provide some options for the StyleGuide.
    :returns:
        An initialized StyleGuide
    :rtype:
        :class:`StyleGuide`
    """
    application = app.Application()
    application.parse_preliminary_options_and_args([])
    flake8.configure_logging(application.prelim_opts.verbose,
                             application.prelim_opts.output_file)
    application.make_config_finder()
    application.find_plugins()
    application.register_plugin_options()
    application.parse_configuration_and_cli([])
    # We basically want application.initialize to be called but with these
    # options set instead before we make our formatter, notifier, internal
    # style guide and file checker manager.
    options = application.options
    for key, value in kwargs.items():
        try:
            getattr(options, key)
            setattr(options, key, value)
        except AttributeError:
            LOG.error('Could not update option "%s"', key)
    application.make_formatter()
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
Example #4
0
def get_style_guide(argv=None):
    # this is a fork of flake8.api.legacy.get_style_guide
    # to allow passing command line argument
    application = Application()
    if hasattr(application, 'parse_preliminary_options'):
        prelim_opts, remaining_args = application.parse_preliminary_options(
            argv)
        from flake8 import configure_logging
        configure_logging(prelim_opts.verbose, prelim_opts.output_file)
        from flake8.options import config
        config_finder = config.ConfigFileFinder(
            application.program,
            prelim_opts.append_config,
            config_file=prelim_opts.config,
            ignore_config_files=prelim_opts.isolated)
        application.find_plugins(config_finder)
        application.register_plugin_options()
        application.parse_configuration_and_cli(config_finder, remaining_args)
    else:
        application.parse_preliminary_options_and_args([])
        application.make_config_finder()
        application.find_plugins()
        application.register_plugin_options()
        application.parse_configuration_and_cli(argv)
    application.make_formatter()
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
def get_style_guide(argv=None):
    # this is a fork of flake8.api.legacy.get_style_guide
    # to allow passing command line argument
    application = Application()
    application.parse_preliminary_options_and_args(argv)
    configure_logging(
        application.prelim_opts.verbose, application.prelim_opts.output_file)
    application.make_config_finder()
    application.find_plugins()
    application.register_plugin_options()
    application.parse_configuration_and_cli(argv)
    application.make_formatter()
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
Example #6
0
def get_style_guide(argv=None):
    # this is a fork of flake8.api.legacy.get_style_guide
    # to allow passing command line argument
    application = Application()
    application.parse_preliminary_options_and_args(argv)
    configure_logging(application.prelim_opts.verbose,
                      application.prelim_opts.output_file)
    application.make_config_finder()
    application.find_plugins()
    application.register_plugin_options()
    application.parse_configuration_and_cli(argv)
    application.make_formatter()
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
Example #7
0
def get_flake8_style_guide(argv):
    # This is a modified version of flake8.legacy.get_style_guide() in which we pass argv through
    # to parse_configuration_and_cli(), as opposed to a dict of flake8 options.
    # Since we are using config files and a mix plugins, it is not trivial to determine the
    # appropriate options to pass into the standard flake8.legacy.get_style_guide();
    # passing argv gets it to determine the options for us.
    application = flake8_app.Application()
    application.parse_preliminary_options_and_args([])
    flake8.configure_logging(application.prelim_opts.verbose,
                             application.prelim_opts.output_file)
    application.make_config_finder()
    application.find_plugins()
    application.register_plugin_options()
    application.parse_configuration_and_cli(argv)
    application.make_formatter()
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
Example #8
0
    def initialize(self, argv):
        # type: (Optional[List[str]]) -> None
        """Initialize the application to be run.

        This finds the plugins, registers their options, and parses the
        command-line arguments.
        """
        # NOTE(sigmavirus24): When updating this, make sure you also update
        # our legacy API calls to these same methods.
        self.parse_preliminary_options_and_args(argv)
        flake8.configure_logging(self.prelim_opts.verbose,
                                 self.prelim_opts.output_file)
        self.make_config_finder()
        self.find_plugins()
        self.register_plugin_options()
        self.parse_configuration_and_cli(argv)
        self.make_formatter()
        self.make_guide()
        self.make_file_checker_manager()
Example #9
0
    def initialize(self, argv):
        # type: (Optional[List[str]]) -> None
        """Initialize the application to be run.

        This finds the plugins, registers their options, and parses the
        command-line arguments.
        """
        # NOTE(sigmavirus24): When updating this, make sure you also update
        # our legacy API calls to these same methods.
        self.parse_preliminary_options_and_args(argv)
        flake8.configure_logging(
            self.prelim_opts.verbose, self.prelim_opts.output_file
        )
        self.make_config_finder()
        self.find_plugins()
        self.register_plugin_options()
        self.parse_configuration_and_cli(argv)
        self.make_formatter()
        self.make_guide()
        self.make_file_checker_manager()
Example #10
0
def test_flake8():
    configure_logging(1)
    argv = [
        '--extend-ignore=' + ','.join(
            ['A003', 'D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107']),
        '--exclude', 'vcstool/compat/shutil.py', '--import-order-style=google'
    ]
    style_guide = get_style_guide(argv)
    base_path = os.path.join(os.path.dirname(__file__), '..')
    paths = [
        os.path.join(base_path, 'setup.py'),
        os.path.join(base_path, 'test'),
        os.path.join(base_path, 'vcstool'),
    ]
    scripts_path = os.path.join(base_path, 'scripts')
    for script in os.listdir(scripts_path):
        if script.startswith('.'):
            continue
        paths.append(os.path.join(scripts_path, script))
    report = style_guide.check_files(paths)
    assert report.total_errors == 0, \
        'Found %d code style warnings' % report.total_errors
Example #11
0
def get_flake8_style_guide(argv):
    # This is a modified version of flake8.legacy.get_style_guide() in which we pass argv through
    # to parse_configuration_and_cli(), as opposed to a dict of flake8 options.
    # Since we are using config files and a mix plugins, it is not trivial to determine the
    # appropriate options to pass into the standard flake8.legacy.get_style_guide();
    # passing argv gets it to determine the options for us.
    application = flake8_app.Application()
    application.parse_preliminary_options_and_args([])
    flake8.configure_logging(
        application.prelim_opts.verbose, application.prelim_opts.output_file)
    application.make_config_finder()
    application.find_plugins()
    application.register_plugin_options()
    application.parse_configuration_and_cli(argv)
    application.make_formatter()
    try:
        # needed in older flake8 versions to populate the listener
        application.make_notifier()
    except AttributeError:
        pass
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
Example #12
0
def get_flake8_style_guide(argv):
    # This is a modified version of flake8.legacy.get_style_guide() in which we pass argv through
    # to parse_configuration_and_cli(), as opposed to a dict of flake8 options.
    # Since we are using config files and a mix plugins, it is not trivial to determine the
    # appropriate options to pass into the standard flake8.legacy.get_style_guide();
    # passing argv gets it to determine the options for us.
    application = flake8_app.Application()
    if hasattr(application, 'parse_preliminary_options'):
        prelim_opts, remaining_args = application.parse_preliminary_options(
            argv)
        flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
        from flake8.options import config
        config_finder = config.ConfigFileFinder(
            application.program,
            prelim_opts.append_config,
            config_file=prelim_opts.config,
            ignore_config_files=prelim_opts.isolated)
        application.find_plugins(config_finder)
        application.register_plugin_options()
        application.parse_configuration_and_cli(config_finder, remaining_args)
    else:
        application.parse_preliminary_options_and_args([])
        flake8.configure_logging(application.prelim_opts.verbose,
                                 application.prelim_opts.output_file)
        application.make_config_finder()
        application.find_plugins()
        application.register_plugin_options()
        application.parse_configuration_and_cli(argv)
    application.make_formatter()
    try:
        # needed in older flake8 versions to populate the listener
        application.make_notifier()
    except AttributeError:
        pass
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
Example #13
0
    def __init__(self, program='flake8', version=flake8.__version__):
        # type: (str, str) -> NoneType
        """Initialize our application.

        :param str program:
            The name of the program/application that we're executing.
        :param str version:
            The version of the program/application we're executing.
        """
        #: The timestamp when the Application instance was instantiated.
        self.start_time = time.time()
        #: The timestamp when the Application finished reported errors.
        self.end_time = None
        #: The name of the program being run
        self.program = program
        #: The version of the program being run
        self.version = version
        #: The instance of :class:`flake8.options.manager.OptionManager` used
        #: to parse and handle the options and arguments passed by the user
        self.option_manager = manager.OptionManager(
            prog='flake8', version=flake8.__version__
        )
        options.register_default_options(self.option_manager)

        # We haven't found or registered our plugins yet, so let's defer
        # printing the version until we aggregate options from config files
        # and the command-line. First, let's clone our arguments on the CLI,
        # then we'll attempt to remove ``--version`` so that we can avoid
        # triggering the "version" action in optparse. If it's not there, we
        # do not need to worry and we can continue. If it is, we successfully
        # defer printing the version until just a little bit later.
        # Similarly we have to defer printing the help text until later.
        args = sys.argv[:]
        try:
            args.remove('--version')
        except ValueError:
            pass
        try:
            args.remove('--help')
        except ValueError:
            pass
        try:
            args.remove('-h')
        except ValueError:
            pass

        preliminary_opts, _ = self.option_manager.parse_known_args(args)
        # Set the verbosity of the program
        flake8.configure_logging(preliminary_opts.verbose,
                                 preliminary_opts.output_file)

        #: The instance of :class:`flake8.plugins.manager.Checkers`
        self.check_plugins = None
        #: The instance of :class:`flake8.plugins.manager.Listeners`
        self.listening_plugins = None
        #: The instance of :class:`flake8.plugins.manager.ReportFormatters`
        self.formatting_plugins = None
        #: The user-selected formatter from :attr:`formatting_plugins`
        self.formatter = None
        #: The :class:`flake8.plugins.notifier.Notifier` for listening plugins
        self.listener_trie = None
        #: The :class:`flake8.style_guide.StyleGuide` built from the user's
        #: options
        self.guide = None
        #: The :class:`flake8.checker.Manager` that will handle running all of
        #: the checks selected by the user.
        self.file_checker_manager = None

        #: The user-supplied options parsed into an instance of
        #: :class:`optparse.Values`
        self.options = None
        #: The left over arguments that were not parsed by
        #: :attr:`option_manager`
        self.args = None
        #: The number of errors, warnings, and other messages after running
        #: flake8 and taking into account ignored errors and lines.
        self.result_count = 0
        #: The total number of errors before accounting for ignored errors and
        #: lines.
        self.total_result_count = 0
        #: Whether or not something catastrophic happened and we should exit
        #: with a non-zero status code
        self.catastrophic_failure = False

        #: Whether the program is processing a diff or not
        self.running_against_diff = False
        #: The parsed diff information
        self.parsed_diff = {}
Example #14
0
"""Test configuration for py.test."""
import sys

import flake8

flake8.configure_logging(2, 'test-logs-%s.%s.log' % sys.version_info[0:2])
Example #15
0
from lsst.ts.hvac.enums import (
    HvacTopic,
    TOPICS_ALWAYS_ENABLED,
    TOPICS_WITHOUT_CONFIGURATION,
)
from lsst.ts.hvac.utils import to_camel_case
import hvac_test_utils
from lsst.ts.idl.enums.HVAC import DeviceId, DEVICE_GROUPS

STD_TIMEOUT = 2  # standard command timeout (sec)

logging.basicConfig(format="%(asctime)s:%(levelname)s:%(name)s:%(message)s",
                    level=logging.DEBUG)

# Make sure that flake8 log level is set to logging.INFO
flake8.configure_logging(1)


class CscTestCase(salobj.BaseCscTestCase, unittest.IsolatedAsyncioTestCase):
    def basic_make_csc(self, initial_state, simulation_mode, **kwargs):
        return hvac.HvacCsc(
            initial_state=initial_state,
            simulation_mode=simulation_mode,
            start_telemetry_publishing=False,
        )

    async def test_standard_state_transitions(self):
        async with self.make_csc(
                initial_state=salobj.State.STANDBY,
                simulation_mode=1,
        ):
Example #16
0
    def __init__(self, program='flake8', version=flake8.__version__):
        # type: (str, str) -> NoneType
        """Initialize our application.

        :param str program:
            The name of the program/application that we're executing.
        :param str version:
            The version of the program/application we're executing.
        """
        #: The timestamp when the Application instance was instantiated.
        self.start_time = time.time()
        #: The timestamp when the Application finished reported errors.
        self.end_time = None
        #: The name of the program being run
        self.program = program
        #: The version of the program being run
        self.version = version
        #: The instance of :class:`flake8.options.manager.OptionManager` used
        #: to parse and handle the options and arguments passed by the user
        self.option_manager = manager.OptionManager(
            prog='flake8', version=flake8.__version__
        )
        options.register_default_options(self.option_manager)

        # We haven't found or registered our plugins yet, so let's defer
        # printing the version until we aggregate options from config files
        # and the command-line. First, let's clone our arguments on the CLI,
        # then we'll attempt to remove ``--version`` so that we can avoid
        # triggering the "version" action in optparse. If it's not there, we
        # do not need to worry and we can continue. If it is, we successfully
        # defer printing the version until just a little bit later.
        # Similarly we have to defer printing the help text until later.
        args = sys.argv[:]
        try:
            args.remove('--version')
        except ValueError:
            pass
        try:
            args.remove('--help')
        except ValueError:
            pass
        try:
            args.remove('-h')
        except ValueError:
            pass

        preliminary_opts, _ = self.option_manager.parse_known_args(args)
        # Set the verbosity of the program
        flake8.configure_logging(preliminary_opts.verbose,
                                 preliminary_opts.output_file)

        #: The instance of :class:`flake8.plugins.manager.Checkers`
        self.check_plugins = None
        #: The instance of :class:`flake8.plugins.manager.Listeners`
        self.listening_plugins = None
        #: The instance of :class:`flake8.plugins.manager.ReportFormatters`
        self.formatting_plugins = None
        #: The user-selected formatter from :attr:`formatting_plugins`
        self.formatter = None
        #: The :class:`flake8.plugins.notifier.Notifier` for listening plugins
        self.listener_trie = None
        #: The :class:`flake8.style_guide.StyleGuide` built from the user's
        #: options
        self.guide = None
        #: The :class:`flake8.checker.Manager` that will handle running all of
        #: the checks selected by the user.
        self.file_checker_manager = None

        #: The user-supplied options parsed into an instance of
        #: :class:`optparse.Values`
        self.options = None
        #: The left over arguments that were not parsed by
        #: :attr:`option_manager`
        self.args = None
        #: The number of errors, warnings, and other messages after running
        #: flake8 and taking into account ignored errors and lines.
        self.result_count = 0
        #: The total number of errors before accounting for ignored errors and
        #: lines.
        self.total_result_count = 0
        #: Whether or not something catastrophic happened and we should exit
        #: with a non-zero status code
        self.catastrophic_failure = False

        #: Whether the program is processing a diff or not
        self.running_against_diff = False
        #: The parsed diff information
        self.parsed_diff = {}