tako is a command language and shell based on Python. https://takoshell.org
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.

setup.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/usr/bin/env python
  2. # This file is part of tako
  3. # Copyright (c) 2015-2017 Adam Hartz <hartz@mit.edu> and contributors
  4. #
  5. # This program is free software: you can redistribute it and/or modify it under
  6. # the terms of the GNU General Public License as published by the Free Software
  7. # Foundation, either version 3 of the License, or (at your option) any later
  8. # version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but WITHOUT
  11. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13. # details.
  14. #
  15. # You should have received a copy of the GNU General Public License along with
  16. # this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. #
  19. # tako is a fork of xonsh (http://xon.sh)
  20. # xonsh is Copyright (c) 2015-2016 the xonsh developers and is licensed under
  21. # the 2-Clause BSD license.
  22. # -*- coding: ascii -*-
  23. """The tako installer."""
  24. from __future__ import print_function, unicode_literals
  25. import os
  26. import sys
  27. import json
  28. try:
  29. from tempfile import TemporaryDirectory
  30. except ImportError:
  31. pass
  32. try:
  33. from setuptools import setup
  34. from setuptools.command.sdist import sdist
  35. from setuptools.command.install import install
  36. from setuptools.command.develop import develop
  37. from setuptools.command.install_scripts import install_scripts
  38. HAVE_SETUPTOOLS = True
  39. except ImportError:
  40. from distutils.core import setup
  41. from distutils.command.sdist import sdist as sdist
  42. from distutils.command.install import install as install
  43. from distutils.command.install_scripts import install_scripts
  44. HAVE_SETUPTOOLS = False
  45. from takoshell import __version__ as TAKO_VERSION
  46. TABLES = ['takoshell/lexer_table.py', 'takoshell/parser_table.py']
  47. def clean_tables():
  48. """Remove the lexer/parser modules that are dynamically created."""
  49. for f in TABLES:
  50. if os.path.isfile(f):
  51. os.remove(f)
  52. print('Remove ' + f)
  53. def build_tables():
  54. """Build the lexer/parser modules."""
  55. print('Building lexer and parser tables.')
  56. sys.path.insert(0, os.path.dirname(__file__))
  57. from takoshell.parser import Parser
  58. Parser(lexer_table='lexer_table', yacc_table='parser_table',
  59. outputdir='takoshell')
  60. sys.path.pop(0)
  61. class xinstall(install):
  62. """Xonsh specialization of setuptools install class."""
  63. def run(self):
  64. clean_tables()
  65. build_tables()
  66. install.run(self)
  67. class xsdist(sdist):
  68. """Xonsh specialization of setuptools sdist class."""
  69. def make_release_tree(self, basedir, files):
  70. clean_tables()
  71. build_tables()
  72. sdist.make_release_tree(self, basedir, files)
  73. #-----------------------------------------------------------------------------
  74. # Hack to overcome pip/setuptools problem on Win 10. See:
  75. # https://github.com/tomduck/pandoc-eqnos/issues/6
  76. # https://github.com/pypa/pip/issues/2783
  77. # Custom install_scripts command class for setup()
  78. class install_scripts_quoted_shebang(install_scripts):
  79. """Ensure there are quotes around shebang paths with spaces."""
  80. def write_script(self, script_name, contents, mode="t", *ignored):
  81. shebang = str(contents.splitlines()[0])
  82. if shebang.startswith('#!') and ' ' in shebang[2:].strip() \
  83. and '"' not in shebang:
  84. quoted_shebang = '#!"%s"' % shebang[2:].strip()
  85. contents = contents.replace(shebang, quoted_shebang)
  86. super().write_script(script_name, contents, mode, *ignored)
  87. # The custom install needs to be used on Windows machines
  88. if os.name == 'nt':
  89. cmdclass = {'install': xinstall, 'sdist': xsdist, 'install_scripts': install_scripts_quoted_shebang}
  90. else:
  91. cmdclass = {'install': xinstall, 'sdist': xsdist}
  92. if HAVE_SETUPTOOLS:
  93. class xdevelop(develop):
  94. """Xonsh specialization of setuptools develop class."""
  95. def run(self):
  96. clean_tables()
  97. build_tables()
  98. develop.run(self)
  99. def main():
  100. """The main entry point."""
  101. if sys.version_info[:2] < (3, 4):
  102. sys.exit('tako currently requires Python 3.4+')
  103. if '--name' not in sys.argv:
  104. print(' ____ \n( oo )\n_||||_\n \n TAKO \n')
  105. skw = dict(
  106. name='takoshell',
  107. description='Pythonic shell language and command prompt',
  108. long_description='tako is a Pythonic shell language and command prompt. https://takoshell.org',
  109. license='GPLv3+',
  110. version=TAKO_VERSION,
  111. author='Adam Hartz',
  112. maintainer='Adam Hartz',
  113. author_email='hartz@mit.edu',
  114. url='https://takoshell.org',
  115. platforms='Cross Platform',
  116. classifiers=['Development Status :: 4 - Beta',
  117. 'Environment :: Console',
  118. 'Intended Audience :: Developers',
  119. 'Intended Audience :: End Users/Desktop',
  120. 'Natural Language :: English',
  121. 'Operating System :: POSIX',
  122. 'Programming Language :: Python :: 3 :: Only',
  123. 'Topic :: System :: Shells',
  124. 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)'],
  125. packages=['takoshell', 'takoshell.ply', 'takoshell.parsers',
  126. 'takoshell.coreutils', 'takoshell.completers'],
  127. package_dir={'takoshell': 'takoshell'},
  128. package_data={'takoshell': ['*.json', 'LICENSE']},
  129. cmdclass=cmdclass
  130. )
  131. if HAVE_SETUPTOOLS:
  132. skw['entry_points'] = {
  133. 'console_scripts': ['tako = takoshell.main:main'],
  134. }
  135. skw['cmdclass']['develop'] = xdevelop
  136. skw['install_requires'] = []
  137. else:
  138. skw['scripts'] = ['scripts/tako']
  139. setup(**skw)
  140. if __name__ == '__main__':
  141. main()