forked from kovidgoyal/calibre
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·120 lines (90 loc) · 3.42 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·120 lines (90 loc) · 3.42 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
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os
import re
import sys
src_base = os.path.dirname(os.path.abspath(__file__))
def check_version_info():
with open(os.path.join(src_base, 'pyproject.toml')) as f:
raw = f.read()
m = re.search(r'''^requires-python\s*=\s*['"](.+?)['"]''', raw, flags=re.MULTILINE)
assert m is not None
minver = m.group(1)
m = re.match(r'(>=?)(\d+)\.(\d+)', minver)
assert m is not None
q = int(m.group(2)), int(m.group(3))
if m.group(1) == '>=':
is_ok = sys.version_info >= q
else:
is_ok = sys.version_info > q
if not is_ok:
sys.exit(f'calibre requires Python {minver}. Current Python version: {".".join(map(str, sys.version_info[:3]))}')
check_version_info()
sys.path.insert(0, src_base)
from setup import commands, get_warnings, prints
def option_parser():
import optparse
parser = optparse.OptionParser()
parser.add_option('-c', '--clean', default=False, action='store_true', help=('Instead of running the command delete all files generated by the command'))
parser.add_option('--clean-backups', default=False, action='store_true', help='Delete all backup files from the source tree')
parser.add_option('--clean-all', default=False, action='store_true', help='Delete all machine generated files from the source tree')
return parser
def clean_backups():
for root, _, files in os.walk('.'):
for name in files:
for t in ('.pyc', '.pyo', '~', '.swp', '.swo'):
if name.endswith(t):
os.remove(os.path.join(root, name))
def main(args=sys.argv):
if len(args) == 1 or args[1] in ('-h', '--help'):
print('Usage: python', args[0], 'command', '[options]')
print('\nWhere command is one of:')
print()
for x in sorted(commands.__all__):
print(f'{x:20} -', end=' ')
c = getattr(commands, x)
desc = getattr(c, 'short_description', c.description)
print(desc)
print('\nTo get help on a particular command, run:')
print('\tpython', args[0], 'command -h')
return 1
command = args[1]
if command not in commands.__all__:
print(command, 'is not a recognized command.')
print('Valid commands:', ', '.join(commands.__all__))
return 1
command = getattr(commands, command)
parser = option_parser()
command.add_all_options(parser)
usage = f'Usage: python setup.py {args[1]} [options]\n\n' + command.description
if command.usage_help:
usage += '\n\n' + command.usage_help
parser.set_usage(usage)
opts, args = parser.parse_args(args)
opts.cli_args = args[2:]
if opts.clean_backups:
clean_backups()
if opts.clean:
prints('Cleaning', args[1])
command.clean()
return 0
if opts.clean_all:
for cmd in commands.__all__:
prints('Cleaning', cmd)
getattr(commands, cmd).clean()
return 0
command.run_all(opts)
warnings = get_warnings()
if warnings:
print()
prints('There were', len(warnings), 'warning(s):')
print()
for args, kwargs in warnings:
prints('*', *args, **kwargs)
print()
return 0
if __name__ == '__main__':
sys.exit(main())