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