setup.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import os
  2. import sys
  3. from fnmatch import fnmatchcase
  4. from distutils.util import convert_path
  5. from setuptools import setup, find_packages
  6. version = __import__('s3sync').get_version()
  7. # Provided as an attribute, so you can append to these instead
  8. # of replicating them:
  9. standard_exclude = ["*.py", "*.pyc", "*~", ".*", "*.bak"]
  10. standard_exclude_directories = [
  11. ".*", "CVS", "_darcs", "./build",
  12. "./dist", "EGG-INFO", "*.egg-info"
  13. ]
  14. # Copied from paste/util/finddata.py
  15. def find_package_data(where=".", package="", exclude=standard_exclude,
  16. exclude_directories=standard_exclude_directories,
  17. only_in_packages=True, show_ignored=False):
  18. """
  19. Return a dictionary suitable for use in ``package_data``
  20. in a distutils ``setup.py`` file.
  21. The dictionary looks like::
  22. {"package": [files]}
  23. Where ``files`` is a list of all the files in that package that
  24. don't match anything in ``exclude``.
  25. If ``only_in_packages`` is true, then top-level directories that
  26. are not packages won't be included (but directories under packages
  27. will).
  28. Directories matching any pattern in ``exclude_directories`` will
  29. be ignored; by default directories with leading ``.``, ``CVS``,
  30. and ``_darcs`` will be ignored.
  31. If ``show_ignored`` is true, then all the files that aren't
  32. included in package data are shown on stderr (for debugging
  33. purposes).
  34. Note patterns use wildcards, or can be exact paths (including
  35. leading ``./``), and all searching is case-insensitive.
  36. """
  37. out = {}
  38. stack = [(convert_path(where), "", package, only_in_packages)]
  39. while stack:
  40. where, prefix, package, only_in_packages = stack.pop(0)
  41. for name in os.listdir(where):
  42. fn = os.path.join(where, name)
  43. if os.path.isdir(fn):
  44. bad_name = False
  45. for pattern in exclude_directories:
  46. if (fnmatchcase(name, pattern)
  47. or fn.lower() == pattern.lower()):
  48. bad_name = True
  49. if show_ignored:
  50. print >> sys.stderr, (
  51. "Directory %s ignored by pattern %s"
  52. % (fn, pattern))
  53. break
  54. if bad_name:
  55. continue
  56. if (os.path.isfile(os.path.join(fn, "__init__.py"))
  57. and not prefix):
  58. if not package:
  59. new_package = name
  60. else:
  61. new_package = package + "." + name
  62. stack.append((fn, "", new_package, False))
  63. else:
  64. stack.append((fn, prefix + name + "/", package,
  65. only_in_packages))
  66. elif package or not only_in_packages:
  67. # is a file
  68. bad_name = False
  69. for pattern in exclude:
  70. if (fnmatchcase(name, pattern)
  71. or fn.lower() == pattern.lower()):
  72. bad_name = True
  73. if show_ignored:
  74. print >> sys.stderr, (
  75. "File %s ignored by pattern %s"
  76. % (fn, pattern))
  77. break
  78. if bad_name:
  79. continue
  80. out.setdefault(package, []).append(prefix + name)
  81. return out
  82. excluded_directories = standard_exclude_directories + ['tests']
  83. package_data = find_package_data(exclude_directories=excluded_directories)
  84. setup(
  85. name='Django S3 Sync',
  86. version=version.replace(' ', '-'),
  87. url='http://github.com/pcraciunoiu/django-s3sync',
  88. author='Paul Craciunoiu',
  89. author_email='paul@craciunoiu.net',
  90. description='Django utils to sync S3 bucket with your media folder with '
  91. 'flexible configuration.',
  92. long_description=open('README.rst', 'r').read() + \
  93. open('AUTHORS.rst', 'r').read() + open('CHANGELOG.rst', 'r').read(),
  94. license='MIT',
  95. packages=find_packages(),
  96. package_data=package_data,
  97. include_package_data=True,
  98. install_requires=['django>=1.3'],
  99. classifiers=[
  100. 'Programming Language :: Python',
  101. 'License :: OSI Approved :: MIT License',
  102. 'Development Status :: 5 - Production/Stable',
  103. 'Operating System :: OS Independent',
  104. 'Framework :: Django',
  105. 'Intended Audience :: Developers',
  106. 'Topic :: Internet :: WWW/HTTP',
  107. 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
  108. ],
  109. )