Page MenuHome

Python: script for packing bpy module as wheel
ClosedPublic

Authored by Brecht Van Lommel (brecht) on Sep 13 2022, 4:24 PM.

Details

Summary

The buildbot will call this script to create a binary .whl file that can be
easily installed through pip.

This includes some additional changes that will be committed separately, but
are included here for easy testing:

  • Make Blender version parsing from make_source_archive.py reusable.
  • Put PYTHON_VERSION in CMakeCache.txt for Windows so it can be read by script.
  • Use Windows Python executable in lib folder for running tests since module build does not install it.
  • Always make MSVC_REDIST_DIR available for oneAPI build.

Diff Detail

Repository
rB Blender
Branch
arcpatch-D15957 (branched from master)
Build Status
Buildable 23764
Build 23764: arc lint + arc unit

Event Timeline

Remove branch name, not used

I added basic support on the buildbot for building the bpy module, available as an option for patch and branch builds.

Example run:
https://builder-uatest.blender.org/admin/#/builders/169/builds/12
https://builder-uatest.blender.org/download/patch/

Linux and Windows are failing, tests are failing, the package name is wrong, etc. But maybe all of that is fixable with just changes to the Blender repository.

Attempt to fix gtest and oneAPI related errors.

This is an update to the script that extracts the Python & Blender version P3190.

Some of the utility functions could be moved into make_utils.py.

build_files/cmake/platform/platform_win32_bundle_crt.cmake
16

*picky* no indentation.

build_files/utils/make_bpy_wheel.py
36–42

@Stephen Imhoff (Clockwork-Muse) mentioned the Python version not included, based on https://peps.python.org/pep-0440/ I think this should include: python_requires="==3.10.*".

I'm not sure what the best way would be to access the Python version. If inspecting the resulting build isn't practical - it could be read from CMakeCache.txt.

  • Incorporate changes from Campbell
  • Try to set appropriate platform and ABI tag
  • Mark as binary package
  • Deduplicate blender version parsing
Brecht Van Lommel (brecht) requested review of this revision.Sep 14 2022, 9:33 PM

Removed draft status because otherwise I don't get notified about comments, even though this is not ready yet.

Suggesting some further changes, although additional meta-data can be handled once in master too.

  • *picky* (stick to one style of quote), better do here to avoid noise in master (maybe best use " to stick to Blender's Python code style).
  • Failure could use sys.exit(1) instead of early returns, so automation can detect failure.
  • Additional meta-data (not so urgent but should probably include at minimum "License": license='GPL-3.0'), see: https://github.com/TylerGubala/blenderpy/blob/master/setup.py for other possible inclusions.

Address comments.

Attempt to fix buildbot packaging where install and build dir are different.

Fix wrong leading zeros in macOS version number

Campbell Barton (campbellbarton) added inline comments.
build_files/utils/make_bpy_wheel.py
151

*picky* quotes.

This revision is now accepted and ready to land.Sep 15 2022, 3:47 AM

Fix for Windows install path and old CentOS Python

More hacking to try to get builds to pass

Fully disable incompatible gtests, fix Windows test Python executable path

Brecht Van Lommel (brecht) retitled this revision from Python: script for packing bpy module as wheel [WIP] to Python: script for packing bpy module as wheel.Sep 15 2022, 1:07 PM
Brecht Van Lommel (brecht) edited the summary of this revision. (Show Details)

Builds passing now, except some unit tests on Windows. Close enough to merge this I think.
https://builder-uatest.blender.org/admin/#/builders/169/builds/23

I added @Ray Molenkamp (LazyDodo) as reviewer for the Windows build configuration changes,

changes look sane to me, couldn't get the wheel to build but that's likely something i screwed up, did not spend a whole lot of time on it

k:\BlenderGit\blender>K:\BlenderGit\lib\win64_vc15\python\310\bin\python.exe build_files\utils\make_bpy_wheel.py --build-dir k:\BlenderGit\bpy_2022\ --output-dir k:\blendergit\wheel k:\BlenderGit\bpy_2022\bin
K:\BlenderGit\lib\win64_vc15\python\310\lib\site-packages\setuptools\dist.py:487: UserWarning: Normalizing '3.4.0-alpha' to '3.4.0a0'
  warnings.warn(tmpl.format(**locals()))
usage: make_bpy_wheel.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: make_bpy_wheel.py --help [cmd1 cmd2 ...]
   or: make_bpy_wheel.py --help-commands
   or: make_bpy_wheel.py cmd --help

error: invalid command 'bdist_wheel'

looking at the test failures on the bots, it's likely missing some dll folder in its env and the binary failing to load

error: invalid command 'bdist_wheel'

This seems to be because the wheel package is not installed (pip install wheel). Probably the Python used to execute the script on the buildbot has it, but not the Python in the lib folder. We could bundle it for convenience.

looking at the test failures on the bots, it's likely missing some dll folder in its env and the binary failing to load

Yeah, I might just disable all the gtests for now. At least on the buildbot this is effectively covered by the regular Blender build.

.... At the point you're doing all of this work, are you sure you don't want to use pip + setuptools + scikit-build?

  • It'll automatically deal with reading from/re-using cmake cache, and handling the linking options required for python.
  • It'll automatically name the wheel file, and handles platform-specific strangeness (the manylinux wheel likely needs both manylinux2014 and manylinux_2_17 for instance, if we're building on CentOS 7).
  • It's the standard way to build a python wheel, especially a native python wheel, so it will be more familiar to future maintainers who deal with python.
  • There's options to automatically discover the version from git, if that's desired.

The only things needed to be installed before calling such a script is python (specifically the version of python to build/distribute against; that is, the python in the lib directory), and pip. Pip would handle auto-downloading the necessary additional build-time tools (it creates a single-use venv in /tmp by default, but there's ways to control that).

yeah i'd be fine with most of the tests being disabled for this build, the import_bpy.py test is the most important one here, as long as that one passes i think we're in good shape

.... At the point you're doing all of this work, are you sure you don't want to use pip + setuptools + scikit-build?

Basically yes, in the end I think this is still simpler than trying to bend our build pipeline to scikit-build.

The code that would have been replaced by scikit-build ended up working basically immediately, it's the integration with everything else that took most time to debug, and extra abstraction layers make that harder.

  • It'll automatically name the wheel file, and handles platform-specific strangeness (the manylinux wheel likely needs both manylinux2014 and manylinux_2_17 for instance, if we're building on CentOS 7).

My understanding is that manylinux_2_17 is the future proof solution. manylinux2014 may be needed for older Python and pip versions, but we're not making wheels for those.