"SenseNova-SI/docs/vscode:/vscode.git/clone" did not exist on "cda31672ccac2ed200e53bb24fa3d89bd71e3fea"
README.rst 13.5 KB
Newer Older
1
2
3
################################################
Utilities for building on Travis-CI and AppVeyor
################################################
4

5
A set of scripts to automate builds of OSX and manylinux1 wheels on the
Andrew Murray's avatar
Andrew Murray committed
6
`Travis-CI <https://travis-ci.org/>`_ infrastructure, and also Windows
7
wheels on the `AppVeyor <https://ci.appveyor.com/>`_ infrastructure.
Matthew Brett's avatar
Matthew Brett committed
8

9
The TravisCI scripts are designed to build *and test*:
Matthew Brett's avatar
Matthew Brett committed
10
11

* Dual architecture OSX wheels;
12
13
* 64-bit ``manylinux1_x86_64`` wheels, both narrow and wide unicode builds;
* 32-bit ``manylinux1_i686`` wheels, both narrow and wide unicode builds.
Matthew Brett's avatar
Matthew Brett committed
14

15
You can currently build and test against Pythons 2.7, 3.3, 3.4, 3.5, 3.6.
Matthew Brett's avatar
Matthew Brett committed
16
17
18
19
20

The small innovation here is that you can test against 32-bit builds, and both
wide and narrow unicode Python 2 builds, which was not easy on the default
travis-ci configurations.

21
22
23
24
25
26
27
The AppVeyor setup is designed to build *and test*:

* 64-bit Windows ``win_amd64`` wheels;
* 32-bit Windows ``win32`` wheels.

You can currently build and test against Pythons 2.7, 3.4, 3.5, 3.6.

28
29
30
31
32
33
34
35
36
37
38
39
40
*****************
How does it work?
*****************

Multibuild is a series of bash scripts that define bash functions to build and
test wheels.

Configuration is by overriding the default build function, and defining a test
function.

The bash scripts are layered, in the sense that they loaded in the following
sequence:

Matthew Brett's avatar
Matthew Brett committed
41
42
OSX
===
43

Matthew Brett's avatar
Matthew Brett committed
44
See ``multibuild/travis_osx_steps.sh``.
45

Matthew Brett's avatar
Matthew Brett committed
46
47
48
For build and test phases, these bash scripts get sourced one after the other,
so that functions and variables defined in later scripts can overwrite
functions and variables in earlier scripts:
49

Matthew Brett's avatar
Matthew Brett committed
50
51
* multibuild/common_utils.sh
* multibuild/osx_utils.sh
52
* env_vars.sh
Matthew Brett's avatar
Matthew Brett committed
53
54
* multibuild/library_builders.sh
* config.sh
55

56
57
See ``travis_osx_steps.sh`` to review source order.

Matthew Brett's avatar
Matthew Brett committed
58
59
60
The OSX build / test and phase are on the OSX VM started by travis-ci.
Therefore any environment variable defined in the ``.travis.yml`` or bash
shell scripts listed above are available for your build and test.
61

62
63
64
The ``build_wheel`` function builds the wheel, and the ``install_run``
function installs the wheel and tests it.  Look in ``common_utils.sh`` for
default definitions of these functions.  See below for more details.
65

Matthew Brett's avatar
Matthew Brett committed
66
67
Manylinux
=========
68

69
70
The build phase is in a Manylinux1 docker container, but the test phase is in
a clean Ubuntu 14.04 container.
71

Matthew Brett's avatar
Matthew Brett committed
72
73
Build phase
-----------
74

Matthew Brett's avatar
Matthew Brett committed
75
76
77
78
79
80
81
``multibuild/travis_linux_steps.sh`` defines the ``build_wheel`` function,
which starts up the Manylinux1 docker container to run a wrapper script
``multibuild/docker_build_wrap.sh``, that (within the container) sources the
following bash scripts:

* multibuild/common_utils.sh
* multibuild/manylinux_utils.sh
82
* env_vars.sh
Matthew Brett's avatar
Matthew Brett committed
83
84
85
* multibuild/library_builders.sh
* config.sh

86
87
See ``docker_build_wrap.sh`` to review the order of script sourcing.

88
89
90
See the definition of ``build_multilinux`` in
``multibuild/travis_linux_steps.sh`` for the environment variables passed from
travis-ci to the Manylinux1 container.
Matthew Brett's avatar
Matthew Brett committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

Once in the container, after sourcing the scripts above, the wrapper runs the
real ``build_wheel`` function, which now comes (by default) from
``multibuild/common_utils.sh``.

Test phase
----------

Testing is in an Ubuntu 14.04 docker container - see
``multibuild/docker_test_wrap.sh``.  ``multibuild/travis_linux_steps.sh``
defines the ``install_run`` function, which starts up the testing docker
container with a wrapper script ``multibuild/docker_test_wrap.sh``.  The
wrapper script sources the following bash scripts:

* multibuild/common_utils.sh
* config.sh

108
109
See ``docker_test_wrap.sh`` for script source order.

Matthew Brett's avatar
Matthew Brett committed
110
111
112
113
114
See ``install_run`` in ``multibuild/travis_linux_steps.sh`` for the
environment variables passed into the container.

It then (in the container) runs the real ``install_run`` command, which comes
(by default) from ``multibuild/common_utils.sh``.
115
116
117
118
119

*********************************
Standard build and test functions
*********************************

Andrew Murray's avatar
Andrew Murray committed
120
The standard build command is ``build_wheel``.  This is a bash function.  By
Matthew Brett's avatar
Matthew Brett committed
121
122
123
124
default the function that is run on OSX, and in the Manylinux container for
the build phase, is defined in ``multibuild/common_utils.sh``.  You can
override the default function in the project ``config.sh`` file (see below).

125
126
127
128
129
130
131
132
If you are building a wheel from pypi, rather than from a source repository,
you can use the ``build_index_wheel`` command, again defined in
``multibuild/common_utils.sh``.

Typically, you can get away with leaving the default ``build_wheel`` /
``build_index_wheel`` functions to do their thing, but you may need to define
a ``pre_build`` function in ``config.sh``.  The default ``build_wheel`` and
``build_index_wheel`` functions will call the ``pre_build`` function, if
133
134
135
defined, before building the wheel, so ``pre_build`` is a good place to build
any required libraries.

Matthew Brett's avatar
Matthew Brett committed
136
137
138
The standard test command is the bash function ``install_run``.  The version
run on OSX and in the Linux testing container is also defined in
``multibuild/common_utils.sh``.  Typically, you do not override this function,
139
140
141
142
but you in that case you will need to define a ``run_tests`` function, to run
your tests, returning a non-zero error code for failure.  The default
``install_run`` implementation calls the ``run_tests`` function, which you
will likely define in ``config.sh``.  See the examples below for examples of
Andrew Murray's avatar
Andrew Murray committed
143
less and more complicated builds, where the complicated builds override more
144
of the default implementations.
145
146
147
148

********************
To use these scripts
********************
Matthew Brett's avatar
Matthew Brett committed
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

* Make a repository for building wheels on travis-ci - e.g.
  https://github.com/MacPython/astropy-wheels - or in your case maybe
  ``https://github.com/your-org/your-project-wheels``;

* Add this (here) repository as a submodule::

    git submodule add https://github.com/matthew-brett/multibuild.git

* Add your own project repository as another submodule::

    git submodule add https://github.com/your-org/your-project.git

* Create a ``.travis.yml`` file, something like this::

    env:
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
        global:
            - REPO_DIR=your-project
            # Commit from your-project that you want to build
            - BUILD_COMMIT=v0.1.0
            # pip dependencies to _build_ your project
            - BUILD_DEPENDS="Cython numpy"
            # pip dependencies to _test_ your project.  Include any dependencies
            # that you need, that are also specified in BUILD_DEPENDS, this will be
            # a separate install.
            - TEST_DEPENDS="numpy scipy pytest"
            - PLAT=x86_64
            - UNICODE_WIDTH=32
            - WHEELHOUSE_UPLOADER_USERNAME=travis-worker
            # Following generated with
            # travis encrypt -r your-org/your-project-wheels WHEELHOUSE_UPLOADER_SECRET=<the api key>
            # This is for Rackspace uploads.  Contact Matthew Brett, or the
            # scikit-learn team, for # permission (and the API key) to upload to
            # the Rackspace account used here, or use your own account.
            - secure:
                "MNKyBWOzu7JAUmC0Y+JhPKfytXxY/ADRmUIMEWZV977FLZPgYctqd+lqel2QIFgdHDO1CIdTSymOOFZckM9ICUXg9Ta+8oBjSvAVWO1ahDcToRM2DLq66fKg+NKimd2OfK7x597h/QmUSl4k8XyvyyXgl5jOiLg/EJxNE2r83IA="
Matthew Brett's avatar
Matthew Brett committed
185
186

    language: python
187
188
    # The travis Python version is unrelated to the version we build and test
    # with.  This is set with the MB_PYTHON_VERSION variable.
189
    python: 3.5
Matthew Brett's avatar
Matthew Brett committed
190
191
192
193
    sudo: required
    dist: trusty
    services: docker

Matthew Brett's avatar
Matthew Brett committed
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
    matrix:
      exclude:
        # Exclude the default Python 3.5 build
        - python: 3.5
      include:
        - os: linux
          env: MB_PYTHON_VERSION=2.7
        - os: linux
          env:
            - MB_PYTHON_VERSION=2.7
            - UNICODE_WIDTH=16
        - os: linux
          env:
            - MB_PYTHON_VERSION=2.7
            - PLAT=i686
        - os: linux
          env:
            - MB_PYTHON_VERSION=2.7
            - PLAT=i686
            - UNICODE_WIDTH=16
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.3
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.3
            - PLAT=i686
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.4
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.4
            - PLAT=i686
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.5
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.5
            - PLAT=i686
riddell1's avatar
riddell1 committed
235
236
237
238
239
240
241
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.6
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.6
            - PLAT=i686
Matthew Brett's avatar
Matthew Brett committed
242
243
244
245
246
247
248
249
250
251
252
253
        - os: osx
          language: generic
          env:
            - MB_PYTHON_VERSION=2.7
        - os: osx
          language: generic
          env:
            - MB_PYTHON_VERSION=3.4
        - os: osx
          language: generic
          env:
            - MB_PYTHON_VERSION=3.5
riddell1's avatar
riddell1 committed
254
255
256
257
        - os: osx
          language: generic
          env:
            - MB_PYTHON_VERSION=3.6
Kyle Stewart's avatar
Kyle Stewart committed
258
259
260
        - os: osx
          language: generic
          env:
261
            - MB_PYTHON_VERSION=pypy-5.7
Matthew Brett's avatar
Matthew Brett committed
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

    before_install:
        - source multibuild/common_utils.sh
        - source multibuild/travis_steps.sh
        - before_install

    install:
        # Maybe get and clean and patch source
        - clean_code $REPO_DIR $BUILD_COMMIT
        - build_wheel $REPO_DIR $PLAT

    script:
        - install_run $PLAT

    after_success:
        # Upload wheels to Rackspace container
        - pip install wheelhouse-uploader
        # This uploads the wheels to a Rackspace container owned by the
        # scikit-learn team, available at http://wheels.scipy.org.  See above
        # for information on using this account or choosing another.
        - python -m wheelhouse_uploader upload --local-folder
            ${TRAVIS_BUILD_DIR}/wheelhouse/
            --no-update-index
            wheels

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
  The example above is for a project building from a git submodule.  If you
  aren't building from a submodule, but want to use ``pip`` to build from a
  source archive on https://pypi.org or similar, replace the first few lines
  of the ``.travis.yml`` file with something like::

    env:
        global:
            # Instead of REPO_DIR, BUILD_COMMIT
            - PROJECT_SPEC="tornado==4.1.1"

  then your ``install`` section could look something like this::

    install:
        - build_index_wheel $PROJECT_SPEC

Matthew Brett's avatar
Matthew Brett committed
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
* Next create a ``config.sh`` for your project, that fills in any steps you
  need to do before building the wheel (such as building required libraries).
  You also need this file to specify how to run your tests::

    # Define custom utilities
    # Test for OSX with [ -n "$IS_OSX" ]

    function pre_build {
        # Any stuff that you need to do before you start building the wheels
        # Runs in the root directory of this repository.
        :
    }

    function run_tests {
        # Runs tests on installed distribution from an empty directory
        python --version
        python -c 'import sys; import yourpackage; sys.exit(yourpackage.test())'
    }

321
322
  Optionally you can specify a different location for ``config.sh`` file with
  the ``$CONFIG_PATH`` environment variable.
323
324
325
326
327
328
329
330
  
* Optionally, create an ``env_vars.sh`` file to set defaults for any build
  environment variables used in ``library_builders.sh``. In Linux, they cannot
  be just set in the global environment because the build runs in Docker, so
  only the variables explicitly passed to ``docker run`` are propagated.
  
  Likewise, you can specify a different location for the file by setting the
  the ``$ENV_VARS_PATH`` environment variable.
331

Matthew Brett's avatar
Matthew Brett committed
332
333
* Make sure your project is set up to build on travis-ci, and you should now
  be ready (to begin the long slow debugging process, probably).
334
335
336
337
338
339
340
341
  
* For the Windows wheels, create an ``appveyor.yml`` file, something like:

  - https://github.com/MacPython/numpy-wheels/blob/master/appveyor.yml
  - https://github.com/MacPython/astropy-wheels/blob/master/appveyor.yml
  - https://github.com/MacPython/nipy-wheels/blob/master/appveyor.yml
  - https://github.com/MacPython/pytables-wheels/blob/master/appveyor.yml
  
342
343
344
  Note the Windows test customizations etc are inside ``appveyor.yml``,
  and that ``config.sh`` and ``env_vars.sh`` are only for the
  Linux/Mac builds on TravisCI.
345
346
347

* Make sure your project is set up to build on appveyor, and you should now
  be ready (for what could be another round of slow debugging).
Matthew Brett's avatar
Matthew Brett committed
348
349
350

If your project depends on numpy, you will want to build against the earliest
numpy that your project supports - see `forward, backward numpy compatibility
Andrew Murray's avatar
Andrew Murray committed
351
<https://stackoverflow.com/questions/17709641/valueerror-numpy-dtype-has-the-wrong-size-try-recompiling/18369312#18369312>`_.
Matthew Brett's avatar
Matthew Brett committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
See the `astropy-wheels travis file
<https://github.com/MacPython/astropy-wheels/blob/master/.travis.yml>`_ for an
example specifying numpy build and test dependencies.

Here are some simple example projects:

* https://github.com/MacPython/astropy-wheels
* https://github.com/scikit-image/scikit-image-wheels
* https://github.com/MacPython/nipy-wheels
* https://github.com/MacPython/dipy-wheels

Less simple projects where there are some serious build dependencies, and / or
OSX / Linux differences:

* https://github.com/MacPython/matplotlib-wheels
* https://github.com/python-pillow/Pillow-wheels
* https://github.com/MacPython/h5py-wheels
369
370
371
372
373
374
375
376

**********************
Multibuild development
**********************

The main multibuild repository is always at
https://github.com/matthew-brett/multibuild

377
378
We try to keep the ``master`` branch stable and do testing and development
in the ``devel`` branch.  From time to time we merge ``devel`` into ``master``.
379

380
381
In practice, you can check out the newest commit from ``devel`` that works
for you, then stay at it until you need newer features.