paths.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """
  2. Installation paths.
  3. Map the .data/ subdirectory names to install paths.
  4. """
  5. import os.path
  6. import sys
  7. import distutils.dist as dist
  8. import distutils.command.install as install
  9. def get_install_command(name):
  10. # late binding due to potential monkeypatching
  11. d = dist.Distribution({'name':name})
  12. i = install.install(d)
  13. i.finalize_options()
  14. return i
  15. def get_install_paths(name):
  16. """
  17. Return the (distutils) install paths for the named dist.
  18. A dict with ('purelib', 'platlib', 'headers', 'scripts', 'data') keys.
  19. """
  20. paths = {}
  21. i = get_install_command(name)
  22. for key in install.SCHEME_KEYS:
  23. paths[key] = getattr(i, 'install_' + key)
  24. # pip uses a similar path as an alternative to the system's (read-only)
  25. # include directory:
  26. if hasattr(sys, 'real_prefix'): # virtualenv
  27. paths['headers'] = os.path.join(sys.prefix,
  28. 'include',
  29. 'site',
  30. 'python' + sys.version[:3],
  31. name)
  32. return paths