Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork252
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·397 lines (340 loc) · 12.6 KB
/
setup.py
File metadata and controls
executable file
·397 lines (340 loc) · 12.6 KB
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/usr/bin/env python3
importos
importplatform
importre
importsubprocess
fromsetuptoolsimportsetup,Command
fromsetuptools.command.buildimportbuild
try:
frombabel.messagesimportfrontendasbabel
using_translations=True
exceptImportError:
using_translations=False
try:
importsphinx
# Sphinx 1.5 and newer support Python 3.6
using_sphinx=sphinx.__version__>="1.5"
exceptImportError:
using_sphinx=False
ifusing_sphinx:
importsys
fromioimportStringIO
fromsetuptools.errorsimportExecError
fromsphinx.applicationimportSphinx
fromsphinx.cmd.buildimporthandle_exception
fromsphinx.util.consoleimportcolor_terminal,nocolor
fromsphinx.util.docutilsimportdocutils_namespace,patch_docutils
fromsphinx.util.osutilimportabspath
classBuildDoc(Command):
"""
Distutils command to build Sphinx documentation.
The Sphinx build can then be triggered from distutils, and some Sphinx
options can be set in ``setup.py`` or ``setup.cfg`` instead of Sphinx's
own configuration file.
For instance, from `setup.py`::
# this is only necessary when not using setuptools/distribute
from sphinx.setup_command import BuildDoc
cmdclass = {'build_sphinx': BuildDoc}
name = 'My project'
version = '1.2'
release = '1.2.0'
setup(
name=name,
author='Bernard Montgomery',
version=release,
cmdclass=cmdclass,
# these are optional and override conf.py settings
command_options={
'build_sphinx': {
'project': ('setup.py', name),
'version': ('setup.py', version),
'release': ('setup.py', release)}},
)
Or add this section in ``setup.cfg``::
[build_sphinx]
project = 'My project'
version = 1.2
release = 1.2.0
"""
description="Build Sphinx documentation"
user_options= [
("fresh-env","E","discard saved environment"),
("all-files","a","build all files"),
("source-dir=","s","Source directory"),
("build-dir=",None,"Build directory"),
("config-dir=","c","Location of the configuration directory"),
(
"builder=",
"b",
"The builder (or builders) to use. Can be a comma- "
'or space-separated list. Defaults to "html"',
),
("warning-is-error","W","Turn warning into errors"),
("project=",None,"The documented project's name"),
("version=",None,"The short X.Y version"),
(
"release=",
None,
"The full version, including alpha/beta/rc tags",
),
(
"today=",
None,
"How to format the current date, used as the "
"replacement for |today|",
),
("link-index","i","Link index.html to the master doc"),
("copyright",None,"The copyright string"),
("pdb",None,"Start pdb on exception"),
("verbosity","v","increase verbosity (can be repeated)"),
(
"nitpicky",
"n",
"nit-picky mode, warn about all missing references",
),
("keep-going",None,"With -W, keep going when getting warnings"),
]
boolean_options= [
"fresh-env",
"all-files",
"warning-is-error",
"link-index",
"nitpicky",
]
definitialize_options(self)->None:
self.fresh_env=self.all_files=False
self.pdb=False
self.source_dir:str=None
self.build_dir:str=None
self.builder="html"
self.warning_is_error=False
self.project=""
self.version=""
self.release=""
self.today=""
self.config_dir:str=None
self.link_index=False
self.copyright=""
# Link verbosity to distutils' (which uses 1 by default).
self.verbosity=self.distribution.verbose-1# type: ignore
self.traceback=False
self.nitpicky=False
self.keep_going=False
def_guess_source_dir(self)->str:
forguessin ("doc","docs"):
ifnotos.path.isdir(guess):
continue
forroot,dirnames,filenamesinos.walk(guess):
if"conf.py"infilenames:
returnroot
returnos.curdir
deffinalize_options(self)->None:
self.ensure_string_list("builder")
ifself.source_dirisNone:
self.source_dir=self._guess_source_dir()
self.announce("Using source directory %s"%self.source_dir)
self.ensure_dirname("source_dir")
ifself.config_dirisNone:
self.config_dir=self.source_dir
ifself.build_dirisNone:
build=self.get_finalized_command("build")
self.build_dir=os.path.join(abspath(build.build_base),"sphinx")# type: ignore
self.doctree_dir=os.path.join(self.build_dir,"doctrees")
self.builder_target_dirs= [
(builder,os.path.join(self.build_dir,builder))
forbuilderinself.builder
]
defrun(self)->None:
ifnotcolor_terminal():
nocolor()
ifnotself.verbose:# type: ignore
status_stream=StringIO()
else:
status_stream=sys.stdout# type: ignore
confoverrides= {}
ifself.project:
confoverrides["project"]=self.project
ifself.version:
confoverrides["version"]=self.version
ifself.release:
confoverrides["release"]=self.release
ifself.today:
confoverrides["today"]=self.today
ifself.copyright:
confoverrides["copyright"]=self.copyright
ifself.nitpicky:
confoverrides["nitpicky"]=self.nitpicky
forbuilder,builder_target_dirinself.builder_target_dirs:
app=None
try:
confdir=self.config_dirorself.source_dir
withpatch_docutils(confdir),docutils_namespace():
app=Sphinx(
self.source_dir,
self.config_dir,
builder_target_dir,
self.doctree_dir,
builder,
confoverrides,
status_stream,
freshenv=self.fresh_env,
warningiserror=self.warning_is_error,
verbosity=self.verbosity,
keep_going=self.keep_going,
)
app.build(force_all=self.all_files)
ifapp.statuscode:
raiseExecError(
"caused by %s builder."%app.builder.name
)
exceptExceptionasexc:
handle_exception(app,self,exc,sys.stderr)
ifnotself.pdb:
raiseSystemExit(1)fromexc
ifnotself.link_index:
continue
src=app.config.root_doc+app.builder.out_suffix# type: ignore
dst=app.builder.get_outfilename("index")# type: ignore
os.symlink(src,dst)
# version handling
defgit_describe_to_python_version(version):
"""Convert output from git describe to PEP 440 conforming versions."""
version_info=version.split("-")
iflen(version_info)<2:
return"unknown"
# we always have $version-$release
release_type=version_info[1]
version_data= {
"version":version_info[0],
"release_type":release_type,
}
iflen(version_info)==4:
version_data["commits"]=version_info[2]
else:
version_data["commits"]=0
ifrelease_type=="release":
iflen(version_info)==2:
# format: $version-release
# This is the case at time of the release.
fmt="{version}"
eliflen(version_info)==4:
# format: $version-release-$commits-$hash
# This is the case after a release.
fmt="{version}-{commits}"
elifrelease_type=="dev":
# format: $version-dev-$commits-$hash or $version-dev
fmt="{version}.dev{commits}"
else:
match=re.match(r"^(alpha|beta|rc)(\d*)$",release_type)
ifmatchisNone:
return"unknown"
iflen(version_info)==2:
fmt="{version}{release_type}"
eliflen(version_info)==4:
fmt="{version}{release_type}-{commits}"
returnfmt.format(**version_data)
version_file="bpython/_version.py"
version="unknown"
try:
# get version from git describe
proc=subprocess.Popen(
["git","describe","--tags","--first-parent"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout=proc.communicate()[0].strip()
stdout=stdout.decode("ascii")
ifproc.returncode==0:
version=git_describe_to_python_version(stdout)
exceptOSError:
pass
ifversion=="unknown":
try:
# get version from existing version file
withopen(version_file)asvf:
version= (
vf.read()
.strip()
.split("=")[-1]
.replace("'","")
.replace('"',"")
)
version=version.strip()
exceptOSError:
pass
ifversion=="unknown":
# get version from directory name (tarballs downloaded from tags)
# directories are named bpython-X.Y-release in this case
basename=os.path.basename(os.path.dirname(__file__))
basename_components=basename.split("-")
if (
len(basename_components)==3
andbasename_components[0]=="bpython"
andbasename_components[2]=="release"
):
version=basename_components[1]
withopen(version_file,"w")asvf:
vf.write("# Auto-generated file, do not edit!\n")
vf.write(f'__version__ = "{version}"\n')
classcustom_build(build):
defrun(self):
ifusing_translations:
self.run_command("compile_catalog")
ifusing_sphinx:
self.run_command("build_sphinx_man")
cmdclass= {"build":custom_build}
translations_dir=os.path.join("bpython","translations")
# localization options
ifusing_translations:
cmdclass["compile_catalog"]=babel.compile_catalog
cmdclass["extract_messages"]=babel.extract_messages
cmdclass["update_catalog"]=babel.update_catalog
cmdclass["init_catalog"]=babel.init_catalog
ifusing_sphinx:
cmdclass["build_sphinx"]=BuildDoc
cmdclass["build_sphinx_man"]=BuildDoc
ifplatform.system()in ("FreeBSD","OpenBSD"):
man_dir="man"
else:
man_dir="share/man"
# manual pages
man_pages= [
(os.path.join(man_dir,"man1"), ["build/man/bpython.1"]),
(os.path.join(man_dir,"man5"), ["build/man/bpython-config.5"]),
]
else:
man_pages= []
data_files= [
# desktop shortcut
(
os.path.join("share","applications"),
["data/org.bpython-interpreter.bpython.desktop"],
),
# AppData
(
os.path.join("share","metainfo"),
["data/org.bpython-interpreter.bpython.metainfo.xml"],
),
# icon
(os.path.join("share","pixmaps"), ["data/bpython.png"]),
]
data_files.extend(man_pages)
# translations
mo_files= []
forlanguageinos.listdir(translations_dir):
mo_subpath=os.path.join(language,"LC_MESSAGES","bpython.mo")
ifos.path.exists(os.path.join(translations_dir,mo_subpath)):
mo_files.append(mo_subpath)
setup(
version=version,
data_files=data_files,
package_data={
"bpython": ["sample-config"],
"bpython.translations":mo_files,
"bpython.test": ["test.config","test.theme"],
},
cmdclass=cmdclass,
test_suite="bpython.test",
zip_safe=False,
)
# vim: fileencoding=utf-8 sw=4 ts=4 sts=4 ai et sta