This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
setup.py
executable file
·315 lines (262 loc) · 10 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/env python3
# coding: utf-8
"""
PyLucid distutils setup
~~~~~~~~~~~~~~~~~~~~~~~
Links
~~~~~
http://www.python-forum.de/viewtopic.php?f=21&t=26895 (de)
:copyleft: 2009-2019 by the PyLucid team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
from __future__ import print_function
import distutils
import os
import sys
import subprocess
import shutil
if sys.version_info < (3, 5):
print("\nERROR: PyLucid requires Python 3.5 or greater!\n")
sys.exit(101)
from setuptools import setup, find_packages
PACKAGE_ROOT = os.path.dirname(os.path.abspath(__file__))
__version__="<unknown>"
def read(*args):
return open(os.path.join(PACKAGE_ROOT, *args)).read()
exec(read('pylucid', 'version.py'))
class BaseCommand(distutils.cmd.Command):
user_options = []
def initialize_options(self): pass
def finalize_options(self): pass
class TestCommand(BaseCommand):
"""Distutils command to run tests via py.test: 'python setup.py test'."""
description = "Run tests via 'py.test'."
def run(self):
self.announce("Running tests...", level=distutils.log.INFO)
returncode = subprocess.call(['pytest'])
sys.exit(returncode)
def get_authors():
try:
with open(os.path.join(PACKAGE_ROOT, "AUTHORS"), "r") as f:
authors = [l.strip(" *\r\n") for l in f if l.strip().startswith("*")]
except Exception as err:
authors = "[Error: %s]" % err
return authors
#_____________________________________________________________________________
# convert creole to ReSt on-the-fly, see also:
# https://github.com/jedie/python-creole/wiki/Use-In-Setup
long_description = None
for arg in ("test", "check", "register", "sdist", "--long-description"):
if arg in sys.argv:
try:
from creole.setup_utils import get_long_description
except ImportError as err:
raise ImportError("%s - Please install python-creole - e.g.: pip install python-creole" % err)
else:
long_description = get_long_description(PACKAGE_ROOT)
break
#----------------------------------------------------------------------------
if "publish" in sys.argv:
"""
'publish' helper for setup.py
Build and upload to PyPi, if...
... __version__ doesn't contains "dev"
... we are on git 'master' branch
... git repository is 'clean' (no changed files)
Upload with "twine", git tag the current version and git push --tag
The cli arguments will be pass to 'twine'. So this is possible:
* Display 'twine' help page...: ./setup.py publish --help
* use testpypi................: ./setup.py publish --repository=test
TODO: Look at: https://github.com/zestsoftware/zest.releaser
Source: https://github.com/jedie/python-code-snippets/blob/master/CodeSnippets/setup_publish.py
copyleft 2015-2019 Jens Diemer - GNU GPL v2+
"""
assert sys.version_info[0] > 2, "Python v3 is needed!"
import_error = False
try:
# Test if wheel is installed, otherwise the user will only see:
# error: invalid command 'bdist_wheel'
import wheel
except ImportError as err:
print("\nError: %s" % err)
print("\nMaybe https://pypi.org/project/wheel is not installed or virtualenv not activated?!?")
print("e.g.:")
print(" ~/your/env/$ source bin/activate")
print(" ~/your/env/$ pip install wheel")
import_error = True
try:
import twine
except ImportError as err:
print("\nError: %s" % err)
print("\nMaybe https://pypi.org/project/twine is not installed or virtualenv not activated?!?")
print("e.g.:")
print(" ~/your/env/$ source bin/activate")
print(" ~/your/env/$ pip install twine")
import_error = True
if import_error:
sys.exit(-1)
def verbose_check_output(*args):
""" 'verbose' version of subprocess.check_output() """
call_info = "Call: %r" % " ".join(args)
try:
output = subprocess.check_output(args, universal_newlines=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as err:
print("\n***ERROR:")
print(err.output)
raise
return call_info, output
def verbose_check_call(*args):
""" 'verbose' version of subprocess.check_call() """
print("\tCall: %r\n" % " ".join(args))
subprocess.check_call(args, universal_newlines=True)
def confirm(txt):
print("\n%s" % txt)
if input("\nPublish anyhow? (Y/N)").lower() not in ("y", "j"):
print("Bye.")
sys.exit(-1)
for key in ("dev", "rc"):
if key in __version__:
confirm("WARNING: Version contains %r: v%s\n" % (key, __version__))
break
print("\nCheck if we are on 'master' branch:")
call_info, output = verbose_check_output("git", "branch", "--no-color")
print("\t%s" % call_info)
if "* master" in output:
print("OK")
else:
confirm("\nNOTE: It seems you are not on 'master':\n%s" % output)
##########################################################################
# check if PyLucid boot file is up-to-date
# Just update own boot file and the "prero is clean" check will faile, on changes ;)
#
verbose_check_call("pylucid_admin", "update_own_boot_file")
#
##########################################################################
print("\ncheck if if git repro is clean:")
call_info, output = verbose_check_output("git", "status", "--porcelain")
print("\t%s" % call_info)
if output == "":
print("OK")
else:
print("\n *** ERROR: git repro not clean:")
print(output)
sys.exit(-1)
print("\nRun './setup.py check':")
call_info, output = verbose_check_output("./setup.py", "check")
if "warning" in output:
print(output)
confirm("Warning found!")
else:
print("OK")
print("\ncheck if pull is needed")
verbose_check_call("git", "fetch", "--all")
call_info, output = verbose_check_output("git", "log", "HEAD..origin/master", "--oneline")
print("\t%s" % call_info)
if output == "":
print("OK")
else:
print("\n *** ERROR: git repro is not up-to-date:")
print(output)
sys.exit(-1)
verbose_check_call("git", "push")
print("\nCleanup old builds:")
def rmtree(path):
path = os.path.abspath(path)
if os.path.isdir(path):
print("\tremove tree:", path)
shutil.rmtree(path)
rmtree("./dist")
rmtree("./build")
print("\nbuild but don't upload...")
log_filename="build.log"
with open(log_filename, "a") as log:
call_info, output = verbose_check_output(
sys.executable or "python",
"setup.py", "sdist", "bdist_wheel", "bdist_egg"
)
print("\t%s" % call_info)
log.write(call_info)
log.write(output)
print("Build output is in log file: %r" % log_filename)
git_tag="v%s" % __version__
print("\ncheck git tag")
call_info, output = verbose_check_output("git", "log", "HEAD..origin/master", "--oneline")
if git_tag in output:
print("\n *** ERROR: git tag %r already exists!" % git_tag)
print(output)
sys.exit(-1)
else:
print("OK")
print("\nUpload with twine:")
twine_args = sys.argv[1:]
twine_args.remove("publish")
twine_args.insert(1, "dist/*")
print("\ttwine upload command args: %r" % " ".join(twine_args))
from twine.commands.upload import main as twine_upload
twine_upload(twine_args)
print("\ngit tag version")
verbose_check_call("git", "tag", git_tag)
print("\ngit push tag to server")
verbose_check_call("git", "push", "--tags")
sys.exit(0)
setup(
name='PyLucid',
version=__version__,
description='PyLucid CMS',
long_description=long_description,
author=get_authors(),
author_email="[email protected]",
maintainer="Jens Diemer",
url='http://www.pylucid.org',
download_url = 'http://www.pylucid.org/en/download/',
packages=find_packages(
#exclude=[".project", ".pydevproject", "pylucid_project.external_plugins.*"]
),
include_package_data=True, # include package data under version control
python_requires='>=3.5',
install_requires=[
"bootstrap_env>=1.0.0rc17",
],
scripts=[
'pylucid/pylucid_boot.py',
'pylucid/pylucid_admin.py',
],
entry_points={'console_scripts': [
"pylucid_boot = pylucid.pylucid_boot:main",
"pylucid_admin = pylucid.pylucid_admin:main",
]},
#
# We don't set 'install_requires', because the requirements.txt files should be used!
# Bootstrap PyLucid works in this way:
# - create virtualenv
# - pip install pylucid
# - pylucid_admin update_env
#
zip_safe=False,
classifiers=[ # https://pypi.python.org/pypi?%3Aaction=list_classifiers
"Development Status :: 2 - Pre-Alpha",
# "Development Status :: 3 - Alpha",
# "Development Status :: 4 - Beta",
# "Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Intended Audience :: Developers",
# "Intended Audience :: Education",
# "Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3 :: Only",
"Framework :: Django",
"Framework :: Django :: 1.11",
"Topic :: Database :: Front-Ends",
"Topic :: Documentation",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Internet :: WWW/HTTP :: Site Management",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
"Operating System :: OS Independent",
],
cmdclass={
'test': TestCommand,
}
)