From dc5c2a9b8f48fe182bc68dd0bf81776cb0ea2fe8 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Mon, 13 Jul 2020 22:38:45 +0100 Subject: [PATCH] Rename PYTHON_SYS_EXECUTABLE to PYO3_PYTHON --- CHANGELOG.md | 1 + build.rs | 17 +++++++++++++---- guide/src/building_and_distribution.md | 2 +- guide/src/pypy.md | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c522deb7e..f5e2e24a5d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Correct FFI definitions `Py_SetProgramName` and `Py_SetPythonHome` to take `*const` argument instead of `*mut`. [#1021](https://github.com/PyO3/pyo3/pull/1021) - Rename `PyString::to_string` to `to_str`, change return type `Cow` to `&str`. [#1023](https://github.com/PyO3/pyo3/pull/1023) - Correct FFI definition `_PyLong_AsByteArray` `*mut c_uchar` argument instead of `*const c_uchar`. [#1029](https://github.com/PyO3/pyo3/pull/1029) +- Rename `PYTHON_SYS_EXECUTABLE` to `PYO3_PYTHON`. The old name will continue to work but will be undocumented, and will be removed in a future release. [#1039](https://github.com/PyO3/pyo3/pull/1039) - `PyType::as_type_ptr` is no longer `unsafe`. [#1047](https://github.com/PyO3/pyo3/pull/1047) - Change `PyIterator::from_object` to return `PyResult` instead of `Result`. [#1051](https://github.com/PyO3/pyo3/pull/1051) - Implement `Send + Sync` for `PyErr`. `PyErr::new`, `PyErr::from_type`, `PyException::py_err` and `PyException::into` have had these bounds added to their arguments. [#1067](https://github.com/PyO3/pyo3/pull/1067) diff --git a/build.rs b/build.rs index a091e3e3169..b72b810f2b2 100644 --- a/build.rs +++ b/build.rs @@ -386,7 +386,7 @@ fn get_rustc_link_lib(config: &InterpreterConfig) -> Result { /// /// The following locations are checked in the order listed: /// -/// 1. If `PYTHON_SYS_EXECUTABLE` is set, this intepreter is used and an error is raised if the +/// 1. If `PYO3_PYTHON` is set, this intepreter is used and an error is raised if the /// version doesn't match. /// 2. `python` /// 3. `python{major version}` @@ -394,7 +394,10 @@ fn get_rustc_link_lib(config: &InterpreterConfig) -> Result { /// /// If none of the above works, an error is returned fn find_interpreter_and_get_config() -> Result<(InterpreterConfig, HashMap)> { - let python_interpreter = if let Some(exe) = env::var_os("PYTHON_SYS_EXECUTABLE") { + let python_interpreter = if let Some(exe) = env::var_os("PYO3_PYTHON") { + exe.into() + } else if let Some(exe) = env::var_os("PYTHON_SYS_EXECUTABLE") { + // Backwards-compatible name for PYO3_PYTHON; this may be removed at some point in the future. exe.into() } else { PathBuf::from( @@ -506,7 +509,7 @@ fn configure(interpreter_config: &InterpreterConfig) -> Result { }; if interpreter_config.version.major == 2 { - // fail PYTHON_SYS_EXECUTABLE=python2 cargo ... + // fail PYO3_PYTHON=python2 cargo ... bail!("Python 2 is not supported"); } @@ -637,7 +640,13 @@ fn main() -> Result<()> { // TODO: Find out how we can set -undefined dynamic_lookup here (if this is possible) } - let env_vars = ["LD_LIBRARY_PATH", "PATH", "PYTHON_SYS_EXECUTABLE", "LIB"]; + let env_vars = [ + "LD_LIBRARY_PATH", + "PATH", + "PYTHON_SYS_EXECUTABLE", + "PYO3_PYTHON", + "LIB", + ]; for var in env_vars.iter() { println!("cargo:rerun-if-env-changed={}", var); diff --git a/guide/src/building_and_distribution.md b/guide/src/building_and_distribution.md index 354261d76c0..7c36fd3822f 100644 --- a/guide/src/building_and_distribution.md +++ b/guide/src/building_and_distribution.md @@ -2,7 +2,7 @@ ## Python version -PyO3 uses a build script to determine the Python version and set the correct linker arguments. By default it uses the `python3` executable. You can override the Python interpreter by setting `PYTHON_SYS_EXECUTABLE`, e.g., `PYTHON_SYS_EXECUTABLE=python3.6`. +PyO3 uses a build script to determine the Python version and set the correct linker arguments. By default it uses the `python3` executable. You can override the Python interpreter by setting `PYO3_PYTHON`, e.g., `PYO3_PYTHON=python3.6`. ## Linking diff --git a/guide/src/pypy.md b/guide/src/pypy.md index 838ceba87f0..111cf43076c 100644 --- a/guide/src/pypy.md +++ b/guide/src/pypy.md @@ -6,9 +6,9 @@ Support is only provided for building Rust extension for code running under PyPy This is a limitation of cpyext and support for embedding cpyext is not planned. -Compilation against PyPy is done by exporting the `PYTHON_SYS_EXECUTABLE` to point to a PyPy binary or by compiling in a PyPy virtualenv. +Compilation against PyPy is done by exporting `PYO3_PYTHON` to point to a PyPy binary or by compiling in a PyPy virtualenv. -For example, `PYTHON_SYS_EXECUTABLE="/path/to/pypy3" /path/to/pypy3 setup.py install` +For example, `PYO3_PYTHON="/path/to/pypy3" /path/to/pypy3 setup.py install` ## Unsupported features