dist.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. import os
  4. from Naked.toolshed.system import file_exists, stderr, exit_success
  5. from Naked.toolshed.shell import run as shell_run
  6. class Dist:
  7. def __init__(self):
  8. self.register = "python setup.py register"
  9. self.sdist = "python setup.py sdist upload"
  10. self.wheel = "python setup.py bdist_wheel upload"
  11. self.swheel = "python setup.py sdist bdist_wheel upload"
  12. self.win = "python setup.py bdist_wininst upload"
  13. self.all = "python setup.py sdist bdist_wheel bdist_wininst upload"
  14. #------------------------------------------------------------------------------
  15. # [ run method ] - iterates through up to 6 directories above current working
  16. # directory and then runs command if setup.py found
  17. #------------------------------------------------------------------------------
  18. def run(self, command):
  19. setuppy_found = False
  20. for i in range(6): # navigate up at most 4 directory levels to search for the setup.py file
  21. if not self._is_setup_py_at_this_level():
  22. os.chdir(os.pardir)
  23. else:
  24. setuppy_found = True
  25. self._run_dist_command(command)
  26. break
  27. if not setuppy_found:
  28. stderr("Unable to locate the setup.py file for your project. Please confirm that you are in your project directory and try again.", 1)
  29. else:
  30. exit_success()
  31. # search for setup.py file
  32. def _is_setup_py_at_this_level(self):
  33. if file_exists('setup.py'):
  34. return True
  35. else:
  36. return False
  37. # run the user requested command
  38. def _run_dist_command(self, the_command):
  39. if the_command in "register":
  40. print('•naked• Running register...')
  41. shell_run(self.register)
  42. elif the_command in "sdist":
  43. print('•naked• Running sdist...')
  44. shell_run(self.sdist)
  45. elif the_command in "wheel":
  46. print('•naked• Running wheel...')
  47. shell_run(self.wheel)
  48. elif the_command in "swheel":
  49. print('•naked• Running swheel...')
  50. shell_run(self.swheel)
  51. elif the_command in "win":
  52. print('•naked• Running win...')
  53. shell_run(self.win)
  54. elif the_command in "all":
  55. print('•naked• Running all...')
  56. shell_run(self.all)
  57. else:
  58. stderr("Unrecognized command. Use 'naked dist help' to view the supported commands.", 1)
  59. def help():
  60. help_string = """
  61. Naked dist Command Help
  62. =======================
  63. The dist secondary commands run the standard distutils 'python setup.py <command>' source/binary distribution commands.
  64. USAGE
  65. naked dist <secondary_command>
  66. SECONDARY COMMANDS python setup.py <command(s)>
  67. all sdist bdist_wheel bdist_wininst upload
  68. register register
  69. sdist sdist upload
  70. swheel sdist bdist_wheel upload
  71. wheel bdist_wheel upload
  72. win bdist_wininst upload
  73. OPTIONS
  74. none
  75. EXAMPLES
  76. naked dist register
  77. naked dist sdist"""
  78. print(help_string)
  79. exit_success()
  80. if __name__ == '__main__':
  81. pass