setup.py 5.59 KB
Newer Older
Chris Wanstrath committed
1
#!/usr/bin/env python
2
# coding: utf-8
Chris Wanstrath committed
3

4
"""
5
This script supports publishing Pystache to PyPI.
6

7 8 9 10
This docstring contains instructions to Pystache maintainers on how
to release a new version of Pystache.

(1) Push to PyPI.  To release a new version of Pystache to PyPI--
11

12 13
    http://pypi.python.org/pypi/pystache

14 15 16
create a PyPI user account if you do not already have one.  The user account
will need permissions to push to PyPI.  A current "Package Index Owner" of
Pystache can grant you those permissions.
17

18
When you have permissions, run the following (after preparing the release,
19
merging to master, bumping the version number in setup.py, etc):
20

21
    python setup.py publish
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

If you get an error like the following--

    Upload failed (401): You must be identified to edit package information

then add a file called .pyirc to your home directory with the following
contents:

    [server-login]
    username: <PyPI username>
    password: <PyPI password>

as described here, for example:

    http://docs.python.org/release/2.5.2/dist/pypirc.html
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51
(2) Tag the release on GitHub.  Here are some commands for tagging.

List current tags:

    git tag -l -n3

Create an annotated tag:

    git tag -a -m "Version 0.5.1" "v0.5.1"

Push a tag to GitHub:

    git push --tags defunkt v0.5.1

52
"""
Chris Wanstrath committed
53

54 55 56
import os
import sys

57 58 59 60 61
py_version = sys.version_info

# Distribute works with Python 2.3.5 and above:
#   http://packages.python.org/distribute/setuptools.html#building-and-distributing-packages-with-distribute
if py_version < (2, 3, 5):
62
    # TODO: this might not work yet.
63 64 65 66
    import distutils as dist
    from distutils import core
    setup = core.setup
else:
67
    import setuptools as dist
68
    setup = dist.setup
69

70
# TODO: use the logging module instead of printing.
71 72
# TODO: include the following in a verbose mode.
# print("Using: version %s of %s" % (repr(dist.__version__), repr(dist)))
73

74

75
VERSION = '0.5.2-rc'  # Also change in pystache/__init__.py.
Chris Wanstrath committed
76

77 78 79 80
HISTORY_PATH = 'HISTORY.rst'
LICENSE_PATH = 'LICENSE'
README_PATH = 'README.rst'

81 82 83 84 85 86 87 88 89 90 91 92 93 94
CLASSIFIERS = (
    'Development Status :: 4 - Beta',
    'License :: OSI Approved :: MIT License',
    'Programming Language :: Python',
    'Programming Language :: Python :: 2',
    'Programming Language :: Python :: 2.4',
    'Programming Language :: Python :: 2.5',
    'Programming Language :: Python :: 2.6',
    'Programming Language :: Python :: 2.7',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.1',
    'Programming Language :: Python :: 3.2',
)

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

def read(path):
    """
    Read and return the contents of a text file as a unicode string.

    """
    # This function implementation was chosen to be compatible across Python 2/3.
    f = open(path, 'rb')
    # We avoid use of the with keyword for Python 2.4 support.
    try:
        b = f.read()
    finally:
        f.close()

    return b.decode('utf-8')

Kenneth Reitz committed
111

112
def publish():
113 114
    """
    Publish this package to PyPI (aka "the Cheeseshop").
Kenneth Reitz committed
115

116
    """
Kenneth Reitz committed
117
    os.system('python setup.py sdist upload')
118 119


120 121 122 123 124
def make_long_description():
    """
    Return the long description for the package.

    """
125 126 127 128 129
    license = """\
License
=======

""" + read(LICENSE_PATH)
130

131 132
    sections = [read(README_PATH), read(HISTORY_PATH), license]
    return '\n\n'.join(sections)
133 134


135
if sys.argv[-1] == 'publish':
136 137 138
    publish()
    sys.exit()

139 140 141
# We follow the guidance here for compatibility with using setuptools instead
# of Distribute under Python 2 (on the subject of new, unrecognized keyword
# arguments to setup()):
142 143 144
#
#   http://packages.python.org/distribute/python3.html#note-on-compatibility-with-setuptools
#
145
if py_version < (3, ):
146 147 148
    extra = {}
else:
    extra = {
149
        # Causes 2to3 to be run during the build step.
150 151 152
        'use_2to3': True,
    }

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
# We use the package simplejson for older Python versions since Python
# does not contain the module json before 2.6:
#
#   http://docs.python.org/library/json.html
#
# Moreover, simplejson stopped officially support for Python 2.4 in version 2.1.0:
#
#   https://github.com/simplejson/simplejson/blob/master/CHANGES.txt
#
requires = []
if py_version < (2, 5):
    requires.append('simplejson<2.1')
elif py_version < (2, 6):
    requires.append('simplejson')

INSTALL_REQUIRES = requires

170 171
# TODO: decide whether to use find_packages() instead.  I'm not sure that
#   find_packages() is available with distutils, for example.
172 173
PACKAGES = [
    'pystache',
174
    'pystache.commands',
175 176 177
    # The following packages are only for testing.
    'pystache.tests',
    'pystache.tests.data',
178 179
    'pystache.tests.data.locator',
    'pystache.tests.examples',
180 181 182
]


183 184
def main(sys_argv):

185 186 187
    long_description = make_long_description()
    template_files = ['*.mustache', '*.txt']

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    setup(name='pystache',
          version=VERSION,
          license='MIT',
          description='Mustache for Python',
          long_description=long_description,
          author='Chris Wanstrath',
          author_email='chris@ozmm.org',
          maintainer='Chris Jerdonek',
          url='http://github.com/defunkt/pystache',
          install_requires=INSTALL_REQUIRES,
          packages=PACKAGES,
          package_data = {
              # Include template files so tests can be run.
              'pystache.tests.data': template_files,
              'pystache.tests.data.locator': template_files,
203
              'pystache.tests.examples': template_files,
204 205
          },
          entry_points = {
206 207 208 209
            'console_scripts': [
                'pystache=pystache.commands.render:main',
                'pystache-test=pystache.commands.test:main',
            ],
210
          },
211
          classifiers = CLASSIFIERS,
212 213 214 215 216 217
          **extra
    )


if __name__=='__main__':
    main(sys.argv)