|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +import os |
| 5 | +import re |
| 6 | +import shutil |
| 7 | +import sys |
| 8 | + |
1 | 9 | from distutils.core import setup
|
2 | 10 |
|
| 11 | + |
| 12 | +def get_version(package): |
| 13 | + """ |
| 14 | + Return package version as listed in `__version__` in `init.py`. |
| 15 | + """ |
| 16 | + with open(os.path.join(package, '__init__.py'), 'rb') as init_py: |
| 17 | + src = init_py.read().decode('utf-8') |
| 18 | + return re.search("__version__ = ['\"]([^'\"]+)['\"]", src).group(1) |
| 19 | + |
| 20 | + |
| 21 | +name = 'drfpasswordless' |
| 22 | +version = get_version('drfpasswordless') |
| 23 | +package = 'drfpasswordless' |
| 24 | +description = 'Passwordless auth for Django Rest Framework Token Authentication.' |
| 25 | +url = 'https://github.com/aaronn/django-rest-framework-passwordless' |
| 26 | +author = 'Aaron Ng' |
| 27 | +author_email = 'hi@aaron.ng' |
| 28 | +license = 'MIT' |
| 29 | +install_requires = [] |
| 30 | + |
| 31 | + |
| 32 | +def read(*paths): |
| 33 | + """ |
| 34 | + Build a file path from paths and return the contents. |
| 35 | + """ |
| 36 | + with open(os.path.join(*paths), 'r') as f: |
| 37 | + return f.read() |
| 38 | + |
| 39 | + |
| 40 | +def get_packages(package): |
| 41 | + """ |
| 42 | + Return root package and all sub-packages. |
| 43 | + """ |
| 44 | + return [dirpath |
| 45 | + for dirpath, dirnames, filenames in os.walk(package) |
| 46 | + if os.path.exists(os.path.join(dirpath, '__init__.py'))] |
| 47 | + |
| 48 | + |
| 49 | +def get_package_data(package): |
| 50 | + """ |
| 51 | + Return all files under the root package, that are not in a |
| 52 | + package themselves. |
| 53 | + """ |
| 54 | + walk = [(dirpath.replace(package + os.sep, '', 1), filenames) |
| 55 | + for dirpath, dirnames, filenames in os.walk(package) |
| 56 | + if not os.path.exists(os.path.join(dirpath, '__init__.py'))] |
| 57 | + |
| 58 | + filepaths = [] |
| 59 | + for base, filenames in walk: |
| 60 | + filepaths.extend([os.path.join(base, filename) |
| 61 | + for filename in filenames]) |
| 62 | + return {package: filepaths} |
| 63 | + |
| 64 | + |
| 65 | +if sys.argv[-1] == 'publish': |
| 66 | + if os.system('pip freeze | grep wheel'): |
| 67 | + print('wheel not installed.\nUse `pip install wheel`.\nExiting.') |
| 68 | + sys.exit() |
| 69 | + if os.system('pip freeze | grep twine'): |
| 70 | + print('twine not installed.\nUse `pip install twine`.\nExiting.') |
| 71 | + sys.exit() |
| 72 | + os.system('python setup.py sdist bdist_wheel') |
| 73 | + os.system('twine upload dist/*') |
| 74 | + shutil.rmtree('dist') |
| 75 | + shutil.rmtree('build') |
| 76 | + shutil.rmtree('drfpasswordless.egg-info') |
| 77 | + print('You probably want to also tag the version now:') |
| 78 | + print(" git tag -a {0} -m 'version {0}'".format(version)) |
| 79 | + print(' git push --tags') |
| 80 | + sys.exit() |
| 81 | + |
| 82 | + |
3 | 83 | setup(
|
4 |
| - name='drfpasswordless', |
5 |
| - version='0.1.0', |
6 |
| - packages=['tests', 'drfpasswordless', 'drfpasswordless.templates'], |
7 |
| - url='https://github.com/aaronn/django-rest-framework-passwordless', |
8 |
| - license='MIT', |
9 |
| - author='Aaron Ng', |
10 |
| - author_email='hi@aaron.ng', |
11 |
| - description='Passwordless auth for Django Rest Framework Token Authentication.' |
| 84 | + name=name, |
| 85 | + version=version, |
| 86 | + url=url, |
| 87 | + license=license, |
| 88 | + description=description, |
| 89 | + long_description=read('README'), |
| 90 | + author=author, |
| 91 | + author_email=author_email, |
| 92 | + packages=get_packages(package), |
| 93 | + package_data=get_package_data(package), |
| 94 | + install_requires=install_requires, |
| 95 | + classifiers=[ |
| 96 | + 'Development Status :: 5 - Production/Stable', |
| 97 | + 'Environment :: Web Environment', |
| 98 | + 'Framework :: Django', |
| 99 | + 'Intended Audience :: Developers', |
| 100 | + 'License :: OSI Approved :: MIT License', |
| 101 | + 'Operating System :: OS Independent', |
| 102 | + 'Programming Language :: Python', |
| 103 | + 'Programming Language :: Python :: 3', |
| 104 | + 'Programming Language :: Python :: 3.3', |
| 105 | + 'Programming Language :: Python :: 3.4', |
| 106 | + 'Programming Language :: Python :: 3.5', |
| 107 | + 'Topic :: Internet :: WWW/HTTP', |
| 108 | + ] |
12 | 109 | )
|
13 |
| - |
|
0 commit comments