python interpreter autoselect based on #!/ on first line#61
Closed
viadanna wants to merge 2 commits intoJulianEberius:masterfrom
viadanna:master
Closed
python interpreter autoselect based on #!/ on first line#61viadanna wants to merge 2 commits intoJulianEberius:masterfrom viadanna:master
viadanna wants to merge 2 commits intoJulianEberius:masterfrom
viadanna:master
Conversation
szhu
added a commit
to szhu/SublimePythonIDE
that referenced
this pull request
Nov 16, 2015
The most canonical way people specify a Python interpreter is as an
argument to `usr/bin/env`, such as
`/usr/bin/env python-executable-name`, rather than naming the full path
to the executable, which is less portable. This commit does two things:
1. Change the python interpreter path (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 providers, including
`get_setting("python_interpreter", ...)`
2. Add `shebang_line_python()`, which detects Python based on the #!
(shebang) line.
JulianEberius/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 `env` and
it had to simulate `env`'s behavior, and it "simulated" this by
assuming Python is always in the same directory as `env`.
* In `proxy_for()`, `python` is used as key for a dictionary. Since
lists cannot be used as keys, a temporary tuple version this is
created.
szhu
added a commit
to szhu/SublimePythonIDE
that referenced
this pull request
Nov 16, 2015
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.
JulianEberius/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">
szhu
added a commit
to szhu/SublimePythonIDE
that referenced
this pull request
Nov 16, 2015
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.
JulianEberius/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">
szhu
added a commit
to szhu/SublimePythonIDE
that referenced
this pull request
Nov 16, 2015
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.
JulianEberius/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">
szhu
added a commit
to szhu/SublimePythonIDE
that referenced
this pull request
Nov 25, 2015
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.
JulianEberius/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">
Owner
|
Thanks for the contribution, and sorry I never got around to pull... however, it is now superseded by pull request #79 Thanks again |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey, got another PR that correctly parses /usr/bin/env python[x] and /usr/bin/python[x] into the python_interpreter setting. Good for multiple projects with differing python versions.