|
1 | 1 | {% block header %} |
| 2 | +# Template by setupmobans |
2 | 3 | {% endblock %} |
| 4 | +import os |
3 | 5 | import codecs |
| 6 | +from shutil import rmtree |
4 | 7 | {% if external_module_library %} |
5 | 8 | from distutils.core import setup, Extension |
6 | 9 | {% else %} |
7 | | -try: |
8 | | - from setuptools import setup, find_packages |
9 | | -except ImportError: |
10 | | - from ez_setup import use_setuptools |
11 | | - use_setuptools() |
12 | | - from setuptools import setup, find_packages |
| 10 | +from setuptools import setup, find_packages, Command |
13 | 11 | {%endif%} |
14 | 12 | {%block platform_block%} |
15 | 13 | from platform import python_implementation |
@@ -124,6 +122,42 @@ EXTRAS_REQUIRE = { |
124 | 122 | EXTRAS_REQUIRE = {} |
125 | 123 | {% endif %} |
126 | 124 | {% endif %} |
| 125 | +PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format( |
| 126 | + sys.executable) |
| 127 | +GS_COMMAND = ('gs {{name}} v{{release}} ' + |
| 128 | + "Find {{release}} in changelog for more details") |
| 129 | +here = os.path.abspath(os.path.dirname(__file__)) |
| 130 | + |
| 131 | + |
| 132 | +class PublishCommand(Command): |
| 133 | + """Support setup.py upload.""" |
| 134 | + |
| 135 | + description = 'Build and publish the package on github and pypi' |
| 136 | + user_options = [] |
| 137 | + |
| 138 | + @staticmethod |
| 139 | + def status(s): |
| 140 | + """Prints things in bold.""" |
| 141 | + print('\033[1m{0}\033[0m'.format(s)) |
| 142 | + |
| 143 | + def initialize_options(self): |
| 144 | + pass |
| 145 | + |
| 146 | + def finalize_options(self): |
| 147 | + pass |
| 148 | + |
| 149 | + def run(self): |
| 150 | + try: |
| 151 | + self.status('Removing previous builds…') |
| 152 | + rmtree(os.path.join(here, 'dist')) |
| 153 | + except OSError: |
| 154 | + pass |
| 155 | + |
| 156 | + self.status('Building Source and Wheel (universal) distribution…') |
| 157 | + if os.system(GS_COMMAND) == 0: |
| 158 | + os.system(PUBLISH_COMMAND) |
| 159 | + |
| 160 | + sys.exit() |
127 | 161 |
|
128 | 162 |
|
129 | 163 | def read_files(*files): |
@@ -196,5 +230,9 @@ if __name__ == '__main__': |
196 | 230 | entry_points=ENTRY_POINTS, |
197 | 231 | {% endif %} |
198 | 232 | {% endif%} |
199 | | - classifiers=CLASSIFIERS |
| 233 | + classifiers=CLASSIFIERS, |
| 234 | + setup_requires=['gease'], |
| 235 | + cmdclass={ |
| 236 | + 'publish': PublishCommand, |
| 237 | + } |
200 | 238 | ) |
0 commit comments