This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
234 lines (199 loc) · 6.56 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import os.path
import sys
import time
import subprocess
from setuptools import setup, find_packages, Command
from setuptools.command.test import test
def read(fname):
with open(os.path.join(os.path.dirname(__file__), fname)) as fp:
return fp.read()
def readlines(fname):
return [l.strip() for l in read(fname).strip().splitlines()]
def runcmd(cmd):
with subprocess.Popen(
cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) as p:
out, err = p.communicate()
return out, err
class PyTest(test):
def finalize_options(self):
super(PyTest, self).finalize_options()
self.test_args = ['tests']
self.test_suite = True
def run_tests(self):
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)
class GenerateVersionCommand(Command):
description = 'generates a version file'
user_options = [
('force=', 'f', 'force a specific version number')]
def initialize_options(self):
self.force = None
def finalize_options(self):
pass
def run(self):
v = self.force or generate_version()
write_version(v)
print("Generated version %s" % v)
return 0
def generate_version():
""" Generate a version file from the source control information.
(this is loosely based on what Mercurial does)"""
if os.path.isdir(os.path.join(os.path.dirname(__file__), '.hg')):
return generate_version_from_mercurial()
elif os.path.isdir(os.path.join(os.path.dirname(__file__), '.git')):
return generate_version_from_git()
else:
raise Exception("Can't generate version number: this is not a "
"Mercurial repository.")
def generate_version_from_mercurial():
try:
# Get the version we're currently on. Also see if we have local
# changes.
cmd = ['hg', 'id', '-i']
hgid, err = runcmd(cmd)
hgid = hgid.decode('utf8').strip()
has_local_changes = hgid.endswith('+')
hgid = hgid.rstrip('+')
# Get the tags on the current version.
cmd = ['hg', 'log', '-r', '.', '--template', '{tags}\n']
tags, err = runcmd(cmd)
versions = [t for t in tags.decode('utf8').split() if t[0].isdigit()]
if versions:
# Use the tag found at the current revision.
version = versions[-1]
else:
# Use the latest tag, but add info about how many revisions
# there have been since then.
cmd = ['hg', 'parents', '--template',
'{latesttag}+{latesttagdistance}']
version, err = runcmd(cmd)
tag, dist = version.decode('utf8').split('+')
if dist == '1':
# We're on the commit that created the tag in the first place.
# Let's just do as if we were on the tag.
version = tag
else:
version = '%s+%s.%s' % (tag, dist, hgid)
if has_local_changes:
if '+' in version:
version += '.'
else:
version += '+'
version += time.strftime('%Y%m%d')
return version
except OSError:
raise Exception("Can't generate version number: Mercurial isn't "
"installed, or in the PATH.")
except Exception as ex:
raise Exception("Can't generate version number: %s" % ex)
def generate_version_from_git():
try:
cmd = ['git', 'describe', '--tags', '--dirty=+']
version, err = runcmd(cmd)
version = version.decode('utf8').strip()
if version.endswith('+'):
version += time.strftime('%Y%m%d')
return version
except OSError:
raise Exception("Can't generate version number: Git isn't installed, "
"or in the PATH.")
except Exception as ex:
raise Exception("Can't generate version number: %s" % ex)
def write_version(version):
if not version:
raise Exception("No version to write!")
f = open("piecrust/__version__.py", "w")
f.write('# this file is autogenerated by setup.py\n')
f.write('APP_VERSION = "%s"\n' % version)
f.close()
try:
from piecrust.__version__ import APP_VERSION
version = APP_VERSION
except ImportError:
print(
"WARNING: Can't get version from version file. "
"Will use version `0.0`.")
version = '0.0'
install_requires = [
'beautifulsoup4>=4.7.0',
'colorama>=0.4.0',
'compressinja>=0.0.2',
'Flask-IndieAuth>=0.0.3.2',
'Flask-Login>=0.4.1',
'Flask>=1.0.2',
'Inukshuk>=0.1.2',
'Jinja2>=2.10.1',
'Markdown>=3.1',
'MarkupSafe>=1.1',
'mf2py>=1.1.2',
'paramiko>=2.4.2',
'Pillow>=6.0.0',
'Pygments>=2.2.0',
'pystache>=0.5.4',
'python-dateutil>=2.8',
'PyYAML>=5.1',
'repoze.lru>=0.7',
'requests>=2.21.0',
'smartypants>=2.0.1',
'strict-rfc3339>=0.7',
'textile>=3.0.3',
'Unidecode>=1.0.23',
'watchdog>=0.9.0',
'Werkzeug>=0.15.2',
]
tests_require = [
'invoke>=1.2.0',
'mock>=3.0.5',
'pytest>=4.4.1',
'pytest-cov>=2.6.1',
'pytest-mock>=1.10.4',
]
setup(
name="PieCrust",
version=version,
description="A powerful static website generator and lightweight CMS.",
long_description=read('README.rst') + '\n\n' + read('CHANGELOG.rst'),
author="Ludovic Chabant",
author_email="ludovic@chabant.com",
license="Apache License 2.0",
url="http://bolt80.com/piecrust",
keywords=' '.join([
'python',
'website',
'generator',
'blog',
'portfolio',
'gallery',
'cms'
]),
packages=find_packages(exclude=['garcon', 'tests']),
include_package_data=True,
zip_safe=False,
install_requires=install_requires,
tests_require=tests_require,
cmdclass={
'test': PyTest,
'version': GenerateVersionCommand
},
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: Apache Software License',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Natural Language :: English',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Internet :: WWW/HTTP :: Site Management'
],
entry_points={'console_scripts': [
'chef = piecrust.main:main'
]}
)