Skip to content

Commit

Permalink
Extension of #481 (#499)
Browse files Browse the repository at this point in the history
* Show installers version with --version option

Specifically, pip and setuptools version is crucial because
pip distributed on apt is very old on Ubuntu 14.04.
I think showing the version of installer helps user to resolve
their issue caused by old package managing tools.

Usage:

  $ rosdep --version
  gem version unknown
  source version unknown
  rosdep version 0.11.5
  apt-get version 1.0.1ubuntu2
  pip version 8.1.2
  setuptools version 28.6.1

* add option --all-versions

other fix ups as well and added Homebrew/Macports
  • Loading branch information
wjwwood authored Apr 28, 2017
1 parent 1a20d2f commit 8c276a4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/rosdep2/installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ def is_installed(self, resolved_item):
'''
return not self.get_packages_to_install([resolved_item])

def get_version_strings(self):
'''
Return a list of version information strings.
Where each string is of the form "<installer> <version string>".
For example, ["apt-get x.y.z"] or ["pip x.y.z", "setuptools x.y.z"].
'''
raise NotImplementedError('subclasses must implement get_version_strings method')

def get_install_command(self, resolved, interactive=True, reinstall=False, quiet=False):
raise NotImplementedError('subclasses must implement', resolved, interactive, reinstall, quiet)

Expand Down
35 changes: 32 additions & 3 deletions src/rosdep2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ def _rosdep_main(args):
parser.add_option("--verbose", "-v", dest="verbose", default=False,
action="store_true", help="verbose display")
parser.add_option("--version", dest="print_version", default=False,
action="store_true", help="print version and exit")
action="store_true", help="print just the rosdep version, then exit")
parser.add_option("--all-versions", dest="print_all_versions", default=False,
action="store_true", help="print rosdep version and version of installers, then exit")
parser.add_option("--reinstall", dest="reinstall", default=False,
action="store_true", help="(re)install all dependencies, even if already installed")
parser.add_option("--default-yes", "-y", dest="default_yes", default=False,
Expand Down Expand Up @@ -320,8 +322,35 @@ def _rosdep_main(args):
"Can be specified multiple times.")

options, args = parser.parse_args(args)
if options.print_version:
print(__version__)
if options.print_version or options.print_all_versions:
# First print the rosdep version.
print('{}'.format(__version__))
# If not printing versions of all installers, exit.
if not options.print_all_versions:
sys.exit(0)
# Otherwise, Then collect the versions of the installers and print them.
installers = create_default_installer_context().installers
installer_keys = get_default_installer()[1]
version_strings = []
for key in installer_keys:
if key is 'source':
# Explicitly skip the source installer.
continue
installer = installers[key]
try:
installer_version_strings = installer.get_version_strings()
assert isinstance(installer_version_strings, list), installer_version_strings
version_strings.extend(installer_version_strings)
except NotImplementedError:
version_strings.append('{} unknown'.format(key))
continue
if version_strings:
print()
print("Versions of installers:")
print('\n'.join([' ' + x for x in version_strings if x]))
else:
print()
print("No installers with versions available found.")
sys.exit(0)

# flatten list of skipped keys and filter-for-installers
Expand Down
6 changes: 6 additions & 0 deletions src/rosdep2/platforms/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# Author Tully Foote, Ken Conley

from __future__ import print_function
import subprocess
import sys
import re

Expand Down Expand Up @@ -201,6 +202,11 @@ class AptInstaller(PackageManagerInstaller):
def __init__(self):
super(AptInstaller, self).__init__(dpkg_detect)

def get_version_strings(self):
output = subprocess.check_output(['apt-get', '--version'])
version = output.splitlines()[0].split(' ')[1]
return ['apt-get {}'.format(version)]

def get_install_command(self, resolved, interactive=True, reinstall=False, quiet=False):
packages = self.get_packages_to_install(resolved, reinstall=reinstall)
if not packages:
Expand Down
4 changes: 4 additions & 0 deletions src/rosdep2/platforms/gem.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class GemInstaller(PackageManagerInstaller):
def __init__(self):
super(GemInstaller, self).__init__(gem_detect, supports_depends=True)

def get_version_strings(self):
gem_version = subprocess.check_output(['gem', '--version']).strip()
return ['gem {}'.format(gem_version)]

def get_install_command(self, resolved, interactive=True, reinstall=False, quiet=False):
if not is_gem_installed():
raise InstallFailed((GEM_INSTALLER, "gem is not installed"))
Expand Down
23 changes: 23 additions & 0 deletions src/rosdep2/platforms/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ class MacportsInstaller(PackageManagerInstaller):
def __init__(self):
super(MacportsInstaller, self).__init__(port_detect)

def get_version_strings(self):
try:
p = subprocess.Popen(
['port', 'version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
version = stdout.replace('Version: ', '')
return ['Macports {}'.format(version.strip())]
except OSError:
return ['Macports not-found']

def get_install_command(self, resolved, interactive=True, reinstall=False):
if not is_port_installed():
raise InstallFailed((MACPORTS_INSTALLER, 'MacPorts is not installed'))
Expand Down Expand Up @@ -251,6 +263,17 @@ def __init__(self):
super(HomebrewInstaller, self).__init__(brew_detect, supports_depends=True)
self.as_root = False

def get_version_strings(self):
try:
p = subprocess.Popen(
['brew', '--version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
return stdout.splitlines()
except OSError:
return ['Homebrew not-found']

def resolve(self, rosdep_args):
"""
See :meth:`Installer.resolve()`
Expand Down
10 changes: 10 additions & 0 deletions src/rosdep2/platforms/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from __future__ import print_function

import pkg_resources
import subprocess

from ..core import InstallFailed
Expand Down Expand Up @@ -100,6 +101,15 @@ class PipInstaller(PackageManagerInstaller):
def __init__(self):
super(PipInstaller, self).__init__(pip_detect, supports_depends=True)

def get_version_strings(self):
pip_version = pkg_resources.get_distribution('pip').version
setuptools_version = pkg_resources.get_distribution('setuptools').version
version_strings = [
'pip {}'.format(pip_version),
'setuptools {}'.format(setuptools_version),
]
return version_strings

def get_install_command(self, resolved, interactive=True, reinstall=False, quiet=False):
if not is_pip_installed():
raise InstallFailed((PIP_INSTALLER, "pip is not installed"))
Expand Down

0 comments on commit 8c276a4

Please sign in to comment.