From 2ad5d376affd8d01145ec8ea9f25c9c7cb5c022d Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Mon, 15 Jul 2024 10:54:24 +0300 Subject: [PATCH] Fix python virtual environment support. This works with python 3.9, 3.10, 3.11 and 3.12 on MacOS. --- Makefile | 9 +++++---- etc/profile.d/z-ps-twtty-7.sh | 4 ++-- gwebu-profile.spec.in | 6 +++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 5efc318..64f2df9 100644 --- a/Makefile +++ b/Makefile @@ -11,11 +11,12 @@ help: @echo "▀▀▀▀▀▀" @echo @echo "Available targets:" - @echo " dist: create source distribution package in dist/" - @echo " rpm: create an RPM package" - @echo " changelog: Add a changelog entry to gwebu-profile.spec.in" + @echo " dist: Create source distribution package in dist/." + @echo " rpm: Create an RPM package." + @echo " podman_rpm Create an RPM package using podman on MacOS." + @echo " changelog: Add a changelog entry to gwebu-profile.spec.in." @echo - @echo " clean: clean all generated files" + @echo " clean: Clean all generated files." @echo @echo "Version $(ver), rpm_ver=$(rpm_ver), rpm_rev=$(rpm_rev)." .PHONY: help diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 348ce08..6a06f0f 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -81,9 +81,9 @@ function prompt_command() { local prompt="--($my_D, Err ${my_P[*]}, $my_TTY)---($PWD)--" if [ -n "${VIRTUAL_ENV:-}" ] && [ -n "$_OLD_VIRTUAL_PS1" ]; then - my_VENV="${VIRTUAL_ENV_PROMPT}" + export my_VENV="${VIRTUAL_ENV##*/}" prompt="--($my_D, Err ${my_P[*]}, $my_TTY, $my_VENV)---($PWD)--" - if [ "${PS1:1:${#VIRTUAL_ENV_PROMPT}}" == "$VIRTUAL_ENV_PROMPT" ]; then + if [ "${PS1:0:${#my_VENV}+3}" == "($my_VENV) " ]; then # PS1 will be restored by virtual environment's deactivate script. # Yeah, that has to be done better, 172 is correct but magic number. export PS1="${_OLD_VIRTUAL_PS1:0:172}, ${my_VENV}${_OLD_VIRTUAL_PS1:172}" diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 5d0acac..cd658be 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,7 +1,7 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile Version: 1.0.3 -Release: 0 +Release: 2 BuildArch: noarch License: GPLv2 Source0: profile.d-%{version}-%{release}.tar.xz @@ -41,6 +41,10 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Mon Jul 15 2024 Doncho Gunchev - 1.0.3-2 +- Fix python virtual environment support. + This works on MacOS with python 3.9, 3.10, 3.11 and 3.12. + * Sun Jul 14 2024 Doncho Gunchev - 1.0.3-0 - Initial python virtual environment support.