Mercurial > piecrust2
comparison setup.py @ 9:8f7ba2c95025
Add packaging and related files.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 16 Aug 2014 23:30:26 -0700 |
parents | |
children | e4a24512b814 |
comparison
equal
deleted
inserted
replaced
8:ff07f6d23450 | 9:8f7ba2c95025 |
---|---|
1 #!/usr/bin/env python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 import os | |
5 import os.path | |
6 import sys | |
7 import time | |
8 import subprocess | |
9 from setuptools import setup, find_packages | |
10 from setuptools.command.test import test | |
11 | |
12 | |
13 def read(fname): | |
14 with open(os.path.join(os.path.dirname(__file__), fname)) as fp: | |
15 return fp.read() | |
16 | |
17 | |
18 def runcmd(cmd): | |
19 with subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
20 stderr=subprocess.PIPE) as p: | |
21 out, err = p.communicate() | |
22 return out, err | |
23 | |
24 | |
25 class PyTest(test): | |
26 def finalize_options(self): | |
27 super(PyTest, self).finalize_options() | |
28 self.test_args = ['tests'] | |
29 self.test_suite = True | |
30 | |
31 def run_tests(self): | |
32 import pytest | |
33 errno = pytest.main(self.test_args) | |
34 sys.exit(errno) | |
35 | |
36 | |
37 # Figure out the version. | |
38 # (this is loosely based on what Mercurial does) | |
39 version = None | |
40 try: | |
41 if os.path.isdir(os.path.join(os.path.dirname(__file__), '.hg')): | |
42 cmd = ['hg', 'log', '-r', '.', '--template', '{tags}\n'] | |
43 tags, err = runcmd(cmd) | |
44 versions = [t for t in tags.decode('utf8').split() if t[0].isdigit()] | |
45 | |
46 cmd = ['hg', 'id', '-i'] | |
47 hgid, err = runcmd(cmd) | |
48 hgid = hgid.decode('utf8').strip() | |
49 | |
50 if versions: | |
51 # Use tag found at the current revision. Add dirty flag if any. | |
52 version = versions[-1] | |
53 if hgid.endswith('+'): | |
54 version += '+' | |
55 else: | |
56 # Use latest tag. | |
57 cmd = ['hg', 'parents', '--template', '{latesttag}+{latesttagdistance}-'] | |
58 version, err = runcmd(cmd) | |
59 version = version.decode('utf8') + hgid | |
60 | |
61 if version.endswith('+'): | |
62 version += time.strftime('%Y%m%d') | |
63 except OSError: | |
64 # Mercurial isn't installed, or not in the PATH. | |
65 version = None | |
66 | |
67 | |
68 if version: | |
69 f = open("piecrust/__version__.py", "w") | |
70 f.write('# this file is autogenerated by setup.py\n') | |
71 f.write('version = "%s"\n' % version) | |
72 f.close() | |
73 | |
74 | |
75 try: | |
76 from piecrust import __version__ | |
77 version = __version__.version | |
78 except ImportError: | |
79 version = 'unknown' | |
80 | |
81 | |
82 setup(name="piecrust", | |
83 version=version, | |
84 description="A powerful static website generator and lightweight CMS.", | |
85 long_description=read('README.rst') + '\n\n' + read('CHANGELOG.rst'), | |
86 author="Ludovic Chabant", | |
87 author_email="ludovic@chabant.com", | |
88 license="Apache License 2.0", | |
89 url="http://github.com/ludovicchabant/piecrust2", | |
90 keywords=' '.join([ | |
91 'python', | |
92 'website', | |
93 'generator', | |
94 'blog', | |
95 'portfolio', | |
96 'gallery', | |
97 'cms' | |
98 ]), | |
99 packages=find_packages(), | |
100 include_package_data=True, | |
101 zip_safe=False, | |
102 install_requires=[ | |
103 'Jinja2==2.7.3', | |
104 'Markdown==2.4.1', | |
105 'MarkupSafe==0.23', | |
106 'PyYAML==3.11', | |
107 'Pygments==1.6', | |
108 'Werkzeug==0.9.6', | |
109 'colorama==0.3.1', | |
110 'mock==1.0.1', | |
111 'py==1.4.23', | |
112 'python-dateutil==2.2', | |
113 'repoze.lru==0.6', | |
114 'strict-rfc3339==0.4' | |
115 ], | |
116 tests_require=[ | |
117 'pytest==2.6.1', | |
118 'pytest-mock==0.2.0' | |
119 ], | |
120 cmdclass={ | |
121 'test': PyTest | |
122 }, | |
123 classifiers=[ | |
124 'Development Status :: 3 - Alpha', | |
125 'License :: OSI Approved :: Apache Software License', | |
126 'Environment :: Console', | |
127 'Intended Audience :: Developers', | |
128 'Intended Audience :: System Administrators', | |
129 'Natural Language :: English', | |
130 'Operating System :: MacOS :: MacOS X', | |
131 'Operating System :: POSIX :: Linux', | |
132 'Operating System :: Microsoft :: Windows', | |
133 'Programming Language :: Python', | |
134 'Programming Language :: Python :: 3' | |
135 ], | |
136 entry_points={'console_scripts': [ | |
137 'chef = piecrust.main:main', | |
138 ]} | |
139 ) | |
140 |