Commit 88ba422
committed
Support multi-argument Pythons (like
The changes in this commit add support for things like `#!/usr/bin/env python3` and make errors easier to find. Here are the details:
1. **Support multi-argument Python interpreters**
Many people specify a Python interpreter with a line like this: `/usr/bin/env python3`. However, SublimePythonIDE allows only to specify the path to a Python interpreter. This would be less portable: Python 3 might be at `/usr/bin/python3` on one system and `/usr/local/bin/python3` on another. This commit makes it possible.
How: This commit changes the python interpreter path (the thing named `python` in `proxy_for()` and `self.python` in `Proxy`) to be a list of strings instead of a single string. This allows for multi-argument Pythons to be specified by any of the Python path providers, including `get_setting("python_interpreter")` (aka, the `python_interpreter` setting can now be a list).
This change is backwards-compatible: Python providers that emit a string will have it converted into the correct format (`"/usr/bin/python" -> ["/usr/bin/python"]`). A new function, `normalize_path`, makes normalizing easier.
2. **Auto-detect Python interpreter from shebang line**
Perhaps the most common place to add such a Python interpreter specification is in the shebang (`#!`) line. This commit will choose the Python interpreter based on this.
/pull/61 tried to do this earlier, but without support for multi-argument Pythons, it was forced to resolve the path to the actual Python. As such, it only worked for absolute paths to Python and `env` and for `env` it had to simulate `env`'s behavior (it "simulated" this by assuming Python is always in the same directory as `env`).
This change is backwards-compatible: If the first line of the current file does not start with `#!`, the other Python path providers are tried.
3. **More informative error messages**
This commit makes the "Could not detect python" message more informative by indicating which paths were tried. Here's an example:
<img width="784" src="https://cloud.githubusercontent.com/assets/1570168/11181148/d40ce048-8c14-11e5-9990-f010174455f5.png">env python)1 parent 7564033 commit 88ba422
1 file changed
Lines changed: 49 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
303 | 323 | | |
304 | 324 | | |
305 | | - | |
| 325 | + | |
306 | 326 | | |
307 | 327 | | |
308 | 328 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
315 | 337 | | |
316 | | - | |
| 338 | + | |
317 | 339 | | |
318 | 340 | | |
319 | 341 | | |
320 | | - | |
321 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
322 | 352 | | |
323 | | - | |
324 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
325 | 357 | | |
326 | 358 | | |
327 | 359 | | |
328 | 360 | | |
329 | 361 | | |
330 | 362 | | |
331 | | - | |
| 363 | + | |
332 | 364 | | |
333 | 365 | | |
334 | 366 | | |
| |||
0 commit comments