setup.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from setuptools import setup
  4. import re
  5. import os
  6. import sys
  7. name = 'django-ipware'
  8. package = 'ipware'
  9. description = "A Django utility application that returns client's real IP address"
  10. url = 'https://github.com/un33k/django-ipware'
  11. author = 'Val Neekman'
  12. author_email = 'info@neekware.com'
  13. license = 'MIT'
  14. install_requires = ['']
  15. classifiers = [
  16. 'Development Status :: 5 - Production/Stable',
  17. 'Environment :: Web Environment',
  18. 'Intended Audience :: Developers',
  19. 'License :: OSI Approved :: MIT License',
  20. 'Operating System :: OS Independent',
  21. 'Programming Language :: Python',
  22. 'Programming Language :: Python :: 2.7',
  23. 'Programming Language :: Python :: 3.4',
  24. 'Programming Language :: Python :: 3.5',
  25. 'Programming Language :: Python :: 3.6',
  26. 'Topic :: Utilities'
  27. ]
  28. def get_version(package):
  29. """
  30. Return package version as listed in `__version__` in `init.py`.
  31. """
  32. init_py = open(os.path.join(package, '__init__.py')).read()
  33. return re.search("^__version__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1)
  34. def get_packages(package):
  35. """
  36. Return root package and all sub-packages.
  37. """
  38. return [dirpath
  39. for dirpath, dirnames, filenames in os.walk(package)
  40. if os.path.exists(os.path.join(dirpath, '__init__.py'))]
  41. def get_package_data(package):
  42. """
  43. Return all files under the root package, that are not in a
  44. package themselves.
  45. """
  46. walk = [(dirpath.replace(package + os.sep, '', 1), filenames)
  47. for dirpath, dirnames, filenames in os.walk(package)
  48. if not os.path.exists(os.path.join(dirpath, '__init__.py'))]
  49. filepaths = []
  50. for base, filenames in walk:
  51. filepaths.extend([os.path.join(base, filename)
  52. for filename in filenames])
  53. return {package: filepaths}
  54. if sys.argv[-1] == 'publish':
  55. os.system("python setup.py sdist upload")
  56. args = {'version': get_version(package)}
  57. print("You probably want to also tag the version now:")
  58. print(" git tag -a %(version)s -m 'version %(version)s' && git push --tags" % args)
  59. sys.exit()
  60. setup(
  61. name=name,
  62. version=get_version(package),
  63. url=url,
  64. license=license,
  65. description=description,
  66. author=author,
  67. author_email=author_email,
  68. packages=get_packages(package),
  69. package_data=get_package_data(package),
  70. install_requires=install_requires,
  71. classifiers=classifiers
  72. )