Skip to content

Commit 857a261

Browse files
committed
[windows] Documentation: Add use case how to build a Python package
This aims to build Python wheels for PyTables in a DIY manner. It uses Microsoft Visual C++ Build Tools 2015 and Anaconda, both installed using Chocolatey, and `cibuildwheel`.
1 parent 33817da commit 857a261

File tree

4 files changed

+135
-2
lines changed

4 files changed

+135
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ in progress
2424
and ``RACKER_WDM_MACHINE``.
2525
- Add environment variable ``RACKER_WDM_PROVIDER`` to reconfigure the
2626
Vagrant virtualization backend differently than VirtualBox.
27+
- Documentation: Add use case how to build a Python package within a
28+
Windows environment, using Microsoft Visual C++ Build Tools 2015 and
29+
Anaconda, both installed using Chocolatey, and ``cibuildwheel``.
2730

2831

2932
2022-05-20 0.2.0

doc/use-cases/python-on-windows.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
###############################
2+
Use cases for Python on Windows
3+
###############################
4+
5+
6+
*************************
7+
Build wheels for PyTables
8+
*************************
9+
10+
DIY, without a hosted CI provider.
11+
12+
References
13+
==========
14+
15+
- https://github.com/PyTables/PyTables/pull/872#issuecomment-773535041
16+
- https://github.com/PyTables/PyTables/blob/master/.github/workflows/wheels.yml
17+
18+
Synopsis
19+
========
20+
21+
.. note::
22+
23+
The ``windows-pytables-wheel.sh`` program is part of this repository. You
24+
will only find it at the designated location when running ``racker`` from
25+
the working tree of its Git repository.
26+
27+
You still can get hold of the program and invoke it, by downloading it from
28+
`windows-pytables-wheel.sh`_.
29+
30+
So, let's start by defining the download URL to that file::
31+
32+
export PAYLOAD_URL=https://raw.githubusercontent.com/cicerops/racker/windows/doc/use-cases/windows-pytables-wheel.sh
33+
34+
Unattended::
35+
36+
time racker --verbose run --rm --platform=windows/amd64 python:3.9 -- \
37+
"sh -c 'wget ${PAYLOAD_URL}; sh -c windows-pytables-wheel.sh'"
38+
39+
Or, interactively::
40+
41+
racker --verbose run -it --rm --platform=windows/amd64 python:3.9 -- bash
42+
wget ${PAYLOAD_URL}
43+
sh -c windows-pytables-wheel.sh
44+
45+
46+
Future
47+
======
48+
49+
See https://github.com/cicerops/racker/issues/8.
50+
51+
When working on the code base, you can invoke the program directly from
52+
the repository, after the ``--volume`` option got implemented::
53+
54+
# Unattended.
55+
time racker --verbose run --rm \
56+
--volume=C:/Users/amo/dev/cicerops-foss/sources/postroj:C:/racker \
57+
--platform=windows/amd64 python:3.9 -- \
58+
sh -c /c/racker/doc/use-cases/windows-pytables-wheel.sh
59+
60+
# Interactively.
61+
racker --verbose run -it --rm \
62+
--volume=C:/Users/amo/dev/cicerops-foss/sources/postroj:C:/racker \
63+
--platform=windows/amd64 python:3.9 -- bash
64+
/c/racker/doc/use-cases/windows-pytables-wheel.sh
65+
66+
67+
.. _windows-pytables-wheel.sh: https://raw.githubusercontent.com/cicerops/racker/main/doc/use-cases/windows-pytables-wheel.sh
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
#
3+
# Build wheels for PyTables on Windows. DIY, without a hosted CI provider.
4+
# https://github.com/cicerops/racker/blob/main/doc/use-cases/python-on-windows.rst
5+
#
6+
# Synopsis::
7+
#
8+
# racker --verbose run -it --rm --platform=windows/amd64 python:3.9 -- bash
9+
# /c/racker/doc/use-cases/windows-pytables-wheel.sh
10+
#
11+
set -e
12+
13+
# Install prerequisites.
14+
15+
# Microsoft Visual C++ Build Tools 2015 14.0.25420.1
16+
# https://community.chocolatey.org/packages/microsoft-visual-cpp-build-tools
17+
choco install --yes microsoft-visual-cpp-build-tools --install-arguments="'/InstallSelectableItems Win81SDK_CppBuildSKUV1;VisualCppBuildTools_ATLMFC_SDK'"
18+
19+
# Miniconda - A minimal installer for Anaconda.
20+
# https://conda.io/miniconda.html
21+
# https://community.chocolatey.org/packages/miniconda3
22+
choco install --yes miniconda3 --package-parameters="'/AddToPath:1'"
23+
export PATH="$PATH:/c/Tools/miniconda3/condabin"
24+
export conda="conda.bat"
25+
26+
# cibuildwheel - Build Python wheels for all the platforms on CI with minimal configuration.
27+
# https://cibuildwheel.readthedocs.io/
28+
pip install --upgrade cibuildwheel
29+
30+
# Check prerequisites.
31+
echo $PATH
32+
$conda --version
33+
# cibuildwheel --version
34+
35+
36+
# Acquire sources.
37+
mkdir -p /c/src
38+
cd /c/src
39+
test ! -d PyTables && git clone https://github.com/PyTables/PyTables --recursive --depth=1
40+
cd PyTables
41+
42+
# Pretend to be on a build matrix.
43+
export MATRIX_ARCH=win_amd64 # win32
44+
export MATRIX_ARCH_SUBDIR=win-64 # win-32
45+
46+
47+
# Configure cibuildwheel.
48+
export CIBW_BUILD="cp36-${MATRIX_ARCH} cp37-${MATRIX_ARCH} cp38-${MATRIX_ARCH} cp39-${MATRIX_ARCH} cp310-${MATRIX_ARCH}"
49+
export CIBW_BEFORE_ALL_WINDOWS="$conda create --yes --name=build && $conda activate build && $conda config --env --set subdir ${MATRIX_ARCH_SUBDIR} && $conda install --yes blosc bzip2 hdf5 lz4 lzo snappy zstd zlib"
50+
export CIBW_ENVIRONMENT_WINDOWS='CONDA_PREFIX="C:\\Miniconda\\envs\\build" PATH="$PATH;C:\\Miniconda\\envs\\build\\Library\\bin"'
51+
export CIBW_ENVIRONMENT="PYTABLES_NO_EMBEDDED_LIBS=true DISABLE_AVX2=true"
52+
export CIBW_BEFORE_BUILD="pip install -r requirements.txt cython>=0.29.21 delvewheel"
53+
export CIBW_REPAIR_WHEEL_COMMAND_WINDOWS="delvewheel repair -w {dest_dir} {wheel}"
54+
55+
# Debugging.
56+
# env
57+
58+
# Build wheel.
59+
cibuildwheel --platform=windows --output-dir=wheelhouse

postroj/winrunner.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ def run(self, command, interactive: bool = False, tty: bool = False):
189189
if interactive or tty:
190190
option_interactive = "-it"
191191

192-
# TODO: Propagate ``--rm`` appropriately.
193-
command = f"docker --context={self.wdm_machine} run {option_interactive} --rm {self.image_real} {command}"
192+
# TODO: Propagate ``--rm`` option appropriately.
193+
# TODO: Propagate ``--volume`` option.
194+
# option_volume = "--volume=C:/Users/amo/dev/cicerops-foss/sources/postroj:C:/racker"
195+
# https://github.com/cicerops/racker/issues/8
196+
option_volume = ""
197+
command = f"docker --context={self.wdm_machine} run {option_interactive} --rm {option_volume} {self.image_real} {command}"
194198

195199
# When an interactive prompt is requested, spawn a shell without further ado.
196200
if interactive or tty:

0 commit comments

Comments
 (0)