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.
 
 
 
 

61 lines
2.2 KiB

  1. from distutils import log
  2. import distutils.command.install_scripts as orig
  3. import os
  4. from pkg_resources import Distribution, PathMetadata, ensure_directory
  5. class install_scripts(orig.install_scripts):
  6. """Do normal script install, plus any egg_info wrapper scripts"""
  7. def initialize_options(self):
  8. orig.install_scripts.initialize_options(self)
  9. self.no_ep = False
  10. def run(self):
  11. import setuptools.command.easy_install as ei
  12. self.run_command("egg_info")
  13. if self.distribution.scripts:
  14. orig.install_scripts.run(self) # run first to set up self.outfiles
  15. else:
  16. self.outfiles = []
  17. if self.no_ep:
  18. # don't install entry point scripts into .egg file!
  19. return
  20. ei_cmd = self.get_finalized_command("egg_info")
  21. dist = Distribution(
  22. ei_cmd.egg_base, PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),
  23. ei_cmd.egg_name, ei_cmd.egg_version,
  24. )
  25. bs_cmd = self.get_finalized_command('build_scripts')
  26. exec_param = getattr(bs_cmd, 'executable', None)
  27. bw_cmd = self.get_finalized_command("bdist_wininst")
  28. is_wininst = getattr(bw_cmd, '_is_running', False)
  29. writer = ei.ScriptWriter
  30. if is_wininst:
  31. exec_param = "python.exe"
  32. writer = ei.WindowsScriptWriter
  33. # resolve the writer to the environment
  34. writer = writer.best()
  35. cmd = writer.command_spec_class.best().from_param(exec_param)
  36. for args in writer.get_args(dist, cmd.as_header()):
  37. self.write_script(*args)
  38. def write_script(self, script_name, contents, mode="t", *ignored):
  39. """Write an executable file to the scripts directory"""
  40. from setuptools.command.easy_install import chmod, current_umask
  41. log.info("Installing %s script to %s", script_name, self.install_dir)
  42. target = os.path.join(self.install_dir, script_name)
  43. self.outfiles.append(target)
  44. mask = current_umask()
  45. if not self.dry_run:
  46. ensure_directory(target)
  47. f = open(target, "w" + mode)
  48. f.write(contents)
  49. f.close()
  50. chmod(target, 0o777 - mask)