Skip to content

Commit a6b1156

Browse files
author
Byron Boulton
committed
Implement PYTHONPATH initialization
Adding the initdir to PYTHONPATH allows users to "import" the "module" function in Python scripts. Signed-off-by: Byron Boulton <bboulton@ara.com>
1 parent d42a822 commit a6b1156

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ sed -e 's|@prefix@|$(prefix)|g' \
479479
-e 's|@setmanpath@|$(setsetmanpath)|g' \
480480
-e 's|@appendmanpath@|$(setappendmanpath)|g' \
481481
-e 's|@usemanpath@|$(setusemanpath)|g' \
482+
-e 's|@setpythonpath@|$(setsetpythonpath)|g' \
483+
-e 's|@appendpythonpath@|$(setappendpythonpath)|g' \
482484
-e 's|@notusemanpath@|$(setnotusemanpath)|g' \
483485
-e 's|@shellcompsource@|$(shellcompsource)|g' \
484486
-e 's|@tcllintercmd@|$(tcllintercmd)|g' \

Makefile.inc.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ libdir32 := @libdir32@
4848
# enable or not some specific definition
4949
setmanpath := @setmanpath@
5050
appendmanpath := @appendmanpath@
51+
setpythonpath := @setpythonpath@
52+
appendpythonpath := @appendpythonpath@
5153
setbinpath := @setbinpath@
5254
appendbinpath := @appendbinpath@
5355
setmodulespath := @setmodulespath@
@@ -179,3 +181,6 @@ BASENAME := @BASENAME@
179181
RMDIR_IGN_NON_EMPTY := @RMDIR_IGN_NON_EMPTY@
180182
SED_ERE := @SED_ERE@
181183

184+
# profile init scripts put init dir on PYTHONPATH
185+
setpythonpath := @setpythonpath@
186+

configure

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ listterseoutput editor variantshortcut bashcompletiondir fishcompletiondir \
4141
zshcompletiondir tcllinter tcllinteropts nagelfardatadir nagelfaraddons \
4242
stickypurge uniquenameloaded abortonerror sourcecache logger loggeropts \
4343
loggedevents conflictunload spideroutput spiderterseoutput spiderindepth \
44-
emacsdatadir emacsaddons requirevia"
44+
emacsdatadir emacsaddons requirevia setpythonpath appendpythonpath"
4545
libarglist=()
4646

4747
# flags to know if argument has been specified on command-line
@@ -52,6 +52,8 @@ defloggeropts=1
5252
prefix=/usr/local/Modules
5353
setmanpath=y
5454
appendmanpath=n
55+
setpythonpath=y
56+
appendpythonpath=n
5557
setbinpath=y
5658
appendbinpath=n
5759
setmodulespath=n
@@ -237,6 +239,9 @@ Optional Features:
237239
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
238240
--enable-set-manpath set mandir to MANPATH in init scripts [yes]
239241
--enable-append-manpath append rather prepend mandir to MANPATH [no]
242+
--enable-set-pythonpath set initdir to PYTHONPATH in init scripts [yes]
243+
--enable-append-pythonpath
244+
append rather prepend initdir to PYTHONPATH [no]
240245
--enable-set-binpath set bindir to PATH in init scripts [yes]
241246
--enable-append-binpath append rather prepend bindir to PATH [no]
242247
--enable-modulespath, --enable-dotmodulespath
@@ -720,6 +725,12 @@ for arg in "$@"; do
720725
--enable-append-manpath*|--disable-append-manpath)
721726
# shellcheck disable=SC2034
722727
appendmanpath=$(get_feature_value "$arg") ;;
728+
--enable-set-pythonpath*|--disable-set-pythonpath)
729+
# shellcheck disable=SC2034
730+
setpythonpath=$(get_feature_value "$arg") ;;
731+
--enable-append-pythonpath*|--disable-append-pythonpath)
732+
# shellcheck disable=SC2034
733+
appendpythonpath=$(get_feature_value "$arg") ;;
723734
--enable-set-binpath*|--disable-set-binpath)
724735
# shellcheck disable=SC2034
725736
setbinpath=$(get_feature_value "$arg") ;;

site.exp.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ set install_libdir32 "@libdir32@"
3232
set install_setmanpath "@setmanpath@"
3333
set install_appendmanpath "@appendmanpath@"
3434
set install_usemanpath "@usemanpath@"
35+
set install_setpythonpath "@setpythonpath@"
36+
set install_appendpythonpath "@appendpythonpath@"
3537
set install_setbinpath "@setbinpath@"
3638
set install_appendbinpath "@appendbinpath@"
3739
set install_examplemodulefiles "@examplemodulefiles@"

tcl/subcmd.tcl.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,11 @@ proc cmdModuleAutoinit {} {
21572157
@setmanpath@}
21582158
}
21592159

2160+
# add Modules init directory to PYTHONPATH if enabled
2161+
@setpythonpath@if {{@initdir@} ni [split [get-env PYTHONPATH] :]} {
2162+
@setpythonpath@ @appendpythonpath@-path PYTHONPATH {@initdir@}
2163+
@setpythonpath@}
2164+
21602165
# source shell completion script if available, not installed in default
21612166
# completion locations and only if shell is interactive
21622167
if {[getState shell] in {@shellcompsource@} && [getState is_stderr_tty]} {

0 commit comments

Comments
 (0)