From 2e87200535f7e19dfde44a5374274bc2d9f9d362 Mon Sep 17 00:00:00 2001 From: Jeroen van Straten Date: Tue, 16 Aug 2022 14:31:18 +0200 Subject: [PATCH] docs: improve error messages for Python out-of-tree builds --- py/substrait_validator_build/__init__.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/py/substrait_validator_build/__init__.py b/py/substrait_validator_build/__init__.py index 9212996e..ccb33180 100644 --- a/py/substrait_validator_build/__init__.py +++ b/py/substrait_validator_build/__init__.py @@ -3,6 +3,7 @@ from maturin import * import shutil import os +import sys _PATHS = [ @@ -55,8 +56,27 @@ def _prepare(): # If the local_dependencies directory exists, pip is building the package # from a source distribution. In that case, the build environment is # already as it should be. - if not os.path.isdir("local_dependencies"): - populate() + if os.path.isdir("local_dependencies"): + return + + # Outside of building from specially-prepared sdist packages, we don't + # support out-of-tree builds, because that breaks Maturin and Cargo. The + # error messages you'd get if you were to try would be cryptic at best, so + # we detect this and fail more gently here. + if os.path.basename(os.path.realpath(".")) != "py": + print( + "\n" + "=================================================================\n" + "Out-of-tree build detected. This is not supported. Please\n" + "configure pip (or whatever build system you're using) to build\n" + "in-tree, for example using an editable install.\n" + "See https://github.com/substrait-io/substrait-validator/issues/35\n" + "=================================================================\n", + file=sys.stderr, + ) + sys.exit(1) + + populate() _maturin_prepare_metadata_for_build_wheel = (