You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

44 lines
1.5 KiB

  1. import distutils.command.bdist_rpm as orig
  2. class bdist_rpm(orig.bdist_rpm):
  3. """
  4. Override the default bdist_rpm behavior to do the following:
  5. 1. Run egg_info to ensure the name and version are properly calculated.
  6. 2. Always run 'install' using --single-version-externally-managed to
  7. disable eggs in RPM distributions.
  8. 3. Replace dash with underscore in the version numbers for better RPM
  9. compatibility.
  10. """
  11. def run(self):
  12. # ensure distro name is up-to-date
  13. self.run_command('egg_info')
  14. orig.bdist_rpm.run(self)
  15. def _make_spec_file(self):
  16. version = self.distribution.get_version()
  17. rpmversion = version.replace('-', '_')
  18. spec = orig.bdist_rpm._make_spec_file(self)
  19. line23 = '%define version ' + version
  20. line24 = '%define version ' + rpmversion
  21. spec = [
  22. line.replace(
  23. "Source0: %{name}-%{version}.tar",
  24. "Source0: %{name}-%{unmangled_version}.tar"
  25. ).replace(
  26. "setup.py install ",
  27. "setup.py install --single-version-externally-managed "
  28. ).replace(
  29. "%setup",
  30. "%setup -n %{name}-%{unmangled_version}"
  31. ).replace(line23, line24)
  32. for line in spec
  33. ]
  34. insert_loc = spec.index(line24) + 1
  35. unmangled_version = "%define unmangled_version " + version
  36. spec.insert(insert_loc, unmangled_version)
  37. return spec