Skip to content

Commit 3d35fbb

Browse files
authored
feat: Add Tcl/Tkinter support (#2928)
1 parent 9872144 commit 3d35fbb

19 files changed

Lines changed: 474 additions & 7 deletions

File tree

docs/changelog/425.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added support for Tcl and Tkinter. You're welcome.
2+
Contributed by :user:`esafak`.

src/virtualenv/activation/bash/activate.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ deactivate () {
2323
unset _OLD_VIRTUAL_PYTHONHOME
2424
fi
2525

26+
if ! [ -z "${_OLD_VIRTUAL_TCL_LIBRARY+_}" ]; then
27+
TCL_LIBRARY="$_OLD_VIRTUAL_TCL_LIBRARY"
28+
export TCL_LIBRARY
29+
unset _OLD_VIRTUAL_TCL_LIBRARY
30+
fi
31+
if ! [ -z "${_OLD_VIRTUAL_TK_LIBRARY+_}" ]; then
32+
TK_LIBRARY="$_OLD_VIRTUAL_TK_LIBRARY"
33+
export TK_LIBRARY
34+
unset _OLD_VIRTUAL_TK_LIBRARY
35+
fi
36+
2637
# The hash command must be called to get it to forget past
2738
# commands. Without forgetting past commands the $PATH changes
2839
# we made may not be respected
@@ -68,6 +79,22 @@ if ! [ -z "${PYTHONHOME+_}" ] ; then
6879
unset PYTHONHOME
6980
fi
7081

82+
if [ __TCL_LIBRARY__ != "''" ]; then
83+
if ! [ -z "${TCL_LIBRARY+_}" ] ; then
84+
_OLD_VIRTUAL_TCL_LIBRARY="$TCL_LIBRARY"
85+
fi
86+
TCL_LIBRARY=__TCL_LIBRARY__
87+
export TCL_LIBRARY
88+
fi
89+
90+
if [ __TK_LIBRARY__ != "''" ]; then
91+
if ! [ -z "${TK_LIBRARY+_}" ] ; then
92+
_OLD_VIRTUAL_TK_LIBRARY="$TK_LIBRARY"
93+
fi
94+
TK_LIBRARY=__TK_LIBRARY__
95+
export TK_LIBRARY
96+
fi
97+
7198
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
7299
_OLD_VIRTUAL_PS1="${PS1-}"
73100
PS1="(${VIRTUAL_ENV_PROMPT}) ${PS1-}"

src/virtualenv/activation/batch/activate.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333

3434
@set PYTHONHOME=
3535

36+
@if defined TCL_LIBRARY @set "_OLD_VIRTUAL_TCL_LIBRARY=%TCL_LIBRARY%"
37+
@if NOT "__TCL_LIBRARY__"=="" @set "TCL_LIBRARY=__TCL_LIBRARY__"
38+
39+
@if defined TK_LIBRARY @set "_OLD_VIRTUAL_TK_LIBRARY=%TK_LIBRARY%"
40+
@if NOT "__TK_LIBRARY__"=="" @set "TK_LIBRARY=__TK_LIBRARY__"
41+
3642
@REM if defined _OLD_VIRTUAL_PATH (
3743
@if not defined _OLD_VIRTUAL_PATH @goto ENDIFVPATH1
3844
@set "PATH=%_OLD_VIRTUAL_PATH%"

src/virtualenv/activation/batch/deactivate.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
@set _OLD_VIRTUAL_PYTHONHOME=
1313
:ENDIFVHOME
1414

15+
@if defined _OLD_VIRTUAL_TCL_LIBRARY @set "TCL_LIBRARY=%_OLD_VIRTUAL_TCL_LIBRARY%"
16+
@if not defined _OLD_VIRTUAL_TCL_LIBRARY @set TCL_LIBRARY=
17+
@set _OLD_VIRTUAL_TCL_LIBRARY=
18+
19+
@if defined _OLD_VIRTUAL_TK_LIBRARY @set "TK_LIBRARY=%_OLD_VIRTUAL_TK_LIBRARY%"
20+
@if not defined _OLD_VIRTUAL_TK_LIBRARY @set TK_LIBRARY=
21+
@set _OLD_VIRTUAL_TK_LIBRARY=
22+
1523
@if not defined _OLD_VIRTUAL_PATH @goto ENDIFVPATH
1624
@set "PATH=%_OLD_VIRTUAL_PATH%"
1725
@set _OLD_VIRTUAL_PATH=

src/virtualenv/activation/cshell/activate.csh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set newline='\
66
'
77

8-
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH:q" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT:q" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
8+
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH:q" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_TCL_LIBRARY != 0 && setenv TCL_LIBRARY "$_OLD_VIRTUAL_TCL_LIBRARY:q" && unset _OLD_VIRTUAL_TCL_LIBRARY || unsetenv TCL_LIBRARY; test $?_OLD_VIRTUAL_TK_LIBRARY != 0 && setenv TK_LIBRARY "$_OLD_VIRTUAL_TK_LIBRARY:q" && unset _OLD_VIRTUAL_TK_LIBRARY || unsetenv TK_LIBRARY; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT:q" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
99

1010
# Unset irrelevant variables.
1111
deactivate nondestructive
@@ -15,7 +15,19 @@ setenv VIRTUAL_ENV __VIRTUAL_ENV__
1515
set _OLD_VIRTUAL_PATH="$PATH:q"
1616
setenv PATH "$VIRTUAL_ENV:q/"__BIN_NAME__":$PATH:q"
1717

18+
if (__TCL_LIBRARY__ != "") then
19+
if ($?TCL_LIBRARY) then
20+
set _OLD_VIRTUAL_TCL_LIBRARY="$TCL_LIBRARY"
21+
endif
22+
setenv TCL_LIBRARY __TCL_LIBRARY__
23+
endif
1824

25+
if (__TK_LIBRARY__ != "") then
26+
if ($?TK_LIBRARY) then
27+
set _OLD_VIRTUAL_TK_LIBRARY="$TK_LIBRARY"
28+
endif
29+
setenv TK_LIBRARY __TK_LIBRARY__
30+
endif
1931

2032
if (__VIRTUAL_PROMPT__ != "") then
2133
setenv VIRTUAL_ENV_PROMPT __VIRTUAL_PROMPT__

src/virtualenv/activation/fish/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ class FishActivator(ViaTemplateActivator):
77
def templates(self):
88
yield "activate.fish"
99

10+
def replacements(self, creator, dest):
11+
data = super().replacements(creator, dest)
12+
data.update({
13+
"__TCL_LIBRARY__": creator.interpreter.tcl_lib or "",
14+
"__TK_LIBRARY__": creator.interpreter.tk_lib or "",
15+
})
16+
return data
17+
1018

1119
__all__ = [
1220
"FishActivator",

src/virtualenv/activation/fish/activate.fish

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ function deactivate -d 'Exit virtualenv mode and return to the normal environmen
2626
set -e _OLD_VIRTUAL_PATH
2727
end
2828

29+
if test -n __TCL_LIBRARY__
30+
if test -n "$_OLD_VIRTUAL_TCL_LIBRARY";
31+
set -gx TCL_LIBRARY "$_OLD_VIRTUAL_TCL_LIBRARY";
32+
set -e _OLD_VIRTUAL_TCL_LIBRARY;
33+
else;
34+
set -e TCL_LIBRARY;
35+
end
36+
end
37+
if test -n __TK_LIBRARY__
38+
if test -n "$_OLD_VIRTUAL_TK_LIBRARY";
39+
set -gx TK_LIBRARY "$_OLD_VIRTUAL_TK_LIBRARY";
40+
set -e _OLD_VIRTUAL_TK_LIBRARY;
41+
else;
42+
set -e TK_LIBRARY;
43+
end
44+
end
45+
2946
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
3047
set -gx PYTHONHOME "$_OLD_VIRTUAL_PYTHONHOME"
3148
set -e _OLD_VIRTUAL_PYTHONHOME
@@ -68,6 +85,19 @@ else
6885
end
6986
set -gx PATH "$VIRTUAL_ENV"'/'__BIN_NAME__ $PATH
7087

88+
if test -n __TCL_LIBRARY__
89+
if set -q TCL_LIBRARY;
90+
set -gx _OLD_VIRTUAL_TCL_LIBRARY $TCL_LIBRARY;
91+
end
92+
set -gx TCL_LIBRARY '__TCL_LIBRARY__'
93+
end
94+
if test -n __TK_LIBRARY__
95+
if set -q TK_LIBRARY;
96+
set -gx _OLD_VIRTUAL_TK_LIBRARY $TK_LIBRARY;
97+
end
98+
set -gx TK_LIBRARY '__TK_LIBRARY__'
99+
end
100+
71101
# Prompt override provided?
72102
# If not, just use the environment name.
73103
if test -n __VIRTUAL_PROMPT__

src/virtualenv/activation/nushell/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def quote(string):
1212
"""
1313
Nushell supports raw strings like: r###'this is a string'###.
1414
15+
https://github.com/nushell/nushell.github.io/blob/main/book/working_with_strings.md
16+
1517
This method finds the maximum continuous sharps in the string and then
1618
quote it with an extra sharp.
1719
"""
@@ -32,6 +34,8 @@ def replacements(self, creator, dest_folder): # noqa: ARG002
3234
"__VIRTUAL_ENV__": str(creator.dest),
3335
"__VIRTUAL_NAME__": creator.env_name,
3436
"__BIN_NAME__": str(creator.bin_dir.relative_to(creator.dest)),
37+
"__TCL_LIBRARY__": creator.interpreter.tcl_lib or "",
38+
"__TK_LIBRARY__": creator.interpreter.tk_lib or "",
3539
}
3640

3741

src/virtualenv/activation/nushell/activate.nu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export-env {
5858
__VIRTUAL_PROMPT__
5959
}
6060
let new_env = { $path_name: $new_path VIRTUAL_ENV: $virtual_env VIRTUAL_ENV_PROMPT: $virtual_env_prompt }
61+
if (has-env 'TCL_LIBRARY') {
62+
let $new_env = $new_env | insert TCL_LIBRARY __TCL_LIBRARY__
63+
}
64+
if (has-env 'TK_LIBRARY') {
65+
let $new_env = $new_env | insert TK_LIBRARY __TK_LIBRARY__
66+
}
6167
let old_prompt_command = if (has-env 'PROMPT_COMMAND') { $env.PROMPT_COMMAND } else { '' }
6268
let new_env = if (is-env-true 'VIRTUAL_ENV_DISABLE_PROMPT') {
6369
$new_env

src/virtualenv/activation/powershell/activate.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ function global:deactivate([switch] $NonDestructive) {
77
Remove-Variable "_OLD_VIRTUAL_PATH" -Scope global
88
}
99

10+
if (Test-Path variable:_OLD_VIRTUAL_TCL_LIBRARY) {
11+
$env:TCL_LIBRARY = $variable:_OLD_VIRTUAL_TCL_LIBRARY
12+
Remove-Variable "_OLD_VIRTUAL_TCL_LIBRARY" -Scope global
13+
} else {
14+
if (Test-Path env:TCL_LIBRARY) {
15+
Remove-Item env:TCL_LIBRARY -ErrorAction SilentlyContinue
16+
}
17+
}
18+
19+
if (Test-Path variable:_OLD_VIRTUAL_TK_LIBRARY) {
20+
$env:TK_LIBRARY = $variable:_OLD_VIRTUAL_TK_LIBRARY
21+
Remove-Variable "_OLD_VIRTUAL_TK_LIBRARY" -Scope global
22+
} else {
23+
if (Test-Path env:TK_LIBRARY) {
24+
Remove-Item env:TK_LIBRARY -ErrorAction SilentlyContinue
25+
}
26+
}
27+
1028
if (Test-Path function:_old_virtual_prompt) {
1129
$function:prompt = $function:_old_virtual_prompt
1230
Remove-Item function:\_old_virtual_prompt
@@ -44,6 +62,20 @@ else {
4462
$env:VIRTUAL_ENV_PROMPT = $( Split-Path $env:VIRTUAL_ENV -Leaf )
4563
}
4664

65+
if (__TCL_LIBRARY__ -ne "") {
66+
if (Test-Path env:TCL_LIBRARY) {
67+
New-Variable -Scope global -Name _OLD_VIRTUAL_TCL_LIBRARY -Value $env:TCL_LIBRARY
68+
}
69+
$env:TCL_LIBRARY = __TCL_LIBRARY__
70+
}
71+
72+
if (__TK_LIBRARY__ -ne "") {
73+
if (Test-Path env:TK_LIBRARY) {
74+
New-Variable -Scope global -Name _OLD_VIRTUAL_TK_LIBRARY -Value $env:TK_LIBRARY
75+
}
76+
$env:TK_LIBRARY = __TK_LIBRARY__
77+
}
78+
4779
New-Variable -Scope global -Name _OLD_VIRTUAL_PATH -Value $env:PATH
4880

4981
$env:PATH = "$env:VIRTUAL_ENV/" + __BIN_NAME__ + __PATH_SEP__ + $env:PATH

0 commit comments

Comments
 (0)