Source

shrinkwrap / doc / packaging.rst

Diff from to

doc/packaging.rst

     source_url = 'http://www.bzip.org/%(version)s/bzip2-%(version)s.tar.gz' % {'version': version}
 
 
-    def installer(self):
+    def installer(inst):
         self.download_and_unpack_tarball(source_url)
 
         bzip2_dir = 'bzip2-' + version
 
     python bzip2-1.0.6.py install
 
-Here, the ``shrinkwrap_installer`` argument to ``setup()`` is set to our own installer function. The installer uses two shrinkwrap-provided convenience functions, ``download_and_unpack_tarball`` and ``make`` to download, untar, and compile the bzip2 library. See :ref:`shrinkwrap_install_api` for a complete list of convenice functions. By passing extra options to make, the software is installed into the root of the active virtualenv.
+Here, the ``shrinkwrap_installer`` argument to ``setup()`` is set to our own installer function.
+The installer function is called with an instance of ShrinkwrapInstall as the argument, which provides several convenience functions. This installer uses two of these functions, ``download_and_unpack_tarball`` and ``make`` to download, untar, and compile the bzip2 library. See :ref:`shrinkwrap_install_api` for a complete list of available functions. By passing extra options to make, the software is installed into the root of the active virtualenv.
 
 .. note:: For several examples of custom installers, see `https://bitbucket.org/seibert/shrinkwrap_pkgs <https://bitbucket.org/seibert/shrinkwrap_pkgs>`_.
 
     Examples include getting code from version control, installing with cmake, and customizing install paths.
 
+.. _system_packages:
+
+Detecting System-provided Packages
+``````````````````````````````````
+
+In some situations, you only want to install a package if the operating system does not
+already provide it.  The ``shrinkwrap_skip`` argument to ``setup()`` allows you to specify
+a function to call to check if installation is performed.  If the skip function returns 
+True, then the ``installer()`` function is skipped, but the package is marked as installed.
+
+Here is an example of a package that installs curl only if version 7.26.0 is not present::
+
+    try:
+        from shrinkwrap.install import ShrinkwrapInstall
+    except ImportError:
+        import subprocess; subprocess.check_call('pip install -b $VIRTUAL_ENV/build/build-shrinkwrap shrinkwrap', shell=True)
+        from shrinkwrap.install import ShrinkwrapInstall
+    from setuptools import setup
+    from distutils.version import LooseVersion
+
+    version = '7.27.0'
+
+    def skip(inst):
+        try:
+            output = inst.cmd_output('curl-config --version')
+            name, version_str = output.split()
+            system_version = LooseVersion(version_str)
+            min_version = LooseVersion('7.26.0')
+            if system_version > min_version:
+                return True # Don't install
+            else:
+                return False # Version too old
+        except:
+            return False # install package if anything went wrong
+
+    setup(
+        name='curl-check',
+        version=version,
+        author='Stan Seibert',
+        author_email='stan@mtrr.org',
+        shrinkwrap_installer='autoconf',
+        shrinkwrap_skip=skip,
+        shrinkwrap_source_url='http://curl.haxx.se/download/curl-%s.tar.bz2' % version,
+        cmdclass={'install': ShrinkwrapInstall},
+    )
 
 .. _package_dependencies: