Skip to content

Commit

Permalink
swc-installation-test-2.py: Also look for extension-less paths
Browse files Browse the repository at this point in the history
Before this commit, CommandDependency checked self.command (with an
optional extension determined by distutils).  If that check failed to
produce a version stream, we cycled through a list of additional
hard-coded paths.  For example:  Notepad++ used:

  self.command = 'notepad++'
  self.paths = [
      _os.path.join(
          _ROOT_PATH, 'Program Files', 'Notepad++', 'notepad++.exe'),
      ]

Because some MS Windows commands lack the expected '.exe' extension,
but are still present and detected by a number of shells, we should
also look for the extension-less version of the command.

I consolidated the _get_version_stream() logic to build a single list
of paths and loop through it looking for success (and accumulating
errors).  This makes the handling of self.paths less of a special
case, and sets us up for any additional path mangling we may need to
support other poorly standardized OSes ;).
  • Loading branch information
W. Trevor King committed Mar 21, 2013
1 parent 22a8bd5 commit 03b86fc
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions setup/swc-installation-test-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,25 +455,22 @@ def _get_command_version_stream(self, command=None, stdin=None,
raise NotImplementedError(self.version_stream)

def _get_version_stream(self, **kwargs):
try:
return self._get_command_version_stream(**kwargs)
except DependencyError as e:
if self.paths:
or_errors = [e]
for path in self.paths:
try:
return self._get_command_version_stream(
command=path, **kwargs)
except DependencyError as e:
print('a')
or_errors.append(e)
raise DependencyError(
checker=self,
message='errors finding {0} version'.format(
self.full_name()),
causes=or_errors)
else:
raise
paths = [self.command + (self.exe_extension or '')]
if self.exe_extension:
paths.append(self.command) # also look at the extension-less path
if self.paths:
paths.extend(self.paths)
or_errors = []
for path in paths:
try:
return self._get_command_version_stream(command=path, **kwargs)
except DependencyError as e:
or_errors.append(e)
raise DependencyError(
checker=self,
message='errors finding {0} version'.format(
self.full_name()),
causes=or_errors)

def _get_version(self):
version_stream = self._get_version_stream()
Expand Down

0 comments on commit 03b86fc

Please sign in to comment.