1- =================================================
2- Building Binary Wheels for Windows using Appveyor
3- =================================================
1+ =================================
2+ Supporting Windows using Appveyor
3+ =================================
44
55:Page Status: Incomplete
6- :Last Reviewed: 2014-09-27
6+ :Last Reviewed: 2015-12-03
77
88This section covers how to use the free `Appveyor `_ continuous integration
9- service to build Windows-targeted binary wheels for your project.
9+ service to provide Windows support for your project. This includes testing
10+ the code on Windows, and building Windows-targeted binaries for projects
11+ that use C extensions.
1012
1113.. contents :: Contents
1214 :local:
@@ -15,19 +17,23 @@ service to build Windows-targeted binary wheels for your project.
1517Background
1618==========
1719
18- Windows users typically do not have access to a C compiler, and therefore are
19- reliant on projects that use C extensions distributing binary wheels on PyPI in
20- order for the distribution to be installable via ``pip install dist ``.
21- However, it is often the case that projects which are intended to be
22- cross-platform are developed on Unix, and so the project developers *also * have
23- the problem of lack of access to a Windows compiler.
20+ Many projects are developed on Unix by default, and providing Windows support
21+ can be a challenge, because setting up a suitable Windows test environment is
22+ non-trivial, and may require buying software licenses.
2423
2524The Appveyor service is a continuous integration service, much like the
2625better-known `Travis `_ service that is commonly used for testing by projects
2726hosted on `Github `_. However, unlike Travis, the build workers on Appveyor are
2827Windows hosts and have the necessary compilers installed to build Python
2928extensions.
3029
30+ Windows users typically do not have access to a C compiler, and therefore are
31+ reliant on projects that use C extensions distributing binary wheels on PyPI in
32+ order for the distribution to be installable via ``pip install <dist> ``. By
33+ using Appveyor as a build service (even if not using it for testing) it is
34+ possible for projects without a dedicated Windows environment to provide
35+ Windows-targeted binaries.
36+
3137Setting Up
3238==========
3339
@@ -65,54 +71,59 @@ The ``appveyor.yml`` file must be located in the root directory of your
6571project. It is in ``YAML `` format, and consists of a number of sections.
6672
6773The ``environment `` section is the key to defining the Python versions for
68- which your wheels will be created. Appveyor comes with Python 2.7, 3.3 and 3.4
69- installed, in both 32-bit and 64-bit builds. The example file builds for all of
70- these environments.
71-
72- The ``install `` section installs any additional software that the project may
73- require. The supplied code installs ``pip `` (if needed) and ``wheel ``. Projects
74- may wish to customise this code in certain circumstances (for example, to install
75- additional build packages such as ``Cython ``, or test tools such as ``tox ``).
74+ which your wheels will be created. Appveyor comes with Python 2.6, 2.7, 3.3,
75+ 3.4 and 3.5 installed, in both 32-bit and 64-bit builds. The example file
76+ builds for all of these environments except Python 2.6. Installing for Python
77+ 2.6 is more complex, as it does not come with pip included. We don't support
78+ 2.6 in this document (as Windows users still using Python 2 are generally able
79+ to move to Python 2.7 without too much difficulty)
80+
81+ The ``install `` section uses pip to install any additional software that the
82+ project may require. The only requirement for building wheels is the ``wheel ``
83+ project, but projects may wish to customise this code in certain circumstances
84+ (for example, to install additional build packages such as ``Cython ``, or test
85+ tools such as ``tox ``).
7686
7787The ``build `` section simply switches off builds - there is no build step needed
7888for Python, unlike languages like ``C# ``.
7989
80- The ``test_script `` section is technically not needed. The supplied file runs
81- your test suite using ``setup.py test ``. You may wish to use another test tool
82- such as ``tox `` or ``py.test ``. Or you could skip the test (but why would you,
83- unless your tests are expected to fail on Windows?) by replacing the script with
84- a simple ``echo Skipped `` command.
90+ The main sections that will need to be tailored to your project are ``test_script ``
91+ and ``after_test ``.
8592
86- The ``after_test `` command is where the wheels are built. Assuming your project
87- uses the recommended tools (specifically, ``setuptools ``) then the
88- ``setup.py bdist_wheel `` command will build your wheels.
93+ The ``test_script `` section is where you will run your project's tests. The
94+ supplied file runs your test suite using ``setup.py test ``. If you are only
95+ interested in building wheels, and not in running your tests on Windows, you
96+ can replace this section with a dummy command such as ``echo Skipped Tests ``.
97+ You may wish to use another test tool, such as ``nose `` or ``py.test ``. Or you
98+ may wish to use a test driver like ``tox `` - however if you are using ``tox ``
99+ there are some additional configuration changes you will need to consider,
100+ which are described below.
101+
102+ The ``after_test `` runs once your tests have completed, and so is where the
103+ wheels should be built. Assuming your project uses the recommended tools
104+ (specifically, ``setuptools ``) then the ``setup.py bdist_wheel `` command
105+ will build your wheels.
89106
90107Note that wheels will only be built if your tests succeed. If you expect your
91108tests to fail on Windows, you can skip them as described above.
92109
93110
94- Support scripts
95- ---------------
111+ Support script
112+ --------------
96113
97- The ``appveyor.yml `` file relies on two support scripts. The code assumes that
98- these will be placed in a subdirectory named ``appveyor `` at the root of your
99- project.
114+ The ``appveyor.yml `` file relies on a single support script, which sets up the
115+ environment to use the SDK compiler for 64-bit builds on Python 3.3 and 3.4.
116+ For projects which do not need a compiler, or which don't support 3.3 or 3.4 on
117+ 64-bit Windows, only the ``appveyor.yml `` file is needed.
100118
101- `appveyor/run_with_compiler .cmd <https://raw.githubusercontent.com/pypa/python-packaging-user-guide/master/source/code/run_with_compiler .cmd >`__
119+ `build .cmd <https://raw.githubusercontent.com/pypa/python-packaging-user-guide/master/source/code/build .cmd >`__
102120is a Windows batch script that runs a single command in an environment with the
103- appropriate compiler for the selected Python version.
104-
105- `appveyor/install.ps1 <https://raw.githubusercontent.com/pypa/python-packaging-user-guide/master/source/code/install.ps1 >`__ is a Powershell
106- script that downloads and installs any missing Python versions, installs
107- ``pip `` into the Python ``site-packages `` and downloads and installs the latest
108- ``wheel `` distribution. Steps that are not needed are omitted, so in practice,
109- the Python install will never be run (it is present for advanced users who want
110- to install additional versions of Python not supplied by Appveyor) and the
111- ``pip `` install will be omitted for Python 3.4, where pip is installed as
112- standard.
121+ appropriate compiler for the selected Python version. All you need to do is to
122+ set the single environment variable ``DISTUTILS_USE_SDK `` to a value of ``1 ``
123+ and the script does the rest. It sets up the SDK needed for 64-bit builds of
124+ Python 3.3 or 3.4, so don't set the environment variable for any other builds.
113125
114- You can simply download these two files and include them in your project
115- unchanged.
126+ You can simply download the batch file and include it in your project unchanged.
116127
117128
118129Access to the built wheels
@@ -128,6 +139,57 @@ wheels and upload them to PyPI as part of your release process.
128139Additional Notes
129140================
130141
142+ Testing with tox
143+ ----------------
144+
145+ Many projects use the `Tox `_ tool to run their tests. It ensures that tests
146+ are run in an isolated environment using the exact files that will be distributed
147+ by the project.
148+
149+ In order to use ``tox `` on Appveyor there are a couple of additional considerations
150+ (in actual fact, these issues are not specific to Appveyor, and may well affect
151+ other CI systems).
152+
153+ 1. By default, ``tox `` only passes a chosen subset of environment variables to the
154+ test processes. Because ``distutils `` uses environment variables to control the
155+ compiler, this "test isolation" feature will cause the tests to use the wrong
156+ compiler by default.
157+
158+ To force ``tox `` to pass the necessary environment variables to the subprocess,
159+ you need to set the ``tox `` configuration option ``passenv `` to list the additional
160+ environment variables to be passed to the subprocess. For the SDK compilers, you
161+ need
162+
163+ - ``DISTUTILS_USE_SDK ``
164+ - ``MSSdk ``
165+ - ``INCLUDE ``
166+ - ``LIB ``
167+
168+ The ``passenv `` option can be set in your ``tox.ini ``, or if you prefer to avoid
169+ adding Windows-specific settings to your general project files, it can be set by
170+ setting the ``TOX_TESTENV_PASSENV `` environment variable. The supplied ``build.cmd ``
171+ script does this by default whenever ``DISTUTILS_USE_SDK `` is set.
172+
173+ 2. When used interactively, ``tox `` allows you to run your tests against multiple
174+ environments (often, this means multiple Python versions). This feature is not as
175+ useful in a CI environment like Travis or Appveyor, where all tests are run in
176+ isolated environments for each configuration. As a result, projects often supply
177+ an argument ``-e ENVNAME `` to ``tox `` to specify which environment to use (there
178+ are default environments for most versions of Python).
179+
180+ However, this does *not * work well with a Windows CI system like Appveyor, where
181+ there are (for example) two installations of Python 3.4 (32-bit and 64-bit)
182+ available, but only one ``py34 `` environment in ``tox ``.
183+
184+ In order to run tests using ``tox ``, therefore, projects should probably use the
185+ default ``py `` environment in ``tox ``, which uses the Python interpreter that
186+ was used to run ``tox ``. This will ensure that when Appveyor runs the tests, they
187+ will be run with the configured interpreter.
188+
189+ In order to support running under the ``py `` environment, it is possible that
190+ projects with complex ``tox `` configurations might need to modify their ``tox.ini ``
191+ file. Doing so is, however, outside the scope of this document.
192+
131193Automatically uploading wheels
132194------------------------------
133195
@@ -145,32 +207,28 @@ External dependencies
145207---------------------
146208
147209The supplied scripts will successfully build any distribution that does not
148- rely on 3rd party external libraries for the build. It would be possible for an
149- individual project to add code to the ``install.ps1 `` script to make external
150- libraries available to the build, but this is of necessity specific to
151- individual projects.
210+ rely on 3rd party external libraries for the build.
211+
212+ It is possible to add steps to the ``appveyor.yml `` configuration (typically
213+ in the "install" section) to download and/or build external libraries needed by
214+ the distribution. And if needed, it is possible to add extra configuration for
215+ the build to supply the location of these libraries to the compiler. However,
216+ this level of configuration is beyond the scope of this document.
152217
153- Should projects develop scripts showing how to do this, references will be
154- added to this guide at a later date.
155218
156219Support scripts
157220---------------
158221
159- For reference, the two support scripts are listed here:
222+ For reference, the SDK setup support script is listed here:
160223
161- ``code/run_with_compiler .cmd ``
224+ ``code/build .cmd ``
162225
163- .. literalinclude :: code/run_with_compiler .cmd
226+ .. literalinclude :: code/build .cmd
164227 :language: bat
165228 :linenos:
166229
167- ``code/install.ps1 ``
168-
169- .. literalinclude :: code/install.ps1
170- :language: powershell
171- :linenos:
172-
173230.. _Appveyor : http://www.appveyor.com/
174231.. _Travis : https://travis-ci.org/
175232.. _Github : https://github.org/
176233.. _Bitbucket : https://bitbucket.org/
234+ .. _Tox : http://tox.testrun.org
0 commit comments