Skip to content

Commit b58e962

Browse files
committed
✨ do build, pypi publish and github release in one command
1 parent e49376a commit b58e962

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

README.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,21 @@ You can get it:
1515
1616
$ git clone http://github.com/moremoban/setupmobans.git
1717
18+
19+
Notes
20+
================================================================================
21+
22+
23+
In order to run, `python setup.py publish`, you will have setup `.pypirc` in
24+
your home folder as::
25+
26+
[distutils]
27+
index-servers =
28+
pypi
29+
30+
[pypi]
31+
username=your_name
32+
password=your_password
33+
34+
35+
And you need `gease` installed too.

templates/setup.py.jj2

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{% block header %}
2+
# Template by setupmobans
23
{% endblock %}
4+
import os
35
import codecs
6+
from shutil import rmtree
47
{% if external_module_library %}
58
from distutils.core import setup, Extension
69
{% 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
1311
{%endif%}
1412
{%block platform_block%}
1513
from platform import python_implementation
@@ -124,6 +122,42 @@ EXTRAS_REQUIRE = {
124122
EXTRAS_REQUIRE = {}
125123
{% endif %}
126124
{% 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 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+
os.system(__GS_COMMAND)
158+
os.system(__PUBLISH_COMMAND)
159+
160+
sys.exit()
127161

128162

129163
def read_files(*files):
@@ -196,5 +230,9 @@ if __name__ == '__main__':
196230
entry_points=ENTRY_POINTS,
197231
{% endif %}
198232
{% endif%}
199-
classifiers=CLASSIFIERS
233+
classifiers=CLASSIFIERS,
234+
setup_requires=['gease'],
235+
cmdclass={
236+
'publish': PublishCommand,
237+
}
200238
)

0 commit comments

Comments
 (0)