~anitanayak/charms/trusty/ibm-mq/ibm-mq-trusty

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/flake8/main/setuptools_command.py

  • Committer: Anita Nayak
  • Date: 2016-10-24 07:10:08 UTC
  • Revision ID: anitanayak@in.ibm.com-20161024071008-tqk3cefak6nc1c69
checking in after fixing lint errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""The logic for Flake8's integration with setuptools."""
 
2
import os
 
3
 
 
4
import setuptools
 
5
 
 
6
from flake8.main import application as app
 
7
 
 
8
UNSET = object()
 
9
 
 
10
 
 
11
class Flake8(setuptools.Command):
 
12
    """Run Flake8 via setuptools/distutils for registered modules."""
 
13
 
 
14
    description = 'Run Flake8 on modules registered in setup.py'
 
15
    # NOTE(sigmavirus24): If we populated this with a list of tuples, users
 
16
    # could do something like ``python setup.py flake8 --ignore=E123,E234``
 
17
    # but we would have to redefine it and we can't define it dynamically.
 
18
    # Since I refuse to copy-and-paste the options here or maintain two lists
 
19
    # of options, and since this will break when users use plugins that
 
20
    # provide command-line options, we are leaving this empty. If users want
 
21
    # to configure this command, they can do so through config files.
 
22
    user_options = []
 
23
 
 
24
    def initialize_options(self):
 
25
        """Override this method to initialize our application."""
 
26
        self.flake8 = app.Application()
 
27
        self.flake8.initialize([])
 
28
        options = self.flake8.option_manager.options
 
29
        for option in options:
 
30
            if option.parse_from_config:
 
31
                setattr(self, option.config_name, UNSET)
 
32
 
 
33
    def finalize_options(self):
 
34
        """Override this to parse the parameters."""
 
35
        options = self.flake8.option_manager.options
 
36
        for option in options:
 
37
            if option.parse_from_config:
 
38
                name = option.config_name
 
39
                value = getattr(self, name, UNSET)
 
40
                if value is UNSET:
 
41
                    continue
 
42
                setattr(self.flake8.options,
 
43
                        name,
 
44
                        option.normalize_from_setuptools(value))
 
45
 
 
46
    def package_files(self):
 
47
        """Collect the files/dirs included in the registered modules."""
 
48
        seen_package_directories = ()
 
49
        directories = self.distribution.package_dir or {}
 
50
        empty_directory_exists = '' in directories
 
51
        packages = self.distribution.packages or []
 
52
        for package in packages:
 
53
            package_directory = package
 
54
            if package in directories:
 
55
                package_directory = directories[package]
 
56
            elif empty_directory_exists:
 
57
                package_directory = os.path.join(directories[''],
 
58
                                                 package_directory)
 
59
 
 
60
            # NOTE(sigmavirus24): Do not collect submodules, e.g.,
 
61
            # if we have:
 
62
            #  - flake8/
 
63
            #  - flake8/plugins/
 
64
            # Flake8 only needs ``flake8/`` to be provided. It will
 
65
            # recurse on its own.
 
66
            if package_directory.startswith(seen_package_directories):
 
67
                continue
 
68
 
 
69
            seen_package_directories += (package_directory,)
 
70
            yield package_directory
 
71
 
 
72
    def module_files(self):
 
73
        """Collect the files listed as py_modules."""
 
74
        modules = self.distribution.py_modules or []
 
75
        filename_from = '{0}.py'.format
 
76
        for module in modules:
 
77
            yield filename_from(module)
 
78
 
 
79
    def distribution_files(self):
 
80
        """Collect package and module files."""
 
81
        for package in self.package_files():
 
82
            yield package
 
83
 
 
84
        for module in self.module_files():
 
85
            yield module
 
86
 
 
87
        yield 'setup.py'
 
88
 
 
89
    def run(self):
 
90
        """Run the Flake8 application."""
 
91
        self.flake8.run_checks(list(self.distribution_files()))
 
92
        self.flake8.formatter.start()
 
93
        self.flake8.report_errors()
 
94
        self.flake8.report_statistics()
 
95
        self.flake8.report_benchmarks()
 
96
        self.flake8.formatter.stop()
 
97
        self.flake8.exit()