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 #68

Closed
wants to merge 2 commits into from
Closed
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
123 changes: 64 additions & 59 deletions prospector/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@


class Prospector(object):
def __init__(self, config, path):
def __init__(self, config, paths):
self.config = config
self.path = path
if os.path.isdir(path):
self.rootpath = path
else:
self.rootpath = os.getcwd()
self.paths = paths
self.adaptors = []
self.libraries = []
self.profiles = []
Expand All @@ -42,19 +38,20 @@ def __init__(self, config, path):
self.summary = None
self.messages = None

self._determine_adapters()
self._determine_profiles()
for path in self.paths:
self._determine_adapters(path)
self._determine_profiles(path)
self._determine_tool_runners()
self._determine_ignores()

def _determine_adapters(self):
def _determine_adapters(self, path):
# Bring in the common adaptor
if self.config.common_plugin:
self.adaptors.append(CommonAdaptor())

# Bring in adaptors that we automatically detect are needed
if self.config.autodetect:
for name, adaptor in autodetect_libraries(self.path):
for name, adaptor in autodetect_libraries(path):
self.libraries.append(name)
self.adaptors.append(adaptor)

Expand All @@ -64,7 +61,7 @@ def _determine_adapters(self):
self.libraries.append(name)
self.adaptors.append(LIBRARY_ADAPTORS[name]())

def _determine_profiles(self):
def _determine_profiles(self, path):

# Use other specialty profiles based on options
if not self.config.doc_warnings:
Expand All @@ -84,12 +81,12 @@ def _determine_profiles(self):

# if there is a '.prospector.yaml' or a '.prospector/prospector.yaml'
# file then we'll include that
prospector_yaml = os.path.join(self.path, '.prospector.yaml')
prospector_yaml = os.path.join(path, '.prospector.yaml')
if os.path.exists(prospector_yaml) and os.path.isfile(prospector_yaml):
profile_provided = True
self.profiles.append(prospector_yaml)

prospector_yaml = os.path.join(self.path, 'prospector', 'prospector.yaml')
prospector_yaml = os.path.join(path, 'prospector', 'prospector.yaml')
if os.path.exists(prospector_yaml) and os.path.isfile('prospector'):
profile_provided = True
self.profiles.append(prospector_yaml)
Expand All @@ -102,18 +99,20 @@ def _determine_profiles(self):
else:
self.strictness = 'from profile'

self.profiles = list(set(self.profiles))

# the profile path is
# * anything provided as an argument
# * a directory called .prospector in the check path
# * the check path
# * prospector provided profiles
profile_path = self.config.profile_path

prospector_dir = os.path.join(self.path, '.prospector')
prospector_dir = os.path.join(path, '.prospector')
if os.path.exists(prospector_dir) and os.path.isdir(prospector_dir):
profile_path.append(prospector_dir)

profile_path.append(self.path)
profile_path.append(path)

provided = os.path.join(os.path.dirname(__file__), 'profiles/profiles')
profile_path.append(provided)
Expand Down Expand Up @@ -187,12 +186,15 @@ def _determine_ignores(self):

self.ignores = ignores

def process_messages(self, messages):
def process_messages(self, messages, path):
rootpath = os.getcwd()
if os.path.isdir(path):
rootpath = path
for message in messages:
if self.config.absolute_paths:
message.to_absolute_path(self.rootpath)
message.to_absolute_path(rootpath)
else:
message.to_relative_path(self.rootpath)
message.to_relative_path(rootpath)
if self.config.blending:
messages = blender.blend(messages)

Expand All @@ -205,49 +207,52 @@ def execute(self):
'libraries': self.libraries,
'strictness': self.strictness,
'profiles': self.profiles,
'adaptors': [adaptor.name for adaptor in self.adaptors],
'adaptors': list(set([adaptor.name for adaptor in self.adaptors])),
'tools': self.tools_to_run,
}

# Find the files and packages in a common way, so that each tool
# gets the same list.
found_files = find_python(self.ignores, self.path)

# Prep the tools.
for tool in self.tool_runners:
tool.prepare(found_files, self.config, self.adaptors)

# Run the tools
messages = []
for tool in self.tool_runners:
try:
messages += tool.run()
except Exception: # pylint: disable=W0703
if self.config.die_on_tool_error:
raise
else:
for name, cls in tools.TOOLS.items():
if cls == tool.__class__:
toolname = name
break
all_messages = []
for path in self.paths:

# Find the files and packages in a common way, so that each tool
# gets the same list.
found_files = find_python(self.ignores, path)

# Prep the tools.
for tool in self.tool_runners:
tool.prepare(found_files, self.config, self.adaptors)

# Run the tools
messages = []
for tool in self.tool_runners:
try:
messages += tool.run()
except Exception: # pylint: disable=W0703
if self.config.die_on_tool_error:
raise
else:
toolname = 'Unknown'

loc = Location(self.path, None, None, None, None)
msg = 'Tool %s failed to run (exception was raised)' % (
toolname,
)
message = Message(
toolname,
'failure',
loc,
message=msg,
)
messages.append(message)

messages = self.process_messages(messages)

summary['message_count'] = len(messages)
for name, cls in tools.TOOLS.items():
if cls == tool.__class__:
toolname = name
break
else:
toolname = 'Unknown'

loc = Location(path, None, None, None, None)
msg = 'Tool %s failed to run (exception was raised)' % (
toolname,
)
message = Message(
toolname,
'failure',
loc,
message=msg,
)
messages.append(message)

all_messages.extend(self.process_messages(messages, path))

summary['message_count'] = len(all_messages)
summary['completed'] = datetime.now()

# Timedelta.total_seconds() is not available
Expand All @@ -258,7 +263,7 @@ def execute(self):
summary['time_taken'] = '%0.2f' % total_seconds

self.summary = summary
self.messages = messages
self.messages = all_messages

def get_summary(self):
return self.summary
Expand Down Expand Up @@ -313,7 +318,7 @@ def main():
paths = [os.getcwd()]

# Make it so
prospector = Prospector(config, paths[0])
prospector = Prospector(config, paths)
prospector.execute()
prospector.print_messages()

Expand Down