Skip to content

Commit

Permalink
Add Python source distribution metadata to source tarball
Browse files Browse the repository at this point in the history
We'll want to upload the source tarball to PyPI so the complete
corresponding source is available alongside the wheels.  However, it's
infeasible to support PEP 517 source builds with our highly customized
build process.  In practice, `pip install` will only try to do source
builds on platforms where a wheel isn't available.  Configure PEP 517
builds to use meson-python, then have meson-python fail with an error
encouraging users to install OpenSlide from source.

Signed-off-by: Benjamin Gilbert <bgilbert@cs.cmu.edu>
  • Loading branch information
bgilbert committed Mar 17, 2024
1 parent 4202688 commit 8102e5d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
13 changes: 12 additions & 1 deletion artifacts/postprocess-sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
sys.path.insert(0, os.environ['MESON_SOURCE_ROOT'])

from common.argparse import TypedArgs # noqa: E402
from common.meson import meson_introspect # noqa: E402
from common.meson import meson_introspect, meson_source_root # noqa: E402
from common.python import pyproject_to_message # noqa: E402


class Args(TypedArgs):
Expand All @@ -46,6 +47,7 @@ class Args(TypedArgs):
)
args.parse()
os.environ['MESONINTROSPECT'] = args.introspect
src = meson_source_root()
dest = Path(os.environ['MESON_DIST_ROOT'])

# remove those parts of .github not ignored from .gitattributes
Expand All @@ -58,3 +60,12 @@ class Args(TypedArgs):
except IndexError:
suffix = ''
(dest / 'suffix').write_text(suffix + '\n')

# create Python source distribution metadata
pyproject = (
(src / 'artifacts' / 'python' / 'pyproject.in.toml')
.read_text()
.replace('@version@', version)
)
(dest / 'pyproject.toml').write_text(pyproject)
(dest / 'PKG-INFO').write_bytes(pyproject_to_message(pyproject).as_bytes())
8 changes: 8 additions & 0 deletions artifacts/python/pyproject.in.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ Homepage = "https://openslide.org/"
# use GitHub Releases page because it has subproject versions
"Release notes" = "https://github.com/openslide/openslide-bin/releases"
Repository = "https://github.com/openslide/openslide-bin"

[build-system]
# The sole purpose of this build is to fail. See comment in meson.build.
build-backend = "mesonpy"
requires = ["meson-python"]

[tool.meson-python.args]
setup = ['-Dpep517=true']
29 changes: 29 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ project(
],
)

if get_option('pep517')
# openslide-bin builds OpenSlide and all its dependencies in a controlled
# environment:
#
# - Linux builds are linked against an EL 8 glibc for maximum compatibility.
# - macOS builds run Meson twice, for x86_64 and arm64, and then merge the
# results into a universal build.
# - Windows builds link against the UCRT, and use a GCC compiled for Win32
# threads to avoid producing a dependency on the winpthreads DLL.
#
# If we wanted to support building via PEP 517, we'd need to run the
# entire build from inside a PEP 517 backend (such as meson-python) which
# isn't designed to emit arbitrary artifacts such as bdist archives. And
# even that wouldn't be enough, since the only way to get correct wheel
# tags is to fix the tags *after* the PEP 517 build finishes, e.g. with
# auditwheel on Linux.
#
# Since our actual wheel is very simple, and building a wheel isn't the
# main purpose of openslide-bin, it's not worth the extra complexity to
# support pip builds from source. And so, while the PyPI source package
# contains exactly the bits that built the binaries, those binaries can
# only be built by directly invoking our build tooling.
#
# If `pip install openslide-bin` doesn't find a wheel, either the OS is
# too old or it isn't supported (e.g. FreeBSD), and openslide-bin can't
# help.
error('No openslide-bin wheel is available for your platform. Install OpenSlide from source.')
endif

system = host_machine.system()

subdir('deps')
Expand Down
6 changes: 6 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ option(
value : false,
description : 'Enable subprojects for OpenSlide Git main',
)
option(
'pep517',
type : 'boolean',
value : false,
description : 'PEP 517 build inside meson-python',
)

0 comments on commit 8102e5d

Please sign in to comment.