setup.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import logging
  2. import os
  3. import sys
  4. try:
  5. from setuptools import setup
  6. except ImportError:
  7. print("WARNING: setuptools not installed. Will try using distutils instead..")
  8. from distutils.core import setup
  9. def launch_http_server(directory):
  10. assert os.path.isdir(directory)
  11. try:
  12. try:
  13. from SimpleHTTPServer import SimpleHTTPRequestHandler
  14. except ImportError:
  15. from http.server import SimpleHTTPRequestHandler
  16. try:
  17. import SocketServer
  18. except ImportError:
  19. import socketserver as SocketServer
  20. import socket
  21. for port in [80] + list(range(8000, 8100)):
  22. try:
  23. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  24. s.bind(('localhost', port))
  25. s.close()
  26. except socket.error as e:
  27. logging.debug("Can't use port %d: %s" % (port, e.strerror))
  28. continue
  29. print("HTML coverage report now available at http://%s%s" % (
  30. socket.gethostname(), (":%s" % port) if port != 80 else ""))
  31. os.chdir(directory)
  32. SocketServer.TCPServer(("", port),
  33. SimpleHTTPRequestHandler).serve_forever()
  34. else:
  35. logging.debug("All network port. ")
  36. except Exception as e:
  37. logging.error("ERROR: while starting an HTTP server to serve "
  38. "the coverage report: %s" % e)
  39. command = sys.argv[-1]
  40. if command == 'publish':
  41. os.system('python setup.py sdist upload')
  42. sys.exit()
  43. elif command == "coverage":
  44. try:
  45. import coverage
  46. except:
  47. sys.exit("coverage.py not installed (pip install --user coverage)")
  48. setup_py_path = os.path.abspath(__file__)
  49. os.system('coverage run --source=configargparse ' + setup_py_path +' test')
  50. os.system('coverage report')
  51. os.system('coverage html')
  52. print("Done computing coverage")
  53. launch_http_server(directory="htmlcov")
  54. sys.exit()
  55. long_description = ''
  56. if command not in ['test', 'coverage']:
  57. long_description = open('README.rst').read()
  58. install_requires = []
  59. if sys.version_info < (2, 7):
  60. install_requires.extend([
  61. 'argparse',
  62. 'ordereddict',
  63. 'unittest2',
  64. ])
  65. setup(
  66. name='ConfigArgParse',
  67. version="0.11.0",
  68. description='A drop-in replacement for argparse that allows options to '
  69. 'also be set via config files and/or environment variables.',
  70. long_description=long_description,
  71. author='Zorro',
  72. author_email='zorro3.github@gmail.com',
  73. url='https://github.com/bw2/ConfigArgParse',
  74. py_modules=['configargparse'],
  75. include_package_data=True,
  76. license="MIT",
  77. keywords='options, argparse, ConfigArgParse, config, environment variables, '
  78. 'envvars, ENV, environment, optparse, YAML, INI',
  79. classifiers=[
  80. 'Development Status :: 4 - Beta',
  81. 'Intended Audience :: Developers',
  82. 'License :: OSI Approved :: MIT License',
  83. 'Natural Language :: English',
  84. "Programming Language :: Python :: 2",
  85. 'Programming Language :: Python :: 2.6',
  86. 'Programming Language :: Python :: 2.7',
  87. 'Programming Language :: Python :: 3',
  88. 'Programming Language :: Python :: 3.2',
  89. 'Programming Language :: Python :: 3.3',
  90. 'Programming Language :: Python :: 3.4',
  91. 'Programming Language :: Python :: 3.5',
  92. 'Programming Language :: Python :: Implementation :: CPython',
  93. 'Programming Language :: Python :: Implementation :: PyPy',
  94. ],
  95. test_suite='tests',
  96. install_requires=install_requires,
  97. extras_require = {
  98. 'yaml': ["PyYAML"],
  99. }
  100. )