MCPcopy Create free account
hub / github.com/ipython/ipython / rehashx

Method rehashx

IPython/core/magics/osm.py:203–280  ·  view source on GitHub ↗

Update the alias table with all executable files in $PATH. rehashx explicitly checks that every entry in $PATH is a file with execute access (os.X_OK). Under Windows, it checks executability as a match against a '|'-separated string of extensions, stored in the IPyt

(self, parameter_s='')

Source from the content-addressed store, hash-verified

201
202 @line_magic
203 def rehashx(self, parameter_s=''):
204 """Update the alias table with all executable files in $PATH.
205
206 rehashx explicitly checks that every entry in $PATH is a file
207 with execute access (os.X_OK).
208
209 Under Windows, it checks executability as a match against a
210 '|'-separated string of extensions, stored in the IPython config
211 variable win_exec_ext. This defaults to 'exe|com|bat'.
212
213 This function also resets the root module cache of module completer,
214 used on slow filesystems.
215 """
216 from IPython.core.alias import InvalidAliasError
217
218 # for the benefit of module completer in ipy_completers.py
219 del self.shell.db['rootmodules_cache']
220
221 path = [os.path.abspath(os.path.expanduser(p)) for p in
222 os.environ.get('PATH','').split(os.pathsep)]
223
224 syscmdlist = []
225 savedir = os.getcwd()
226
227 # Now walk the paths looking for executables to alias.
228 try:
229 # write the whole loop for posix/Windows so we don't have an if in
230 # the innermost part
231 if self.is_posix:
232 for pdir in path:
233 try:
234 os.chdir(pdir)
235 except OSError:
236 continue
237
238 # for python 3.6+ rewrite to: with os.scandir(pdir) as dirlist:
239 dirlist = os.scandir(path=pdir)
240 for ff in dirlist:
241 if self.isexec(ff):
242 fname = ff.name
243 try:
244 # Removes dots from the name since ipython
245 # will assume names with dots to be python.
246 if not self.shell.alias_manager.is_alias(fname):
247 self.shell.alias_manager.define_alias(
248 fname.replace('.',''), fname)
249 except InvalidAliasError:
250 pass
251 else:
252 syscmdlist.append(fname)
253 else:
254 no_alias = Alias.blacklist
255 for pdir in path:
256 try:
257 os.chdir(pdir)
258 except OSError:
259 continue
260

Callers

nothing calls this directly

Calls 3

isexecMethod · 0.95
is_aliasMethod · 0.80
define_aliasMethod · 0.80

Tested by

no test coverage detected