Skip to content
This repository was archived by the owner on Dec 7, 2023. It is now read-only.

Commit 9660e49

Browse files
committed
refactor to setup.py to accept a publish command
1 parent 6683151 commit 9660e49

File tree

1 file changed

+81
-8
lines changed

1 file changed

+81
-8
lines changed

setup.py

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,97 @@
1-
from setuptools import find_packages, setup
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
import io
5+
import os
6+
from shutil import rmtree
7+
import sys
8+
9+
from setuptools import Command, find_packages, setup
10+
11+
12+
# Package meta-data.
13+
VERSION = __import__("ajax_views").__version__
14+
NAME = 'django-ajax-partials'
15+
DESCRIPTION = 'Django module to easily use generic views with ajax. '
16+
URL = 'https://github.com/dipcode-software/django-ajax-partials/'
17+
EMAIL = 'team@dipcode.com'
18+
AUTHOR = 'Dipcode'
19+
20+
21+
here = os.path.abspath(os.path.dirname(__file__))
22+
with io.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
23+
long_description = '\n' + f.read()
24+
25+
26+
class PublishCommand(Command):
27+
"""Support setup.py publish."""
28+
29+
description = 'Build and publish the package.'
30+
user_options = []
31+
environment = None
32+
33+
@staticmethod
34+
def status(s):
35+
"""Prints things in bold."""
36+
print('\033[1m{0}\033[0m'.format(s))
37+
38+
def initialize_options(self):
39+
pass
40+
41+
def finalize_options(self):
42+
pass
43+
44+
def run(self):
45+
try:
46+
self.status('Removing previous builds…')
47+
rmtree(os.path.join(here, 'dist'))
48+
rmtree(os.path.join(here, 'build'))
49+
except OSError:
50+
pass
51+
52+
self.status('Building Source and Wheel distribution…')
53+
os.system(
54+
'{0} setup.py sdist bdist_wheel '.format(sys.executable)
55+
)
56+
57+
self.status('Uploading the package to {env} via Twine…'\
58+
.format(env=self.environment))
59+
os.system('twine upload --repository {env} dist/*'.format(env=self.environment))
60+
61+
sys.exit()
62+
63+
64+
class ProductionPublishCommand(PublishCommand):
65+
environment = 'pypi'
66+
67+
68+
class DevelopmentPublishCommand(PublishCommand):
69+
environment = 'testpypi'
270

371

472
setup(
5-
name='django-ajax-partials',
6-
version=__import__("ajax_views").__version__,
73+
name=NAME,
74+
version=VERSION,
75+
description=DESCRIPTION,
76+
long_description=long_description,
77+
author=AUTHOR,
78+
author_email=EMAIL,
79+
url=URL,
780
packages=find_packages(),
881
include_package_data=True,
982
license='MIT',
10-
description='Django module to easily use generic views with ajax.',
11-
url='https://github.com/dipcode-software/django-ajax-partials/',
12-
author='Dipcode',
13-
author_email='team@dipcode.com',
1483
classifiers=[
1584
'Environment :: Web Environment',
1685
'Framework :: Django',
17-
'Framework :: Django :: 1.10',
86+
'Framework :: Django :: 1.11',
1887
'Intended Audience :: Developers',
1988
'License :: OSI Approved :: MIT License',
2089
'Operating System :: OS Independent',
2190
'Programming Language :: Python',
2291
'Programming Language :: Python :: 2.7',
2392
],
93+
cmdclass={
94+
'publish_dev': DevelopmentPublishCommand,
95+
'publish_prod': ProductionPublishCommand,
96+
},
2497
)

0 commit comments

Comments
 (0)