Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export python interpreter cargo variable #119

Merged
merged 3 commits into from
Dec 8, 2017

Conversation

indygreg
Copy link
Contributor

@indygreg indygreg commented Dec 7, 2017

The goal of this series is to export the full path to the Python interpreter as a Cargo variable so dependent crates can access the Python that python*-sys is using.

Read the commit messages for more info.

An upcoming commit will add yet another line of output to the invoked
Python program. Rather than continue to deal with line offsets, let's
pop the line(s) that we give named values to make code easier to
understand.
Previously, Python interpreter detection likely used "python",
"python2", "python3" as the Python interpreter path. This works
because command execution takes PATH into account.

But the determined Python path is ambiguous because it relies on
environment variables.

This commit changes the invoked Python script to print the value
of sys.executable. This value is captured and is used as the
Python interpreter path.
I had a need for this feature as part of implementing a dependent
crate that embeds a Python interpreter. I need that crate's build
script to invoke the Python interpreter and get some extra state
from it.

Before this commit, it wasn't obvious which Python interpreter the
python*-sys crates were actually using. You could force one via
PYTHON_SYS_EXECUTABLE or you could reimplemented the logic. But for
many cases, the simple thing of having the dependent crate read
state from the python*-sys crate feels best.
@dgrunwald dgrunwald merged commit 557652a into dgrunwald:master Dec 8, 2017
@indygreg indygreg deleted the export-python-interpreter branch December 9, 2017 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants