|
5 | 5 |
|
6 | 6 | import io
|
7 | 7 | import os
|
| 8 | +import sys |
| 9 | +from shutil import rmtree |
8 | 10 |
|
| 11 | +from setuptools import Command |
9 | 12 | from setuptools import find_packages
|
10 | 13 | from setuptools import setup
|
11 | 14 |
|
|
72 | 75 | about['__version__'] = VERSION
|
73 | 76 |
|
74 | 77 |
|
| 78 | +class UploadCommand(Command): |
| 79 | + """Support setup.py upload.""" |
| 80 | + |
| 81 | + description = 'Build and publish the package.' |
| 82 | + user_options = [] |
| 83 | + |
| 84 | + @staticmethod |
| 85 | + def status(s): |
| 86 | + """Prints things in bold.""" |
| 87 | + print('\033[1m{0}\033[0m'.format(s)) |
| 88 | + |
| 89 | + def initialize_options(self): |
| 90 | + pass |
| 91 | + |
| 92 | + def finalize_options(self): |
| 93 | + pass |
| 94 | + |
| 95 | + def run(self): |
| 96 | + try: |
| 97 | + self.status('Removing previous builds…') |
| 98 | + rmtree(os.path.join(here, 'dist')) |
| 99 | + except OSError: |
| 100 | + pass |
| 101 | + |
| 102 | + self.status('Building Source and Wheel (universal) distribution…') |
| 103 | + os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) |
| 104 | + |
| 105 | + self.status('Uploading the package to PyPI via Twine…') |
| 106 | + os.system('twine upload dist/*') |
| 107 | + |
| 108 | + self.status('Pushing git tags…') |
| 109 | + os.system('git tag v{0}'.format(about['__version__'])) |
| 110 | + os.system('git push --tags') |
| 111 | + |
| 112 | + sys.exit() |
| 113 | + |
| 114 | + |
75 | 115 | setup(
|
76 | 116 | name=NAME,
|
77 | 117 | version=about['__version__'],
|
|
104 | 144 | install_requires=REQUIRED,
|
105 | 145 | tests_require=TESTS,
|
106 | 146 | extras_require=EXTRAS,
|
| 147 | + # $ setup.py upload support. |
| 148 | + cmdclass={ |
| 149 | + 'upload': UploadCommand, |
| 150 | + }, |
107 | 151 | )
|
0 commit comments