Using AppVeyor to distribute Python wheels
2014-09-21 ⋅AppVeyor uses a simple configuration file that uses YAML. Here is what the config file for your project might look like:
install:
- ps: (new-object net.webclient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'C:/get-pip.py')
- C:/Python34/python.exe C:/get-pip.py
- C:/Python34/Scripts/pip.exe install wheel
build_script:
- python setup.py build
test_script:
- C:/Python34/Scripts/py.test
deploy_script:
- python setup.py sdist bdist_wheel upload
It goes into a file named appveyor.yml. Here's what's going on, one piece at a time:
install:
The install section defines commands to run for installation.
- ps: (new-object net.webclient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'C:/get-pip.py')
- C:/Python34/python.exe C:/get-pip.py
These two lines install pip. The first uses PowerShell to download the install script; the second runs it.
- C:/Python34/Scripts/pip.exe install wheel
- C:/Python34/Scripts/pip.exe install pytest
The first line installs wheel. The second is optional; it just installs pytest (a unit testing framework). I put it here as an example of installing other packages with pip.
build_script:
- C:/Python34/python.exe setup.py build
The commands to build your Python project go here.
test_script:
- C:/Python34/Scripts/py.test
Whatever you do to run your project tests go here.
deploy_script:
- python setup.py sdist bdist_wheel upload
This is the magic part; it runs bdist_wheel and uploads the result.
That's it! Pretty simple, no? Now, you can build Windows binary wheels easily.
EDIT: Someone pointed out in the comments that I completely ignored PyPI authentication. Luckily, it's a simple addition.
-
Now, add this to the end of appveyor.yml:
environment: password: secure:
replacing
value
with the value you copied from the Encrypt Data page. Then, change the deploy_script part to read this:deploy_script: - "echo [pypi] > %USERPROFILE%\\.pypirc" - "echo username: user >> %USERPROFILE%\\.pypirc" - "echo password: %password% >> %USERPROFILE%\\.pypirc" - python setup.py sdist bdist_wheel upload