Uh oh!
There was an error while loading. Please reload this page.
forked from gregneagle/relocatable-python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_relocatable_python_framework.py
More file actions
Latest commit
executable file
·139 lines (129 loc) · 4.89 KB
/
Copy pathmake_relocatable_python_framework.py
File metadata and controls
executable file
·139 lines (129 loc) · 4.89 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
#!/usr/bin/python3
# encoding: utf-8
#
# Copyright 2018 Greg Neagle.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tool to build relocatable Python frameworks on macOS"""
from __future__ importprint_function
importoptparse
importos
importsubprocess
fromlocallibsimportget
fromlocallibs.fiximportfix_broken_signatures, fix_other_things
fromlocallibs.installimportinstall_extras
fromlocallibs.relocatablizerimportrelocatablize
defmain():
"""Main"""
usage="usage: %prog [options]"
parser=optparse.OptionParser(usage=usage)
parser.add_option(
"--destination",
default=".",
help="Directory destination for the Python.framework",
)
parser.add_option(
"--local-source",
default=None,
help="Used existing on disk Python.framework")
parser.add_option(
"--baseurl",
default=get.DEFAULT_BASEURL,
help="Override the base URL used to download the framework.",
)
parser.add_option(
"--os-version",
default=get.DEFAULT_OS_VERSION,
help="Override the macOS version of the downloaded pkg. "
'Current supported versions are "10.6", "10.9", and "11". '
"Not all Python version and macOS version combinations are valid.",
)
parser.add_option(
"--python-version",
default=get.DEFAULT_PYTHON_VERSION,
help="Override the version of the Python framework to be downloaded. "
"See available versions at "
"https://www.python.org/downloads/mac-osx/",
)
parser.add_option(
"--pip-requirements",
default=None,
help="Path to a pip freeze requirements.txt file that describes extra "
"Python modules to be installed. If not provided, no modules will be installed.",
)
parser.add_option(
"--no-unsign",
dest="unsign",
action="store_false",
help="Do not unsign binaries and libraries after they are relocatablized."
)
parser.add_option(
"--upgrade-pip",
default=False,
action="store_true",
help="Upgrade pip prior to installing extra python modules."
)
parser.add_option(
"--without-pip",
default=False,
action="store_true",
help="Do not install pip."
)
parser.set_defaults(unsign=True)
parser.add_option(
"--sign",
default=None,
help="Sign using the designated signing identity"
)
options, _arguments=parser.parse_args()
ifoptions.local_source:
# verify that this is here
framework_path=os.path.expanduser(options.local_source)
ifos.path.basename(framework_path) !="Python.framework":
framework_path=os.path.join(framework_path, "Python.framework")
else:
framework_path=get.FrameworkGetter(
python_version=options.python_version,
os_version=options.os_version,
base_url=options.baseurl,
).download_and_extract(destination=options.destination)
ifframework_path:
files_relocatablized=relocatablize(framework_path)
ifoptions.unsign:
fix_broken_signatures(files_relocatablized)
short_version=".".join(options.python_version.split(".")[0:2])
install_extras(
framework_path,
version=short_version,
requirements_file=options.pip_requirements,
upgrade_pip=options.upgrade_pip,
without_pip=options.without_pip
)
iffix_other_things(framework_path, short_version):
print()
print("Done!")
print("Customized, relocatable framework is at %s"%framework_path)
ifoptions.sign:
sign_items= []
forroot, directories, filenamesinos.walk(os.path.join(options.destination,'Python.framework')):
forfilenameinfilenames:
if'.so'infilenameor'.dylib'infilename:
sign_items+= [os.path.join(root,filename)]
sign_items+= ['Python.framework']
command_parameters= ['/usr/bin/codesign', '--force', '-o', 'runtime', '--timestamp', '--sign',
options.sign, '--preserve-metadata=identifier,entitlements,flags'] \
+sign_items
sign_result=subprocess.check_output(command_parameters, stderr=subprocess.STDOUT)
print(sign_result.decode('utf-8'))
if__name__=="__main__":
main()