Merge lp:~qcxhome/pyflakes/pyflakes-options--exclude into lp:pyflakes

Proposed by Chenxiong Qi
Status: Needs review
Proposed branch: lp:~qcxhome/pyflakes/pyflakes-options--exclude
Merge into: lp:pyflakes
Diff against target: 72 lines (+40/-5)
1 file modified
pyflakes/api.py (+40/-5)
To merge this branch: bzr merge lp:~qcxhome/pyflakes/pyflakes-options--exclude
Reviewer Review Type Date Requested Status
Pyflakes Dev Pending
Review via email: mp+180500@code.launchpad.net

Description of the change

Hi Team,

To exclude some files or directories is more useful. In some cases, a django-based project might have directory named migrations to track models' changes, and test code within tests/ or tests.py. All these files and directories are not necessary to be checked with pyflakes. Without option --exclude, user has to specify all other files and directories that must be checked. It's not very convenient. Hope this commit be useful to pyflakes' users.

Regards,
Chenxiong Qi

To post a comment you must log in.
109. By Chenxiong Qi

change to help text of exclude option

Unmerged revisions

109. By Chenxiong Qi

change to help text of exclude option

108. By Chenxiong Qi

add --exclude option

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pyflakes/api.py'
--- pyflakes/api.py 2013-04-21 09:32:10 +0000
+++ pyflakes/api.py 2013-08-17 03:26:51 +0000
@@ -104,7 +104,14 @@
104 yield path104 yield path
105105
106106
107def checkRecursive(paths, reporter):107def is_path_excluded(path, exclude_patterns):
108 if exclude_patterns is None:
109 return False
110 result = set(exclude_patterns) & set(path.split(os.sep))
111 return len(result) > 0
112
113
114def checkRecursive(paths, reporter, options):
108 """115 """
109 Recursively check all source files in C{paths}.116 Recursively check all source files in C{paths}.
110117
@@ -112,20 +119,48 @@
112 containing Python source files.119 containing Python source files.
113 @param reporter: A L{Reporter} where all of the warnings and errors120 @param reporter: A L{Reporter} where all of the warnings and errors
114 will be reported to.121 will be reported to.
122 @param options: options passed in the command line.
115 @return: The number of warnings found.123 @return: The number of warnings found.
116 """124 """
117 warnings = 0125 warnings = 0
126 patterns = options.exclude_patterns
118 for sourcePath in iterSourceCode(paths):127 for sourcePath in iterSourceCode(paths):
119 warnings += checkPath(sourcePath, reporter)128 if not is_path_excluded(sourcePath, patterns):
129 warnings += checkPath(sourcePath, reporter)
120 return warnings130 return warnings
121131
122132
133def build_options_parser(prog, version):
134 parser = OptionParser(prog=prog, version=version)
135 parser.add_option('--exclude', action='store',
136 metavar='patterns', dest='exclude_patterns',
137 help='exclude files or directories which match patterns '
138 'separated by comma. Specify the basename instead '
139 'of relative or absolute path. (default: '
140 '.svn,CVS,.bzr,.hg,.git)')
141 return parser
142
143
144def clean_options(options):
145 patterns = options.exclude_patterns
146 default_patterns = ['.svn', 'CVS', '.bzr', '.hg', '.git']
147 if patterns is not None:
148 options.exclude_patterns = default_patterns + patterns.split(',')
149
150
151def parse_args(prog, version):
152 parser = build_options_parser(prog=prog, version=version)
153 opts, args = parser.parse_args()
154 clean_options(opts)
155 return opts, args
156
157
123def main(prog=None):158def main(prog=None):
124 parser = OptionParser(prog=prog, version=__version__)159 opts, args = parse_args(prog=prog, version=__version__)
125 __, args = parser.parse_args()160
126 reporter = modReporter._makeDefaultReporter()161 reporter = modReporter._makeDefaultReporter()
127 if args:162 if args:
128 warnings = checkRecursive(args, reporter)163 warnings = checkRecursive(args, reporter, opts)
129 else:164 else:
130 warnings = check(sys.stdin.read(), '<stdin>', reporter)165 warnings = check(sys.stdin.read(), '<stdin>', reporter)
131 raise SystemExit(warnings > 0)166 raise SystemExit(warnings > 0)

Subscribers

People subscribed via source and target branches

to all changes: