-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmake_upload.py
executable file
·104 lines (85 loc) · 4.35 KB
/
make_upload.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
#!/usr/bin/env python3
#
import sys, optparse, subprocess, platform, glob
distDir = "/Users/erwin/coding/pyimfit/dist/"
fixedWheelsDir = distDir + "fixed_wheels/"
WHEEL_NAME_TEMPLATE = "pyimfit-{0}-cp{1}-cp{1}-{2}.whl"
WHEEL_PREFIX_TEMPLATE = "pyimfit-{0}-"
# delocate-wheel -w fixed_wheels -v pyimfit-${VERSION_NUM}-cp312-cp312-${WHEEL_SUFFIX}.whl
def main( argv=None ):
usageString = "%prog <version-number> [options]\n"
parser = optparse.OptionParser(usage=usageString, version="%prog ")
parser.add_option("--test-upload", action="store_true", dest="doTestUpload",
default=False, help="do test upload (to TestPyPI)")
parser.add_option("--upload", action="store_true", dest="doUpload",
default=False, help="Upload to PyPI)")
parser.add_option("--skip-build", action="store_false", dest="doBuild",
default=True, help="Skip the build process")
parser.add_option("--python", dest="pyVersion", type="str", default=None,
help="Build only for this version of Python [default = 3.10-3.12]")
(options, args) = parser.parse_args(argv)
# args[0] = name program was called with
# args[1] = first actual argument, etc.
if len(args) < 2:
print("You must supply a PyImfit version number!\n")
return None
versionNum = args[1]
# Figure out which type of macOS architecture we're running under
proctype = platform.processor()
if proctype == "arm":
usingAppleSilicon = True
prelimString = "export _PYTHON_HOST_PLATFORM='macosx-11.0-arm64' ; export ARCHFLAGS='-arch arm64' ; "
wheelSuffix = "macosx_11_0_arm64"
pythonVersionList = ["3.10", "3.11", "3.12"]
else:
usingAppleSilicon = False
prelimString = "export _PYTHON_HOST_PLATFORM='macosx-10.9-x86_64' ; export ARCHFLAGS='-arch x86_64' ; "
wheelSuffix = "macosx_10_9_x86_64"
pythonVersionList = ["3.10", "3.11", "3.12"]
if options.pyVersion is not None:
pythonVersionList = [options.pyVersion]
if options.doBuild:
# Make sdist (.tar.gz) and macOS binary wheels
# Note that this particular formatting of cmdLine is necessary (trying to define the environment
# variables separately and passing them to subprocess.run via its "env" keyword ends up producing
# an error when wheel.py tries to parse the output of distutils.util.get_platform)
for pythonVersion in pythonVersionList:
cmdLine = prelimString + "python" + pythonVersion + " setup.py sdist bdist_wheel"
print(cmdLine)
result = subprocess.run([cmdLine], shell=True)
# Copy shared libs into wheel using delocate
print("\nRunning delocate...\n")
for pythonVersion in pythonVersionList:
vname = pythonVersion.replace(".", "")
if pythonVersion in ["3.12", "3.13"] and not usingAppleSilicon:
# special case of Python 3.12 (and 3.13?) on Intel macOS, where the resulting wheel
# is named with "macos_10_13"
wheelSuffix = "macosx_10_13_x86_64"
wheelname = WHEEL_NAME_TEMPLATE.format(versionNum, vname, wheelSuffix)
cmdLine = "cd dist ; delocate-wheel -w fixed_wheels -v {0}".format(wheelname)
print(cmdLine)
result = subprocess.run([cmdLine], shell=True)
else:
print("Skipping build phase...")
# Upload processed wheels
if options.doUpload or options.doTestUpload:
if options.doUpload:
print("\nUploading to PyPi...")
repoString = ""
else:
print("\nUploading to TestPyPi...")
repoString = "-r testpypi"
# source distribution:
cmdLine = "python3 -m twine upload {0} dist/pyimfit-{1}.tar.gz".format(repoString, versionNum)
print(cmdLine)
result = subprocess.run([cmdLine], shell=True)
# binary wheels
wheel_prefix = WHEEL_PREFIX_TEMPLATE.format(versionNum)
wheelList = glob.glob(fixedWheelsDir + "{0}*.whl".format(wheel_prefix))
for wheelname in wheelList:
cmdLine = "python3 -m twine upload {0} {1}".format(repoString, wheelname)
print(cmdLine)
result = subprocess.run([cmdLine], shell=True)
print("\nDone!")
if __name__ == '__main__':
main(sys.argv)