Skip to content

Commit 5f30eb0

Browse files
committed
Add tool for building manylinux wheels
1 parent 491446b commit 5f30eb0

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,31 @@ Double check that your import is correct.
5959
### `package github.com/a/b/c: /tmp/.../github.com/a/b exists but /tmp/.../github.com/a/b/.git does not - stale checkout?`
6060

6161
You've probably mistyped an import. Double check that your import is correct.
62+
63+
### Building manylinux wheels
64+
65+
`setuptools-golang` also provides a tool for building
66+
[PEP 513](https://www.python.org/dev/peps/pep-0513/) manylinux1 wheels so your
67+
consumers don't need to have a go compiler installed to use your library.
68+
69+
Simply run `setuptools-golang-build-manylinux-wheels` from your source
70+
directory. The resulting wheels will end up in `./dist`.
71+
72+
```
73+
$ setuptools-golang-build-manylinux-wheels
74+
75+
...
76+
77+
+ ls /dist -al
78+
total 8092
79+
drwxrwxr-x 2 1000 1000 4096 Feb 1 04:16 .
80+
drwxr-xr-x 41 root root 4096 Feb 1 04:15 ..
81+
-rw-r--r-- 1 1000 1000 2065095 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp27-cp27mu-manylinux1_x86_64.whl
82+
-rw-r--r-- 1 1000 1000 2063299 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp34-cp34m-manylinux1_x86_64.whl
83+
-rw-r--r-- 1 1000 1000 2064862 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
84+
-rw-r--r-- 1 1000 1000 2064873 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
85+
-rw-rw-r-- 1 1000 1000 4273 Feb 1 04:14 setuptools-golang-examples-0.1.1.tar.gz
86+
*******************************************************************************
87+
Your wheels have been built into ./dist
88+
*******************************************************************************
89+
```

setup.py

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
py_modules=['setuptools_golang'],
2525
install_requires=[],
2626
entry_points={
27+
'console_scripts': [
28+
'setuptools-golang-build-manylinux-wheels = '
29+
'setuptools_golang:build_manylinux_wheels',
30+
],
2731
'distutils.setup_keywords': [
2832
'build_golang = setuptools_golang:set_build_ext',
2933
],

setuptools_golang.py

+41
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,44 @@ def set_build_ext(dist, attr, value):
9595
root = value['root']
9696
base = dist.cmdclass.get('build_ext', _build_ext)
9797
dist.cmdclass['build_ext'] = _get_build_ext_cls(base, root)
98+
99+
100+
GOLANG = 'https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gz'
101+
WHEEL_ARGS = '--no-deps --wheel-dir /tmp /dist/*.tar.gz'
102+
103+
104+
def build_manylinux_wheels(argv=None): # pragma: no cover
105+
assert os.path.exists('setup.py')
106+
shutil.rmtree('dist')
107+
os.makedirs('dist')
108+
_check_call(('python', 'setup.py', 'sdist'), cwd='.', env={})
109+
_check_call(
110+
(
111+
'docker', 'run',
112+
'--volume', '{}:/dist:rw'.format(os.path.abspath('dist')),
113+
# I'd use --user, but this breaks git:
114+
# http://stackoverflow.com/a/20272540/812183
115+
'--env', 'UID={}'.format(os.getuid()),
116+
'--env', 'GID={}'.format(os.getgid()),
117+
'quay.io/pypa/manylinux1_x86_64:latest',
118+
'bash', '-exc',
119+
'cd /tmp\n'
120+
'wget {golang} -q --no-check-certificate -O /tmp/golang.tar.gz\n'
121+
'tar -xf /tmp/golang.tar.gz\n'
122+
'export GOROOT=/tmp/go\n'
123+
'export PATH="$GOROOT/bin:$PATH"\n'
124+
'/opt/python/cp27-cp27mu/bin/pip wheel {wheel_args}\n'
125+
'/opt/python/cp34-cp34m/bin/pip wheel {wheel_args}\n'
126+
'/opt/python/cp35-cp35m/bin/pip wheel {wheel_args}\n'
127+
'/opt/python/cp36-cp36m/bin/pip wheel {wheel_args}\n'
128+
'mkdir /tmp/whls\n'
129+
'ls *.whl | xargs -n1 --verbose auditwheel repair -w /tmp/whls\n'
130+
'cp /tmp/whls/* /dist\n'
131+
'chown "$UID:$GID" /dist/*\n'
132+
'ls /dist -al\n'.format(golang=GOLANG, wheel_args=WHEEL_ARGS),
133+
),
134+
cwd='.', env={},
135+
)
136+
print('*' * 79)
137+
print('Your wheels have been built into ./dist')
138+
print('*' * 79)

0 commit comments

Comments
 (0)