-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathbrand_python.py
More file actions
41 lines (31 loc) · 1.25 KB
/
brand_python.py
File metadata and controls
41 lines (31 loc) · 1.25 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
import argparse
import os
import re
platform_file = os.path.join('Lib', 'platform.py')
get_version_file = os.path.join('Python', 'getversion.c')
def patch_platform(msg):
with open(platform_file, 'r') as fh:
lines = list(fh)
lines_it = iter(lines)
with open(platform_file, 'w') as fh:
for line in lines_it:
fh.write(line)
if line.startswith('_sys_version_parser'):
next_line = next(lines_it)
fh.write(" r'([\w.+]+)\s*" + re.escape(' ' + msg) + "\s*'\n")
def patch_get_version(msg):
with open(get_version_file, 'r') as fh:
content = list(fh)
lines = iter(content)
with open(get_version_file, 'w') as fh:
for line in lines:
if line.strip().startswith('PyOS_snprintf(version, sizeof(version)') and "Stackless" in line:
fh.write(' PyOS_snprintf(version, sizeof(version),\n')
fh.write(' "%.80s Stackless %.80s ' + msg.replace('"', '\\"') + ' (%.80s) %.80s",\n')
else:
fh.write(line)
msg = os.environ.get('python_branding', '<undefined>')
if msg == '<undefined>':
msg = "| packaged by conda-forge |"
# patch_platform(msg) # not required for stackless
patch_get_version(msg)