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

configure: don't assume python3, create $PYTHON var. #6630

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ ifneq ($(RUST),0)
include cln-grpc/Makefile

$(MSGGEN_GENALL)&: doc/schemas/*.request.json doc/schemas/*.schema.json
PYTHONPATH=contrib/msggen python3 contrib/msggen/msggen/__main__.py
PYTHONPATH=contrib/msggen $(PYTHON) contrib/msggen/msggen/__main__.py

# The compiler assumes that the proto files are in the same
# directory structure as the generated files will be. Since we
Expand All @@ -384,8 +384,8 @@ GRPC_GEN = \
ALL_TEST_GEN += $(GRPC_GEN)

$(GRPC_GEN)&: cln-grpc/proto/node.proto cln-grpc/proto/primitives.proto
python3 -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/node.proto --python_out=$(GRPC_PATH)/ --grpc_python_out=$(GRPC_PATH)/ --experimental_allow_proto3_optional
python3 -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/primitives.proto --python_out=$(GRPC_PATH)/ --experimental_allow_proto3_optional
$(PYTHON) -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/node.proto --python_out=$(GRPC_PATH)/ --grpc_python_out=$(GRPC_PATH)/ --experimental_allow_proto3_optional
$(PYTHON) -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/primitives.proto --python_out=$(GRPC_PATH)/ --experimental_allow_proto3_optional
find $(GRPC_DIR)/ -type f -name "*.py" -print0 | xargs -0 sed -i'.bak' -e 's/^import \(.*\)_pb2 as .*__pb2/from pyln.grpc import \1_pb2 as \1__pb2/g'
find $(GRPC_DIR)/ -type f -name "*.py.bak" -delete
endif
Expand Down Expand Up @@ -421,7 +421,7 @@ mkdocs.yml: $(MANPAGES:=.md)
find doc -maxdepth 1 -name '*\.[0-9]\.md' | \
cut -b 5- | LC_ALL=C sort | \
sed 's/\(.*\)\.\(.*\).*\.md/- "\1": "\1.\2.md"/' | \
python3 devtools/blockreplace.py mkdocs.yml manpages --language=yml --indent " " \
$(PYTHON) devtools/blockreplace.py mkdocs.yml manpages --language=yml --indent " " \
)


Expand Down
34 changes: 22 additions & 12 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,25 @@ default_cwarnflags()
echo "$F"
}

default_python()
{
PYTHON_BINS="python3 python"
for p in $PYTHON_BINS; do
if [ "$(which $p)" != "" ] ; then
if $p --version 2>&1 | grep -q "Python 3."; then
echo "$p"
return
fi
fi
done
}

# Takes PYTHON var
default_pytest()
{
# Since we just checked that we have python3 we give that one the
# most priority and then fall back to some common aliases.
PYTEST_BINS="python3 -m pytest,pytest,py.test,pytest3,pytest-3"
PYTEST_BINS="$1 -m pytest,pytest,py.test,pytest3,pytest-3"
IFS=','
for p in $PYTEST_BINS; do
# If it is a combined command such as `python3 -m pytest` we
Expand All @@ -87,16 +101,10 @@ default_pytest()
fi
done

PYTHON_BINS="python python3"
for p in $PYTHON_BINS; do
if [ "$(which $p)" != "" ] ; then
$p --version 2>&1 | grep -q "Python 3." || continue
if $p -c "import pytest" 2>/dev/null ; then
echo "$p -m pytest"
return
fi
fi
done
if $1 -c "import pytest" 2>/dev/null; then
echo "$1 -m pytest"
return
fi
}

check_command()
Expand Down Expand Up @@ -170,7 +178,8 @@ set_defaults()
CSANFLAGS="$CSANFLAGS $FUZZFLAGS"
fi
echo CSANFLAGS = $CSANFLAGS
PYTEST=${PYTEST-$(default_pytest)}
PYTHON=${PYTHON-$(default_python)}
PYTEST=${PYTEST-$(default_pytest $PYTHON)}
COPTFLAGS=${COPTFLAGS-$(default_coptflags "$DEBUGBUILD")}
CONFIGURATOR_CC=${CONFIGURATOR_CC-$CC}
VALGRIND=${VALGRIND:-$(default_valgrind_setting)}
Expand Down Expand Up @@ -526,6 +535,7 @@ add_var HAVE_LOWDOWN "$HAVE_LOWDOWN"
add_var SHA256SUM "$SHA256SUM"
add_var FUZZING "$FUZZING"
add_var RUST "$RUST"
add_var PYTHON "$PYTHON"

# Hack to avoid sha256 name clash with libwally: will be fixed when that
# becomes a standalone shared lib.
Expand Down
2 changes: 1 addition & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ doc/index.rst: $(MANPAGES:=.md)
find doc -maxdepth 1 -name '*\.[0-9]\.md' | \
cut -b 5- | LC_ALL=C sort | \
sed "s/\(.*\)\.\(.*\).*\.md/\1 <\1.\2.md>/" | \
python3 devtools/blockreplace.py doc/index.rst manpages --language=rst --indent " " \
$(PYTHON) devtools/blockreplace.py doc/index.rst manpages --language=rst --indent " " \
)

# Overridden by GH CI if necessary.
Expand Down
Loading