Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Use a minimal Windows Docker container to check the wheels #18802

Merged
merged 124 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
2ac1985
[WIP] MNT Use a minimal Windows Docker container to check the wheels
alfaro96 Nov 9, 2020
32cb163
MNT Add step
alfaro96 Nov 9, 2020
7de7338
MNT Use ubuntu-latest instead of windows-latest
alfaro96 Nov 9, 2020
c18f683
MNT Pull Windows docker image
alfaro96 Nov 9, 2020
f77163a
MNT Run Windows Docker container
alfaro96 Nov 9, 2020
b6f790e
MNT Run powershell
alfaro96 Nov 9, 2020
95dc1ce
MNT Download and install Python
alfaro96 Nov 9, 2020
4f91487
MNT Build custom Docker image
alfaro96 Nov 9, 2020
64979e8
FIX Specify command with CMD
alfaro96 Nov 9, 2020
53f5c19
FIX Properly specify the base Docker image
alfaro96 Nov 9, 2020
a3ad94c
FIX Specify Python version at build time
alfaro96 Nov 9, 2020
541df1b
FIX Specify Python version at build time
alfaro96 Nov 9, 2020
02b97b1
FIX Specify Python version at build time
alfaro96 Nov 9, 2020
56cef2a
FIX Specify Python version at build time
alfaro96 Nov 9, 2020
d9351f1
FIX Specify Python version at build time
alfaro96 Nov 9, 2020
bbb66cb
FIX Specify Python version at build time
alfaro96 Nov 9, 2020
2581b10
MNT Use Windows container to test the wheel
alfaro96 Nov 9, 2020
340153f
MNT Minor changes
alfaro96 Nov 9, 2020
21cef7e
MNT Minor changes
alfaro96 Nov 9, 2020
e3e3459
MNT Minor changes
alfaro96 Nov 9, 2020
1e08883
MNT Minor changes
alfaro96 Nov 10, 2020
e05fa34
MNT Put all together [cd build]
alfaro96 Nov 10, 2020
f842bc2
MNT Exchange RUN by CMD [cd build]
alfaro96 Nov 10, 2020
826343c
MNT Revert temporary changes [cd build]
alfaro96 Nov 10, 2020
9d567cd
MNT Trigger build [cd build]
alfaro96 Nov 10, 2020
b3d51eb
MNT Debug [cd build]
alfaro96 Nov 10, 2020
7130e40
MNT Debug [cd build]
alfaro96 Nov 10, 2020
553c00a
MNT Revert temporary changes [cd build]
alfaro96 Nov 10, 2020
5aec640
MNT Debug [cd build]
alfaro96 Nov 10, 2020
8897727
MNT Revert temporary changes [cd build]
alfaro96 Nov 10, 2020
9f9ca8b
Merge remote-tracking branch 'upstream/master' into minimal_windows_c…
alfaro96 Nov 13, 2020
9096658
MNT Integrate minimal Windows Docker container in the tests [cd build]
alfaro96 Nov 13, 2020
2732968
MNT Add missing character [cd build]
alfaro96 Nov 13, 2020
65c67d8
MNT Minor changes [cd build]
alfaro96 Nov 13, 2020
b3de81b
MNT Minor changes [cd build]
alfaro96 Nov 13, 2020
b453412
MNT Minor changes [cd build]
alfaro96 Nov 13, 2020
db05784
MNT Minor changes [cd build]
alfaro96 Nov 13, 2020
4a60ca5
MNT Minor changes [cd build]
alfaro96 Nov 13, 2020
c0e9b82
MNT Find the repaired wheel [cd build]
alfaro96 Nov 13, 2020
7ed2af7
Merge remote-tracking branch 'upstream/master' into minimal_windows_c…
alfaro96 Nov 13, 2020
c5e45fa
MNT Find the repaired wheel [cd build]
alfaro96 Nov 13, 2020
65e741b
MNT Find the repaired wheel [cd build]
alfaro96 Nov 13, 2020
8b3fd91
MNT Find the repaired wheel [cd build]
alfaro96 Nov 13, 2020
0e9b6a1
MNT Refactor code [cd build]
alfaro96 Nov 13, 2020
d01802d
MNT Debug [cd build]
alfaro96 Nov 13, 2020
2b174df
MNT Debug [cd build]
alfaro96 Nov 13, 2020
0fdb595
MNT Debug [cd build]
alfaro96 Nov 13, 2020
24cc152
MNT Explictly specify the test command for Windows [cd build]
alfaro96 Nov 13, 2020
47fe8e4
MNT Explictly specify the test command for Windows [cd build]
alfaro96 Nov 13, 2020
808190d
MNT Properly specify the CMD command [cd build]
alfaro96 Nov 13, 2020
b5fc3c7
MNT Properly specify the CMD command [cd build]
alfaro96 Nov 13, 2020
00cc7cb
MNT Trigger build [cd build]
alfaro96 Nov 13, 2020
b51e6e2
MNT Properly specify the build arguments [cd build]
alfaro96 Nov 13, 2020
2d49356
MNT Properly specify the build arguments [cd build]
alfaro96 Nov 13, 2020
cae1698
MNT Properly specify the build arguments [cd build]
alfaro96 Nov 13, 2020
0e06085
MNT Copy file before building image [cd build]
alfaro96 Nov 14, 2020
23cdf94
MNT Minor changes [cd build]
alfaro96 Nov 14, 2020
7353f75
MNT Minor changes [cd build]
alfaro96 Nov 14, 2020
426cc42
FIX Fix Docker image name [cd build]
alfaro96 Nov 14, 2020
995ef49
FIX Fix Dockerfile CMD command [cd build]
alfaro96 Nov 14, 2020
c4a4083
FIX Fix Dockerfile CMD command [cd build]
alfaro96 Nov 14, 2020
911d1e5
FIX Fix Dockerfile CMD command [cd build]
alfaro96 Nov 14, 2020
2154065
FIX Skip network tests [cd build]
alfaro96 Nov 14, 2020
00073de
FIX Fix network tests [cd build]
alfaro96 Nov 15, 2020
b05c2f3
Revert [cd build]
alfaro96 Nov 15, 2020
85e4b8d
Minor changes [cd build]
alfaro96 Nov 16, 2020
7dce6d9
MNT Solve certificate issue [cd build]
alfaro96 Nov 16, 2020
5f2554e
Revert [cd build]
alfaro96 Nov 16, 2020
06757fb
Update build_tools/github/build_minimal_windows_image.sh
alfaro96 Nov 16, 2020
06b5859
Set rest of environment variables [cd build]
alfaro96 Nov 16, 2020
1e8d618
Merge branch 'minimal_windows_container' of github.com:alfaro96/sciki…
alfaro96 Nov 16, 2020
cd8d57b
CLN Apply suggested changes [cd build]
alfaro96 Nov 16, 2020
e4c8c2d
MNT Run command with Powershell [cd build]
alfaro96 Nov 16, 2020
c6635d8
MNT Embed msvcp140.dll [cd build]
alfaro96 Nov 16, 2020
7f1e089
MNT Embed msvcp140.dll [cd build]
alfaro96 Nov 16, 2020
2314b94
MNT Embed msvcp140.dll [cd build]
alfaro96 Nov 16, 2020
9e86aca
MNT Embed msvcp140.dll [cd build]
alfaro96 Nov 16, 2020
e2fdff6
MNT Use powershell [cd build]
alfaro96 Nov 16, 2020
d380061
MNT Vendor VCRUNTIME140.dll [cd build]
alfaro96 Nov 16, 2020
53845e2
FIX Fix path [cd build]
alfaro96 Nov 16, 2020
7fbbfb1
FIX Fix path [cd build]
alfaro96 Nov 16, 2020
82ab495
FIX Vendor only VCRUNTIME140.dll [cd build]
alfaro96 Nov 16, 2020
9878e43
FIX Fix linting errors [cd build]
alfaro96 Nov 16, 2020
ac3c390
MNT Properly vendor the DLL for each architecture [cd build]
alfaro96 Nov 16, 2020
f059e8b
Skip @pytest.mark.network tests when SKLEARN_SKIP_NETWORK_TESTS=1
ogrisel Nov 17, 2020
ae4f583
[cd build]
ogrisel Nov 17, 2020
250f2e4
FIX Fix find random failures
alfaro96 Nov 17, 2020
08fe6b2
[cd build]
alfaro96 Nov 17, 2020
5543046
[cd build]
alfaro96 Nov 17, 2020
49c4e52
Debug [cd build]
alfaro96 Nov 17, 2020
47aea85
FIX ignore missing folders with find
ogrisel Nov 17, 2020
5326e5e
[cd build]
ogrisel Nov 17, 2020
75dbe4a
MNT Set the environment variable in docker exec [cd build]
alfaro96 Nov 17, 2020
03268e2
MNT Set the environment variable in docker exec [cd build]
alfaro96 Nov 17, 2020
f52cf3a
MNT Set the environment variable in docker exec [cd build]
alfaro96 Nov 17, 2020
e5e1709
MNT Set the environment variable in docker run [cd build]
alfaro96 Nov 17, 2020
1881b08
MNT Set the environment variable using docker exec [cd build]
alfaro96 Nov 17, 2020
6defb5b
MNT Escape $ [cd build]
alfaro96 Nov 17, 2020
5c97b14
CLN Apply suggested changes [cd build]
alfaro96 Nov 17, 2020
4da3fee
CLN Apply suggested changes [cd build]
alfaro96 Nov 17, 2020
79b7b4b
Debug [cd build]
alfaro96 Nov 17, 2020
1a80e45
Debug [cd build]
alfaro96 Nov 17, 2020
507c5db
MNT Copy conftest.py [cd build]
alfaro96 Nov 18, 2020
39eb109
MNT Fix linting issues [cd build]
alfaro96 Nov 18, 2020
acc7548
MNT Fix cp issues [cd build]
alfaro96 Nov 18, 2020
0468e1b
MNT Fix remaining failure and ready to merge [cd build]
alfaro96 Nov 18, 2020
3a428bb
MNT Fix remaining failure and ready to merge [cd build]
alfaro96 Nov 18, 2020
04c7ee6
MNT Fix remaining failure and ready to merge [cd build]
alfaro96 Nov 18, 2020
be484f6
MNT Fix remaining failure and ready to merge [cd build]
alfaro96 Nov 18, 2020
2e2c30a
MNT Final nitpicks [cd build]
alfaro96 Nov 18, 2020
cd935c2
CLN Apply suggested changes [cd build]
alfaro96 Nov 18, 2020
b9f95dd
CLN Apply suggested changes [cd build]
alfaro96 Nov 18, 2020
8d1a247
MNT Minor changes [cd build]
alfaro96 Nov 18, 2020
2a7e8fc
Run source distribu tests from a sibling folder [cd build]
ogrisel Nov 18, 2020
78a5e9b
MNT Remove SKLEARN_SKIP_NETWORK_TESTS from sdist [cd build]
alfaro96 Nov 18, 2020
7ceb442
Merge branch 'minimal_windows_container' of github.com:alfaro96/sciki…
alfaro96 Nov 18, 2020
67b9970
[cd build]
alfaro96 Nov 18, 2020
17c4a62
MNT Revert [cd build]
alfaro96 Nov 18, 2020
c2cb3e0
CLN Apply suggested changes [cd build]
alfaro96 Nov 18, 2020
e477e74
CLN Apply suggested changes [cd build]
alfaro96 Nov 18, 2020
94ec15c
MNT Remove conftest.py copy [cd build]
alfaro96 Nov 18, 2020
6ece922
MNT Move up two levels [cd build]
alfaro96 Nov 18, 2020
a4c9cf8
MNT Move up two levels [cd build]
alfaro96 Nov 18, 2020
60ebf91
MNT Copy conftest.py [cd build]
alfaro96 Nov 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,19 @@ jobs:

- name: Build and test wheels
env:
# Set the directory where the wheel is unpacked
CONFTEST_PATH: ${{ github.workspace }}/conftest.py
CONFTEST_NAME: conftest.py
CIBW_ENVIRONMENT: WHEEL_DIRNAME=scikit_learn-$SCIKIT_LEARN_VERSION
OMP_NUM_THREADS=2
OPENBLAS_NUM_THREADS=2
SKLEARN_SKIP_NETWORK_TESTS=1
SKLEARN_BUILD_PARALLEL=3
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: bash build_tools/github/repair_windows_wheels.sh {wheel} {dest_dir} ${{ matrix.bitness }}
CIBW_BEFORE_TEST_WINDOWS: bash build_tools/github/build_minimal_windows_image.sh ${{ matrix.python }} ${{ matrix.bitness }}
CIBW_TEST_REQUIRES: pytest pandas threadpoolctl
# Test that there are no links to system libraries
CIBW_TEST_COMMAND: pytest --pyargs sklearn &&
python -m threadpoolctl -i sklearn
# By default, the Windows wheels are not repaired.
# In this case, we need to vendor the vcomp140.dll
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: wheel unpack {wheel} &&
python build_tools/github/vendor_vcomp140.py %WHEEL_DIRNAME% &&
wheel pack %WHEEL_DIRNAME% -d {dest_dir} &&
rmdir /s /q %WHEEL_DIRNAME%
CIBW_TEST_COMMAND: bash {project}/build_tools/github/test_wheels.sh
CIBW_TEST_COMMAND_WINDOWS: bash {project}/build_tools/github/test_windows_wheels.sh ${{ matrix.python }} ${{ matrix.bitness }}

run: bash build_tools/github/build_wheels.sh

Expand All @@ -117,8 +113,17 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2

- name: Build and test source distribution
- name: Build source distribution
run: bash build_tools/github/build_source.sh
env:
SKLEARN_BUILD_PARALLEL: 3

- name: Test source distribution
run: bash build_tools/github/test_source.sh
env:
OMP_NUM_THREADS: 2
OPENBLAS_NUM_THREADS: 2
SKLEARN_SKIP_NETWORK_TESTS: 1

- name: Store artifacts
uses: actions/upload-artifact@v2
Expand All @@ -130,7 +135,7 @@ jobs:
name: Upload to Anaconda
runs-on: ubuntu-latest
needs: [build_wheels, build_sdist]
# The artifacts are not be uploaded on PRs
# The artifacts cannot be uploaded on PRs
if: github.event_name != 'pull_request'

steps:
Expand Down
15 changes: 15 additions & 0 deletions build_tools/github/Windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Get the Python version of the base image from a build argument
ARG PYTHON_VERSION
FROM winamd64/python:$PYTHON_VERSION-windowsservercore

ARG WHEEL_NAME
ARG CONFTEST_NAME
ARG CIBW_TEST_REQUIRES

# Copy and install the Windows wheel
COPY $WHEEL_NAME $WHEEL_NAME
COPY $CONFTEST_NAME $CONFTEST_NAME
RUN pip install $env:WHEEL_NAME

# Install the testing dependencies
RUN pip install $env:CIBW_TEST_REQUIRES.split(" ")
31 changes: 31 additions & 0 deletions build_tools/github/build_minimal_windows_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e
set -x

PYTHON_VERSION=$1
BITNESS=$2

if [[ "$PYTHON_VERSION" == "36" || "$BITNESS" == "32" ]]; then
# Python 3.6 and 32-bit architectures are not supported
# by the official Docker images: Tests will just be run
# on the host (instead of the minimal Docker container).
exit 0
fi

TEMP_FOLDER="$HOME/AppData/Local/Temp"
WHEEL_PATH=$(ls -d $TEMP_FOLDER/*/repaired_wheel/*)
WHEEL_NAME=$(basename $WHEEL_PATH)

cp $WHEEL_PATH $WHEEL_NAME

# Dot the Python version for identyfing the base Docker image
PYTHON_VERSION=$(echo ${PYTHON_VERSION:0:1}.${PYTHON_VERSION:1:2})
ogrisel marked this conversation as resolved.
Show resolved Hide resolved

# Build a minimal Windows Docker image for testing the wheels
docker build --build-arg PYTHON_VERSION=$PYTHON_VERSION \
--build-arg WHEEL_NAME=$WHEEL_NAME \
--build-arg CONFTEST_NAME=$CONFTEST_NAME \
--build-arg CIBW_TEST_REQUIRES="$CIBW_TEST_REQUIRES" \
-f build_tools/github/Windows \
-t scikit-learn/minimal-windows .
13 changes: 8 additions & 5 deletions build_tools/github/build_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
set -e
set -x

# Move up two levels to create the virtual
# environment outside of the source folder
cd ../../

python -m venv build_env
source build_env/bin/activate

python -m pip install numpy scipy cython
python -m pip install twine
python -m pip install pytest pandas

cd scikit-learn/scikit-learn
python setup.py sdist
python -m pip install dist/*.tar.gz
python setup.py build_ext -i

pytest --pyargs sklearn

# Check whether the source distribution will render correctly
twine check dist/*.tar.gz
2 changes: 1 addition & 1 deletion build_tools/github/build_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
set -x

# OpenMP is not present on macOS by default
if [ "$RUNNER_OS" == "macOS" ]; then
if [[ "$RUNNER_OS" == "macOS" ]]; then
brew install libomp
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
Expand Down
15 changes: 15 additions & 0 deletions build_tools/github/repair_windows_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e
set -x

WHEEL=$1
DEST_DIR=$2
BITNESS=$3

# By default, the Windows wheels are not repaired.
# In this case, we need to vendor VCRUNTIME140.dll
wheel unpack "$WHEEL"
python build_tools/github/vendor.py "$WHEEL_DIRNAME" "$BITNESS"
wheel pack "$WHEEL_DIRNAME" -d "$DEST_DIR"
rm -rf "$WHEEL_DIRNAME"
19 changes: 19 additions & 0 deletions build_tools/github/test_source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e
set -x

cd ../../

python -m venv test_env
source test_env/bin/activate

python -m pip install scikit-learn/scikit-learn/dist/*.tar.gz
python -m pip install pytest pandas

# Run the tests on the installed source distribution
mkdir tmp_for_test
cp scikit-learn/scikit-learn/conftest.py tmp_for_test
cd tmp_for_test

pytest --pyargs sklearn
alfaro96 marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions build_tools/github/test_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e
set -x

if [[ "$OSTYPE" != "linux-gnu" ]]; then
# The Linux test environment is run in a Docker container and
# it is not possible to copy the test configuration file (yet)
alfaro96 marked this conversation as resolved.
Show resolved Hide resolved
cp $CONFTEST_PATH $CONFTEST_NAME
alfaro96 marked this conversation as resolved.
Show resolved Hide resolved
fi

pytest --pyargs sklearn

# Test that there are no links to system libraries
python -m threadpoolctl -i sklearn
24 changes: 24 additions & 0 deletions build_tools/github/test_windows_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e
set -x

PYTHON_VERSION=$1
BITNESS=$2

if [[ "$PYTHON_VERSION" == "36" || "$BITNESS" == "32" ]]; then
# For Python 3.6 and 32-bit architecture use the regular
# test command (outside of the minimal Docker container)
cp $CONFTEST_PATH $CONFTEST_NAME
alfaro96 marked this conversation as resolved.
Show resolved Hide resolved
pytest --pyargs sklearn
python -m threadpoolctl -i sklearn
else
docker container run -e SKLEARN_SKIP_NETWORK_TESTS=1 \
-e OMP_NUM_THREADS=2 \
-e OPENBLAS_NUM_THREADS=2 \
--rm scikit-learn/minimal-windows \
powershell -Command "pytest --pyargs sklearn"

docker container run --rm scikit-learn/minimal-windows \
powershell -Command "python -m threadpoolctl -i sklearn"
fi
148 changes: 148 additions & 0 deletions build_tools/github/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""Embed vcomp140.dll, vcruntime140.dll and vcruntime140_1.dll.

Note that vcruntime140_1.dll is only required (and available)
for 64-bit architectures.
"""


import os
import os.path as op
import shutil
import sys
import textwrap


TARGET_FOLDER = op.join("sklearn", ".libs")
DISTRIBUTOR_INIT = op.join("sklearn", "_distributor_init.py")
VCOMP140_SRC_PATH = "C:\\Windows\\System32\\vcomp140.dll"
VCRUNTIME140_SRC_PATH = "C:\\Windows\\System32\\vcruntime140.dll"
VCRUNTIME140_1_SRC_PATH = "C:\\Windows\\System32\\vcruntime140_1.dll"


def make_distributor_init_32_bits(distributor_init,
vcomp140_dll_filename,
vcruntime140_dll_filename):
"""Create a _distributor_init.py file for 32-bit architectures.

This file is imported first when importing the sklearn package
so as to pre-load the vendored vcomp140.dll and vcruntime140.dll.
"""
with open(distributor_init, "wt") as f:
f.write(textwrap.dedent("""
'''Helper to preload vcomp140.dll and vcruntime140.dll to
prevent "not found" errors.

Once vcomp140.dll and vcruntime140.dll are preloaded, the
namespace is made available to any subsequent vcomp140.dll
and vcruntime140.dll. This is created as part of the scripts
that build the wheel.
'''


import os
import os.path as op
from ctypes import WinDLL


if os.name == "nt":
# Load vcomp140.dll and vcruntime140.dll
libs_path = op.join(op.dirname(__file__), ".libs")
vcomp140_dll_filename = op.join(libs_path, "{0}")
vcruntime140_dll_filename = op.join(libs_path, "{1}")
WinDLL(op.abspath(vcomp140_dll_filename))
WinDLL(op.abspath(vcruntime140_dll_filename))
""".format(vcomp140_dll_filename, vcruntime140_dll_filename)))


def make_distributor_init_64_bits(distributor_init,
vcomp140_dll_filename,
vcruntime140_dll_filename,
vcruntime140_1_dll_filename):
"""Create a _distributor_init.py file for 64-bit architectures.

This file is imported first when importing the sklearn package
so as to pre-load the vendored vcomp140.dll, vcruntime140.dll
and vcruntime140_1.dll.
"""
with open(distributor_init, "wt") as f:
f.write(textwrap.dedent("""
'''Helper to preload vcomp140.dll, vcruntime140.dll and
vcruntime140_1.dll to prevent "not found" errors.

Once vcomp140.dll, vcruntime140.dll and vcruntime140_1.dll are
preloaded, the namespace is made available to any subsequent
vcomp140.dll, vcruntime140.dll and vcruntime140_1.dll. This is
created as part of the scripts that build the wheel.
'''


import os
import os.path as op
from ctypes import WinDLL


if os.name == "nt":
# Load vcomp140.dll, vcruntime140.dll and vcruntime140_1.dll
libs_path = op.join(op.dirname(__file__), ".libs")
vcomp140_dll_filename = op.join(libs_path, "{0}")
vcruntime140_dll_filename = op.join(libs_path, "{1}")
vcruntime140_1_dll_filename = op.join(libs_path, "{2}")
WinDLL(op.abspath(vcomp140_dll_filename))
WinDLL(op.abspath(vcruntime140_dll_filename))
WinDLL(op.abspath(vcruntime140_1_dll_filename))
""".format(vcomp140_dll_filename,
vcruntime140_dll_filename,
vcruntime140_1_dll_filename)))


def main(wheel_dirname, bitness):
"""Embed vcomp140.dll, vcruntime140.dll and vcruntime140_1.dll."""
if not op.exists(VCOMP140_SRC_PATH):
raise ValueError(f"Could not find {VCOMP140_SRC_PATH}.")

if not op.exists(VCRUNTIME140_SRC_PATH):
raise ValueError(f"Could not find {VCRUNTIME140_SRC_PATH}.")

if not op.exists(VCRUNTIME140_1_SRC_PATH) and bitness == "64":
raise ValueError(f"Could not find {VCRUNTIME140_1_SRC_PATH}.")

if not op.isdir(wheel_dirname):
raise RuntimeError(f"Could not find {wheel_dirname} file.")

vcomp140_dll_filename = op.basename(VCOMP140_SRC_PATH)
vcruntime140_dll_filename = op.basename(VCRUNTIME140_SRC_PATH)
vcruntime140_1_dll_filename = op.basename(VCRUNTIME140_1_SRC_PATH)

target_folder = op.join(wheel_dirname, TARGET_FOLDER)
distributor_init = op.join(wheel_dirname, DISTRIBUTOR_INIT)

# Create the "sklearn/.libs" subfolder
if not op.exists(target_folder):
os.mkdir(target_folder)

print(f"Copying {VCOMP140_SRC_PATH} to {target_folder}.")
shutil.copy2(VCOMP140_SRC_PATH, target_folder)

print(f"Copying {VCRUNTIME140_SRC_PATH} to {target_folder}.")
shutil.copy2(VCRUNTIME140_SRC_PATH, target_folder)

if bitness == "64":
print(f"Copying {VCRUNTIME140_1_SRC_PATH} to {target_folder}.")
shutil.copy2(VCRUNTIME140_1_SRC_PATH, target_folder)

# Generate the _distributor_init file in the source tree
print("Generating the '_distributor_init.py' file.")
if bitness == "32":
make_distributor_init_32_bits(distributor_init,
vcomp140_dll_filename,
vcruntime140_dll_filename)
else:
make_distributor_init_64_bits(distributor_init,
vcomp140_dll_filename,
vcruntime140_dll_filename,
vcruntime140_1_dll_filename)


if __name__ == "__main__":
_, wheel_file, bitness = sys.argv
main(wheel_file, bitness)
Loading