Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple positional path arguments #78

Merged
merged 2 commits into from
Jan 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion prospector/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ def build_command_line_source(prog=None, description='Performs static analysis o
positional = (
('checkpath', {
'help': 'The path to a Python project to inspect. Defaults to PWD'
' if not specified.',
' if not specified. If multiple paths are specified,'
' they must all be files (no directories).',
'metavar': 'PATH',
'nargs': '*',
}),
Expand Down
1 change: 1 addition & 0 deletions prospector/formatters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class TextFormatter(Formatter):
summary_labels = (
('path', 'Path'),
('started', 'Started'),
('completed', 'Finished'),
('time_taken', 'Time Taken', lambda x: '%s seconds' % x),
Expand Down
20 changes: 15 additions & 5 deletions prospector/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def process_messages(self, messages):
def execute(self):

summary = {
'path': self.path,
'started': datetime.now(),
'libraries': self.libraries,
'strictness': self.strictness,
Expand Down Expand Up @@ -284,10 +285,12 @@ def print_messages(self, write_to=None):
self.summary['formatter'] = output_format
formatter = FORMATTERS[output_format](self.summary, self.messages)

print_messages = not self.config.summary_only and self.messages

# Produce the output
write_to.write(formatter.render(
summary=not self.config.messages_only,
messages=not self.config.summary_only,
messages=print_messages,
))
write_to.write('\n')

Expand Down Expand Up @@ -315,10 +318,17 @@ def main():
else:
paths = [os.getcwd()]

if len(paths) > 1 and not all([os.path.isfile(path) for path in paths]):
raise ValueError('In multi-path mode, all inputs must be files, '
'not directories.')

# Make it so
prospector = Prospector(config, paths[0])
prospector.execute()
prospector.print_messages()
messages = []
for path in paths:
prospector = Prospector(config, path)
prospector.execute()
prospector.print_messages()
messages.extend(prospector.get_messages())

if config.zero_exit:
# if we ran successfully, and the user wants us to, then we'll
Expand All @@ -328,7 +338,7 @@ def main():
# otherwise, finding messages is grounds for exiting with an error
# code, to make it easier for bash scripts and similar situations
# to know if there any errors have been found.
if len(prospector.get_messages()) > 0:
if len(messages) > 0:
return 1
return 0

Expand Down