Skip to content

Commit f528c19

Browse files
authored
Merge pull request #2940 from esafak/fix/2930-tcl-library-bug
fix: Correctly unpack _get_tcl_tk_libs() response in PythonInfo
2 parents 94004cc + a7c6824 commit f528c19

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

docs/changelog/2930.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Correctly unpack _get_tcl_tk_libs() response in PythonInfo.
2+
Contributed by :user:`esafak`.

src/virtualenv/activation/bash/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ def templates(self):
1212
def as_name(self, template):
1313
return Path(template).stem
1414

15+
def replacements(self, creator, dest):
16+
data = super().replacements(creator, dest)
17+
data.update({
18+
"__TCL_LIBRARY__": creator.interpreter.tcl_lib or "",
19+
"__TK_LIBRARY__": creator.interpreter.tk_lib or "",
20+
})
21+
return data
22+
1523

1624
__all__ = [
1725
"BashActivator",

src/virtualenv/activation/bash/activate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ if ! [ -z "${PYTHONHOME+_}" ] ; then
7979
unset PYTHONHOME
8080
fi
8181

82-
if [ __TCL_LIBRARY__ != "''" ]; then
82+
if [ __TCL_LIBRARY__ != "" ]; then
8383
if ! [ -z "${TCL_LIBRARY+_}" ] ; then
8484
_OLD_VIRTUAL_TCL_LIBRARY="$TCL_LIBRARY"
8585
fi
8686
TCL_LIBRARY=__TCL_LIBRARY__
8787
export TCL_LIBRARY
8888
fi
8989

90-
if [ __TK_LIBRARY__ != "''" ]; then
90+
if [ __TK_LIBRARY__ != "" ]; then
9191
if ! [ -z "${TK_LIBRARY+_}" ] ; then
9292
_OLD_VIRTUAL_TK_LIBRARY="$TK_LIBRARY"
9393
fi

src/virtualenv/discovery/py_info.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ def abs_path(v):
123123

124124
self.sysconfig_vars = {i: sysconfig.get_config_var(i or "") for i in config_var_keys}
125125

126-
self.tcl_lib, self.tk_lib = self._get_tcl_tk_libs() if "TCL_LIBRARY" in os.environ else None, None
126+
if "TCL_LIBRARY" in os.environ:
127+
self.tcl_lib, self.tk_lib = self._get_tcl_tk_libs()
128+
else:
129+
self.tcl_lib, self.tk_lib = None, None
127130

128131
confs = {
129132
k: (self.system_prefix if v is not None and v.startswith(self.prefix) else v)

tests/unit/activation/test_bash.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ def __init__(self, dest):
4848
assert "unset _OLD_VIRTUAL_TK_LIBRARY" in content
4949

5050
if present:
51-
assert "if [ /path/to/tcl != \"''\" ]; then" in content
51+
assert 'if [ /path/to/tcl != "" ]; then' in content
5252
assert "TCL_LIBRARY=/path/to/tcl" in content
5353
assert "export TCL_LIBRARY" in content
5454

55-
assert "if [ /path/to/tk != \"''\" ]; then" in content
55+
assert 'if [ /path/to/tk != "" ]; then' in content
5656
assert "TK_LIBRARY=/path/to/tk" in content
5757
assert "export TK_LIBRARY" in content
5858
else:
5959
# When not present, the if condition is false, so the block is not executed
60-
assert "if [ '' != \"''\" ]; then" in content
60+
assert "if [ '' != \"\" ]; then" in content, content
6161
assert "TCL_LIBRARY=''" in content
6262
# The export is inside the if, so this is fine
6363
assert "export TCL_LIBRARY" in content

0 commit comments

Comments
 (0)