message: python: Add a find directive.
diff: # See the LICENSE file for more information.
  import drake
  +import itertools
  +import drake.cxx
  class Package(drake.VirtualNode):
  @@ -52,3 +54,50 @@ class Package(drake.VirtualNode):
  @property
  def fullname(self):
  return self.__fullname
  +
  +def find(python = None,
  + version = None):
  + if version is None:
  + versions = (drake.Version(3, 6),
  + drake.Version(3, 5),
  + drake.Version(3, 4),
  + drake.Version(3, 3),
  + drake.Version(3, 2))
  + elif not isinstance(version, collections.Iterable):
  + versions = (version,)
  + else: # version is already a list.
  + versions = version
  + tk = drake.cxx.Toolkit()
  + windows = tk.os is drake.os.windows
  + if python is None and drake.cxx.PkgConfig.available:
  + def options():
  + for v in versions:
  + yield ('python', v)
  + yield ('python3', v) # CentOS
  + yield ('python-%s' % v, v) # Gentoo
  + for pkg_name, version in options():
  + pkg = drake.cxx.PkgConfig(pkg_name, version = version)
  + if pkg.exists:
  + python3 = pkg.prefix
  + break
  + include_dir = list(itertools.chain(
  + ('include',),
  + *(('include/python%s' % v,
  + 'include/python%sm' % v) for v in versions)))
  + python = drake.cxx.find_library(
  + 'pyconfig.h',
  + prefix = python,
  + include_dir = include_dir)
  + python_version = tk.preprocess('''\
  +#include <patchlevel.h>
  +PY_MAJOR_VERSION
  +PY_MINOR_VERSION''', config = python)
  + python_version = python_version.split('\n')[-3:-1]
  + python_version = drake.Version(*map(int, python_version))
  + if windows:
  + python_bin = 'python.exe'
  + else:
  + python_bin = 'bin/python%s' % python_version
  + python.python_interpreter = python.prefix / python_bin
  + python.version = python_version
  + return python
  