code: def run(self):  # noqa: C901
      if DEBUG:
          print("before _get_package_data():")
          print("vendor =", self.vendor)
          print("packager =", self.packager)
          print("doc_files =", self.doc_files)
          print("changelog =", self.changelog)
  
      # make directories
      if self.spec_only:
          spec_dir = self.dist_dir
          self.mkpath(spec_dir)
      else:
          rpm_dir = {}
          for d in ("SOURCES", "SPECS", "BUILD", "RPMS", "SRPMS"):
              rpm_dir[d] = os.path.join(self.rpm_base, d)
              self.mkpath(rpm_dir[d])
          spec_dir = rpm_dir["SPECS"]
  
      # Spec file goes into 'dist_dir' if '--spec-only specified',
      # build/rpm.<plat> otherwise.
      spec_path = os.path.join(
          spec_dir, "%s.spec" % self.distribution.get_name()
      )
      self.execute(
          write_file,
          (spec_path, self._make_spec_file()),
          "writing '%s'" % spec_path,
      )
  
      if self.spec_only:  # stop if requested
          return
  
      # Make a source distribution and copy to SOURCES directory with
      # optional icon.
      saved_dist_files = self.distribution.dist_files[:]
      sdist = self.reinitialize_command("sdist")
      if self.use_bzip2:
          sdist.formats = ["bztar"]
      else:
          sdist.formats = ["gztar"]
      self.run_command("sdist")
      self.distribution.dist_files = saved_dist_files
  
      source = sdist.get_archive_files()[0]
      source_dir = rpm_dir["SOURCES"]
      self.copy_file(source, source_dir)
  
      if self.icon:
          if os.path.exists(self.icon):
              self.copy_file(self.icon, source_dir)
          else:
              raise DistutilsFileError(
                  "icon file '%s' does not exist" % self.icon
              )
  
      # build package
      log.info("building RPMs")
      rpm_cmd = ["rpmbuild"]
  
      if self.source_only:  # what kind of RPMs?
          rpm_cmd.append("-bs")
      elif self.binary_only:
          rpm_cmd.append("-bb")
      else:
          rpm_cmd.append("-ba")
      rpm_cmd.extend(["--define", "__python %s" % self.python])
      if self.rpm3_mode:
          rpm_cmd.extend(
              [
                  "--define",
                  "_topdir %s" % os.path.abspath(self.rpm_base),
              ]
          )
      if not self.keep_temp:
          rpm_cmd.append("--clean")
  
      if self.quiet:
          rpm_cmd.append("--quiet")
  
      rpm_cmd.append(spec_path)
      # Determine the binary rpm names that should be built out of this spec
      # file
      # Note that some of these may not be really built (if the file
      # list is empty)
      nvr_string = "%{name}-%{version}-%{release}"
      src_rpm = nvr_string + ".src.rpm"
      non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
      q_cmd = r"rpm -q --qf '{} {}\n' --specfile '{}'".format(
          src_rpm,
          non_src_rpm,
          spec_path,
      )
  
      out = os.popen(q_cmd)
      try:
          binary_rpms = []
          source_rpm = None
          while True:
              line = out.readline()
              if not line:
                  break
              ell = line.strip().split()
              assert len(ell) == 2
              binary_rpms.append(ell[1])
              # The source rpm is named after the first entry in the spec file
              if source_rpm is None:
                  source_rpm = ell[0]
  
          status = out.close()
          if status:
              raise DistutilsExecError(
                  "Failed to execute: %s" % repr(q_cmd)
              )
  
      finally:
          out.close()
  
      self.spawn(rpm_cmd)
  
      if not self.dry_run:
          if self.distribution.has_ext_modules():
              pyversion = get_python_version()
          else:
              pyversion = "any"
  
          if not self.binary_only:
              srpm = os.path.join(rpm_dir["SRPMS"], source_rpm)
              assert os.path.exists(srpm)
              self.move_file(srpm, self.dist_dir)
              filename = os.path.join(self.dist_dir, source_rpm)
              self.distribution.dist_files.append(
                  ("bdist_rpm", pyversion, filename)
              )
  
          if not self.source_only:
              for rpm in binary_rpms:
                  rpm = os.path.join(rpm_dir["RPMS"], rpm)
                  if os.path.exists(rpm):
                      self.move_file(rpm, self.dist_dir)
                      filename = os.path.join(
                          self.dist_dir, os.path.basename(rpm)
                      )
                      self.distribution.dist_files.append(
                          ("bdist_rpm", pyversion, filename)
                      )
  
file_path: catboost/contrib/python/setuptools/py3/setuptools/_distutils/command/bdist_rpm.py
imports: import subprocess
  import sys
  import os
  from ..core import Command
  from ..debug import DEBUG
  from ..file_util import write_file
  from ..errors import DistutilsOptionError, DistutilsPlatformError, DistutilsFileError, DistutilsExecError
  from ..sysconfig import get_python_version
  from distutils._log import log
label_desc: Use image node_id 4 for calling the bdist_rpm obj's underlying member method code with example usage: obj.run() without return types