1
0

bdist_dumb.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """distutils.command.bdist_dumb
  2. Implements the Distutils 'bdist_dumb' command (create a "dumb" built
  3. distribution -- i.e., just an archive to be unpacked under $prefix or
  4. $exec_prefix)."""
  5. import os
  6. from distutils.core import Command
  7. from distutils.util import get_platform
  8. from distutils.dir_util import remove_tree, ensure_relative
  9. from distutils.errors import *
  10. from distutils.sysconfig import get_python_version
  11. from distutils import log
  12. class bdist_dumb(Command):
  13. description = "create a \"dumb\" built distribution"
  14. user_options = [('bdist-dir=', 'd',
  15. "temporary directory for creating the distribution"),
  16. ('plat-name=', 'p',
  17. "platform name to embed in generated filenames "
  18. "(default: %s)" % get_platform()),
  19. ('format=', 'f',
  20. "archive format to create (tar, gztar, bztar, xztar, "
  21. "ztar, zip)"),
  22. ('keep-temp', 'k',
  23. "keep the pseudo-installation tree around after " +
  24. "creating the distribution archive"),
  25. ('dist-dir=', 'd',
  26. "directory to put final built distributions in"),
  27. ('skip-build', None,
  28. "skip rebuilding everything (for testing/debugging)"),
  29. ('relative', None,
  30. "build the archive using relative paths "
  31. "(default: false)"),
  32. ('owner=', 'u',
  33. "Owner name used when creating a tar file"
  34. " [default: current user]"),
  35. ('group=', 'g',
  36. "Group name used when creating a tar file"
  37. " [default: current group]"),
  38. ]
  39. boolean_options = ['keep-temp', 'skip-build', 'relative']
  40. default_format = { 'posix': 'gztar',
  41. 'nt': 'zip' }
  42. def initialize_options(self):
  43. self.bdist_dir = None
  44. self.plat_name = None
  45. self.format = None
  46. self.keep_temp = 0
  47. self.dist_dir = None
  48. self.skip_build = None
  49. self.relative = 0
  50. self.owner = None
  51. self.group = None
  52. def finalize_options(self):
  53. if self.bdist_dir is None:
  54. bdist_base = self.get_finalized_command('bdist').bdist_base
  55. self.bdist_dir = os.path.join(bdist_base, 'dumb')
  56. if self.format is None:
  57. try:
  58. self.format = self.default_format[os.name]
  59. except KeyError:
  60. raise DistutilsPlatformError(
  61. "don't know how to create dumb built distributions "
  62. "on platform %s" % os.name)
  63. self.set_undefined_options('bdist',
  64. ('dist_dir', 'dist_dir'),
  65. ('plat_name', 'plat_name'),
  66. ('skip_build', 'skip_build'))
  67. def run(self):
  68. if not self.skip_build:
  69. self.run_command('build')
  70. install = self.reinitialize_command('install', reinit_subcommands=1)
  71. install.root = self.bdist_dir
  72. install.skip_build = self.skip_build
  73. install.warn_dir = 0
  74. log.info("installing to %s", self.bdist_dir)
  75. self.run_command('install')
  76. # And make an archive relative to the root of the
  77. # pseudo-installation tree.
  78. archive_basename = "%s.%s" % (self.distribution.get_fullname(),
  79. self.plat_name)
  80. pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
  81. if not self.relative:
  82. archive_root = self.bdist_dir
  83. else:
  84. if (self.distribution.has_ext_modules() and
  85. (install.install_base != install.install_platbase)):
  86. raise DistutilsPlatformError(
  87. "can't make a dumb built distribution where "
  88. "base and platbase are different (%s, %s)"
  89. % (repr(install.install_base),
  90. repr(install.install_platbase)))
  91. else:
  92. archive_root = os.path.join(self.bdist_dir,
  93. ensure_relative(install.install_base))
  94. # Make the archive
  95. filename = self.make_archive(pseudoinstall_root,
  96. self.format, root_dir=archive_root,
  97. owner=self.owner, group=self.group)
  98. if self.distribution.has_ext_modules():
  99. pyversion = get_python_version()
  100. else:
  101. pyversion = 'any'
  102. self.distribution.dist_files.append(('bdist_dumb', pyversion,
  103. filename))
  104. if not self.keep_temp:
  105. remove_tree(self.bdist_dir, dry_run=self.dry_run)