From b5987293d1f8260b2afe3d8f59ca65966db741e3 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 17 Nov 2022 16:42:17 +1000 Subject: [PATCH 1/3] fix: determine package version even in deactivated venv --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 494a4298..3be043c0 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,12 @@ SHELL := bash # Set the package's name and version for use throughout the Makefile. PACKAGE_NAME := package -ifeq ($(origin VIRTUAL_ENV),undefined) - PACKAGE_VERSION := unknown -else +ifneq ($(origin VIRTUAL_ENV),undefined) PACKAGE_VERSION := $(shell python -c 'import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__)') +else ifneq ($(wildcard .venv/upgraded-on),) + PACKAGE_VERSION := $(shell .venv/bin/python -c 'import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__)') +else + PACKAGE_VERSION := unknown endif # This variable contains the first goal that matches any of the listed goals From c9a8a3b2d339dce338065af1239cf951c2fd04cd Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 17 Nov 2022 22:36:19 +1000 Subject: [PATCH 2/3] fix: error out if package version can not be determined --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3be043c0..f29dc200 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,15 @@ # https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html SHELL := bash -# Set the package's name and version for use throughout the Makefile. +# Set the package's name and version for use throughout the Makefile. If the +# version can not be determined then error out. PACKAGE_NAME := package ifneq ($(origin VIRTUAL_ENV),undefined) PACKAGE_VERSION := $(shell python -c 'import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__)') else ifneq ($(wildcard .venv/upgraded-on),) PACKAGE_VERSION := $(shell .venv/bin/python -c 'import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__)') else - PACKAGE_VERSION := unknown + $(error Unable to determine package version) endif # This variable contains the first goal that matches any of the listed goals From 66d2e0dd1eb63d4e81935cbb2009dc9b7965bfe1 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 17 Nov 2022 22:37:20 +1000 Subject: [PATCH 3/3] fix: just read the package version and fail in Python, not the Makefile --- Makefile | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index f29dc200..d05c6a51 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,9 @@ # https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html SHELL := bash -# Set the package's name and version for use throughout the Makefile. If the -# version can not be determined then error out. +# Set the package's name and version for use throughout the Makefile. PACKAGE_NAME := package -ifneq ($(origin VIRTUAL_ENV),undefined) - PACKAGE_VERSION := $(shell python -c 'import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__)') -else ifneq ($(wildcard .venv/upgraded-on),) - PACKAGE_VERSION := $(shell .venv/bin/python -c 'import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__)') -else - $(error Unable to determine package version) -endif +PACKAGE_VERSION := $(shell python -c $$'try: import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__);\nexcept: print("unknown");') # This variable contains the first goal that matches any of the listed goals # here, else it contains an empty string. The net effect is to filter out