Add current working directory, '', to sys.path Unlike Python's default, we insert before the first `site-packages` or `dist-packages` directory, so that it is after the standard library. .. versionchanged:: 7.2 Try to insert after the standard library, i
(self)
| 191 | self.shell.init_user_ns() |
| 192 | |
| 193 | def init_path(self): |
| 194 | """Add current working directory, '', to sys.path |
| 195 | |
| 196 | Unlike Python's default, we insert before the first `site-packages` |
| 197 | or `dist-packages` directory, |
| 198 | so that it is after the standard library. |
| 199 | |
| 200 | .. versionchanged:: 7.2 |
| 201 | Try to insert after the standard library, instead of first. |
| 202 | .. versionchanged:: 8.0 |
| 203 | Allow optionally not including the current directory in sys.path |
| 204 | """ |
| 205 | if '' in sys.path or self.ignore_cwd: |
| 206 | return |
| 207 | for idx, path in enumerate(sys.path): |
| 208 | parent, last_part = os.path.split(path) |
| 209 | if last_part in {'site-packages', 'dist-packages'}: |
| 210 | break |
| 211 | else: |
| 212 | # no site-packages or dist-packages found (?!) |
| 213 | # back to original behavior of inserting at the front |
| 214 | idx = 0 |
| 215 | sys.path.insert(idx, '') |
| 216 | |
| 217 | def init_shell(self): |
| 218 | raise NotImplementedError("Override in subclasses") |