Skip to content

Commit 2df1960

Browse files
TobiasTobias
authored andcommitted
changed comments and mode for sourced scripts
the comment of sourced scripts now tells about this fact (they are not run but sourced), and they are not made executable
1 parent 8c64859 commit 2df1960

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

virtualenvwrapper/user_scripts.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,61 +66,84 @@ def run_global(script_name, *args):
6666
GLOBAL_HOOKS = [
6767
# initialize
6868
("initialize",
69-
"This hook is run during the startup phase "
69+
"This hook is sourced during the startup phase "
7070
"when loading virtualenvwrapper.sh."),
7171

7272
# mkvirtualenv
7373
("premkvirtualenv",
7474
"This hook is run after a new virtualenv is created "
7575
"and before it is activated."),
76+
# argument: name of new environment
7677
("postmkvirtualenv",
77-
"This hook is run after a new virtualenv is activated."),
78+
"This hook is sourced after a new virtualenv is activated."),
79+
80+
# cpvirtualenv:
81+
# precpvirtualenv <old> <new> (run),
82+
# postcpvirtualenv (sourced)
7883

7984
# rmvirtualenv
8085
("prermvirtualenv",
8186
"This hook is run before a virtualenv is deleted."),
87+
# argument: full path to environment directory
8288
("postrmvirtualenv",
8389
"This hook is run after a virtualenv is deleted."),
90+
# argument: full path to environment directory
8491

8592
# deactivate
8693
("predeactivate",
87-
"This hook is run before every virtualenv is deactivated."),
94+
"This hook is sourced before every virtualenv is deactivated."),
8895
("postdeactivate",
89-
"This hook is run after every virtualenv is deactivated."),
96+
"This hook is sourced after every virtualenv is deactivated."),
9097

9198
# activate
9299
("preactivate",
93100
"This hook is run before every virtualenv is activated."),
101+
# argument: environment name
94102
("postactivate",
95-
"This hook is run after every virtualenv is activated."),
103+
"This hook is sourced after every virtualenv is activated."),
104+
105+
# mkproject:
106+
# premkproject <new project name> (run),
107+
# postmkproject (sourced)
96108

97109
# get_env_details
98110
("get_env_details",
99111
"This hook is run when the list of virtualenvs is printed "
100112
"so each name can include details."),
113+
# argument: environment name
101114
]
102115

103116

104117
LOCAL_HOOKS = [
105118
# deactivate
106119
("predeactivate",
107-
"This hook is run before this virtualenv is deactivated."),
120+
"This hook is sourced before this virtualenv is deactivated."),
108121
("postdeactivate",
109-
"This hook is run after this virtualenv is deactivated."),
122+
"This hook is sourced after this virtualenv is deactivated."),
110123

111124
# activate
112125
("preactivate",
113126
"This hook is run before this virtualenv is activated."),
114127
("postactivate",
115-
"This hook is run after this virtualenv is activated."),
128+
"This hook is sourced after this virtualenv is activated."),
116129

117130
# get_env_details
118131
("get_env_details",
119132
"This hook is run when the list of virtualenvs is printed "
120133
"in 'long' mode so each name can include details."),
134+
# argument: environment name
121135
]
122136

123137

138+
SOURCED = ('initialize',
139+
'postactivate',
140+
'predeactivate',
141+
'postdeactivate',
142+
'postmkproject',
143+
'postmkvirtualenv',
144+
)
145+
146+
124147
def make_hook(filename, comment):
125148
"""Create a hook script.
126149
@@ -132,13 +155,18 @@ def make_hook(filename, comment):
132155
log.info('creating %s', filename)
133156
f = open(filename, 'w')
134157
try:
158+
# for sourced scripts, the shebang line won't be used;
159+
# it is useful for editors to recognize the file type, though
135160
f.write("#!%(shell)s\n# %(comment)s\n\n" % {
136161
'comment': comment,
137162
'shell': os.environ.get('SHELL', '/bin/sh'),
138163
})
139164
finally:
140165
f.close()
141-
os.chmod(filename, PERMISSIONS)
166+
os.chmod(filename,
167+
os.path.basename(filename) in SOURCED
168+
and PERMISSIONS_SOURCED
169+
or PERMISSIONS)
142170
return
143171

144172

0 commit comments

Comments
 (0)