From 60ef137bc33e203ac46342ae757a79ba79b63b70 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 22 Feb 2025 09:04:17 +0000 Subject: [PATCH] projects.mk, py-defs.mk, py-version.mk: Add py-version.mk This commit adds py-version.mk, eliminating redundancy between projects.mk and py-defs.mk in setting up the Python version early. --- make/projects.mk | 11 +---------- make/py-defs.mk | 12 ++---------- make/py-version.mk | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 20 deletions(-) create mode 100644 make/py-version.mk diff --git a/make/projects.mk b/make/projects.mk index bb2406da..b904474a 100644 --- a/make/projects.mk +++ b/make/projects.mk @@ -27,16 +27,7 @@ ifndef WHICH WHICH := $(firstword $(wildcard /usr/bin/which) $(shell which which)) endif -# note: This is redundant to py-defs.mk -ifneq ($(PYTHON_VERSION),) - PYTHON := /usr/bin/python$(PYTHON_VERSION) -else - ifeq ($(PYTHON),) - PYTHON := $(lastword $(shell /bin/bash -O extglob -c "ls -v /usr/bin/python[0-9].+([0-9])")) - endif - PYTHON_VERSION ?= $(patsubst python%,%,$(notdir $(PYTHON))) -endif -PYTHON_MAJOR = $(basename $(PYTHON_VERSION)) +include $(JWBDIR)/make/py-version.mk ifneq ($(TOPDIR),) proj_query_cmd = $(PYTHON) $(JWB_SCRIPT_DIR)/projects.py -p $(PROJECTS_DIR) -t $(TOPDIR) $(PROJECTS_PY_EXTRA_ARGS) diff --git a/make/py-defs.mk b/make/py-defs.mk index 9d3f9ef7..5c884a62 100644 --- a/make/py-defs.mk +++ b/make/py-defs.mk @@ -1,15 +1,6 @@ ENV_PYTHONPATH := $(PYTHONPATH) -# note: This is redundant to projects.mk -ifneq ($(PYTHON_VERSION),) - PYTHON := /usr/bin/python$(PYTHON_VERSION) -else - ifeq ($(PYTHON),) - PYTHON := $(lastword $(shell /bin/bash -O extglob -c "ls -v /usr/bin/python[0-9].+([0-9])")) - endif - PYTHON_VERSION ?= $(patsubst python%,%,$(notdir $(PYTHON))) -endif -PYTHON_MAJOR = $(basename $(PYTHON_VERSION)) +include $(JWBDIR)/make/py-version.mk ifeq ($(DEVELOPMENT),true) PY_SITE_PACKAGES_PATH := $(PREFIX)/python$(PYTHON_VERSION)/site-packages @@ -86,6 +77,7 @@ all: clean: pyc.clean echo-py: + @echo "PYTHON = $(PYTHON)" @echo "PY_INSTALL_DIR_PY = $(PY_INSTALL_DIR_PY)" @echo "PROJECT = $(PROJECT)" @echo "PY_SITE_PACKAGES_PATH = $(PY_SITE_PACKAGES_PATH)" diff --git a/make/py-version.mk b/make/py-version.mk new file mode 100644 index 00000000..c705891a --- /dev/null +++ b/make/py-version.mk @@ -0,0 +1,14 @@ +# This file strives to be the most minimal piece of code to set the python +# version up + +ifneq ($(PYTHON_VERSION),) + PYTHON := /usr/bin/python$(PYTHON_VERSION) +else + ifeq ($(PYTHON),) + #PYTHON := $(lastword $(shell /bin/bash -O extglob -c "ls -v /usr/bin/python[0-9].+([0-9])")) + PYTHON := $(shell which python3 | xargs readlink -f) + endif + PYTHON_VERSION ?= $(patsubst python%,%,$(notdir $(PYTHON))) +endif +PYTHON_MAJOR = $(basename $(PYTHON_VERSION)) +