setup.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import sys
  2. from distutils.cmd import Command
  3. from subprocess import check_call
  4. from typing import List
  5. from setuptools import setup, find_packages
  6. class CustomCommand(Command):
  7. user_options: List[str] = []
  8. description = 'Custom command'
  9. def initialize_options(self):
  10. pass
  11. def finalize_options(self):
  12. pass
  13. class DevelopCommand(CustomCommand):
  14. def run(self):
  15. print('Do not try to install telecaster. Run `pip install -r requirements.txt` instead.') # noqa
  16. sys.exit(1)
  17. class LocalCommand(CustomCommand):
  18. def run(self):
  19. print('Do not try to install telecaster. Run `pip install -r requirements-dev.txt` instead.') # noqa
  20. sys.exit(1)
  21. def create_command(text: str, commands: List[List[str]]):
  22. class GeneratedCommand(CustomCommand):
  23. description = text
  24. def run(self):
  25. for cmd in commands:
  26. check_call(cmd)
  27. return GeneratedCommand
  28. setup(
  29. name='telecaster',
  30. version='1.0',
  31. packages=find_packages(),
  32. scripts=['manage.py'],
  33. cmdclass=dict(
  34. develop=DevelopCommand,
  35. local=LocalCommand,
  36. fix=create_command(
  37. 'Auto-fixes and lints code',
  38. [
  39. ['python', 'setup.py', 'format'],
  40. ['python', 'setup.py', 'lint'],
  41. ['python', 'setup.py', 'lint_types'],
  42. ['python', 'setup.py', 'format_docstrings'],
  43. ],
  44. ),
  45. verify=create_command(
  46. 'Verifies that code is valid',
  47. [
  48. ['python', 'setup.py', 'verify_format'],
  49. ['python', 'setup.py', 'lint'],
  50. ['python', 'setup.py', 'lint_types'],
  51. ['python', 'setup.py', 'verify_format_docstrings'],
  52. ],
  53. ),
  54. format=create_command('Auto-formats code', [['black', '-S', '--config', './pyproject.toml', '.']]),
  55. verify_format=create_command(
  56. 'Verifies that code is properly formatted',
  57. [['black', '-S', '--check', '--config', './pyproject.toml', '.']],
  58. ),
  59. format_docstrings=create_command(
  60. 'Auto-formats doc strings', [['docformatter', '-r', '-e', 'env', 'venv', '-i', '.']]
  61. ),
  62. verify_format_docstrings=create_command(
  63. 'Verifies that doc strings are properly formatted',
  64. [['docformatter', '-r', '-e', 'env', 'venv', 'node_modules', '-c', '.']],
  65. ),
  66. lint=create_command('Lints the code', [['flake8', '.']]),
  67. lint_types=create_command(
  68. 'Type checks the code',
  69. [
  70. ['mypy', 'telecaster', '--strict', '--config-file', './setup.cfg'],
  71. ],
  72. ),
  73. ),
  74. )