setup.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
  5. #
  6. # This setup script is part of python-sqlparse and is released under
  7. # the BSD License: http://www.opensource.org/licenses/bsd-license.php
  8. import re
  9. from setuptools import setup, find_packages
  10. def get_version():
  11. """Parse __init__.py for version number instead of importing the file."""
  12. VERSIONFILE = 'sqlparse/__init__.py'
  13. VSRE = r'^__version__ = [\'"]([^\'"]*)[\'"]'
  14. with open(VERSIONFILE) as f:
  15. verstrline = f.read()
  16. mo = re.search(VSRE, verstrline, re.M)
  17. if mo:
  18. return mo.group(1)
  19. raise RuntimeError('Unable to find version in {fn}'.format(fn=VERSIONFILE))
  20. LONG_DESCRIPTION = """
  21. ``sqlparse`` is a non-validating SQL parser module.
  22. It provides support for parsing, splitting and formatting SQL statements.
  23. Visit the `project page <https://github.com/andialbrecht/sqlparse>`_ for
  24. additional information and documentation.
  25. **Example Usage**
  26. Splitting SQL statements::
  27. >>> import sqlparse
  28. >>> sqlparse.split('select * from foo; select * from bar;')
  29. [u'select * from foo; ', u'select * from bar;']
  30. Formatting statemtents::
  31. >>> sql = 'select * from foo where id in (select id from bar);'
  32. >>> print sqlparse.format(sql, reindent=True, keyword_case='upper')
  33. SELECT *
  34. FROM foo
  35. WHERE id IN
  36. (SELECT id
  37. FROM bar);
  38. Parsing::
  39. >>> sql = 'select * from someschema.mytable where id = 1'
  40. >>> res = sqlparse.parse(sql)
  41. >>> res
  42. (<Statement 'select...' at 0x9ad08ec>,)
  43. >>> stmt = res[0]
  44. >>> str(stmt) # converting it back to unicode
  45. 'select * from someschema.mytable where id = 1'
  46. >>> # This is how the internal representation looks like:
  47. >>> stmt.tokens
  48. (<DML 'select' at 0x9b63c34>,
  49. <Whitespace ' ' at 0x9b63e8c>,
  50. <Operator '*' at 0x9b63e64>,
  51. <Whitespace ' ' at 0x9b63c5c>,
  52. <Keyword 'from' at 0x9b63c84>,
  53. <Whitespace ' ' at 0x9b63cd4>,
  54. <Identifier 'somes...' at 0x9b5c62c>,
  55. <Whitespace ' ' at 0x9b63f04>,
  56. <Where 'where ...' at 0x9b5caac>)
  57. """
  58. setup(
  59. name='sqlparse',
  60. version=get_version(),
  61. author='Andi Albrecht',
  62. author_email='albrecht.andi@gmail.com',
  63. url='https://github.com/andialbrecht/sqlparse',
  64. description='Non-validating SQL parser',
  65. long_description=LONG_DESCRIPTION,
  66. license='BSD',
  67. classifiers=[
  68. 'Development Status :: 4 - Beta',
  69. 'Intended Audience :: Developers',
  70. 'License :: OSI Approved :: BSD License',
  71. 'Operating System :: OS Independent',
  72. 'Programming Language :: Python',
  73. 'Programming Language :: Python :: 2',
  74. 'Programming Language :: Python :: 2.7',
  75. 'Programming Language :: Python :: 3',
  76. 'Programming Language :: Python :: 3.3',
  77. 'Programming Language :: Python :: 3.4',
  78. 'Programming Language :: Python :: 3.5',
  79. 'Topic :: Database',
  80. 'Topic :: Software Development',
  81. ],
  82. packages=find_packages(exclude=('tests',)),
  83. entry_points={
  84. 'console_scripts': [
  85. 'sqlformat = sqlparse.__main__:main',
  86. ]
  87. },
  88. )