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

\n in path causing issues on windows #2298

Closed
nobsclement opened this issue Apr 12, 2022 · 0 comments · Fixed by #2299
Closed

\n in path causing issues on windows #2298

nobsclement opened this issue Apr 12, 2022 · 0 comments · Fixed by #2299
Labels

Comments

@nobsclement
Copy link

nobsclement commented Apr 12, 2022

Bug Description

When building a brand new project created with maturin new, I see that error: failed to parse PyO3 config: Error { value: "expected key=value pair on line 7", source: None }.

After some investigations, I found out that from_cargo_dep_env() replaces every \\n with \n.

.map(|buf| InterpreterConfig::from_reader(buf.replace("\\n", "\n").as_bytes()))

Here is what buf.as_str() looks like before that replace is done:

"implementation=CPython\\nversion=3.9\\nshared=true\\nabi3=false\\nlib_name=python39\\nlib_dir=C:\\Users\\nobsclement\\AppData\\Local\\Programs\\Python\\Python39\\libs\\nexecutable=D:\\code\\nobody\\rust\\libs\\test_package\\.venv\\Scripts\\python.exe\\npointer_width=64\\nbuild_flags=\\nsuppress_build_script_link_lines=false\\n"

And after the replace:

"implementation=CPython\nversion=3.9\nshared=true\nabi3=false\nlib_name=python39\nlib_dir=C:\\Users\nobsclement\\AppData\\Local\\Programs\\Python\\Python39\\libs\nexecutable=D:\\code\nobody\\rust\\libs\\test_package\\.venv\\Scripts\\python.exe\npointer_width=64\nbuild_flags=\nsuppress_build_script_link_lines=false\n"

Note that lib_dir and executable now have wrong paths: C:\\Users\nobsclement\\AppData\\Local\\Programs\\Python\\Python39\\libs and D:\\code\nobody\\rust\\libs\\test_package\\.venv\\Scripts\\python.exe.

The bug occurs when the parse_value macro trims the line and interprets the path as two (or more) lines:

$variable = Some($value.trim().parse().context(format!(

Steps to Reproduce

On windows:

  1. Source a venv in a path that contains a folder that starts with a lowercase n
  2. Use maturin build

The build crashed when parsing lib_dir, but it should also crash when parsing executable which those steps should reproduce.

Backtrace

error: failed to run custom build command for `pyo3 v0.16.3`

Caused by:
  process didn't exit successfully: `D:\code\nobody\rust\target\debug\build\pyo3-b6ef0b8efd5a0d05\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'failed to parse PyO3 config: Error { value: "expected key=value pair on line 7", source: None }', C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\pyo3-build-config-0.16.3\src\lib.rs:94:10
  stack backtrace:
     0: std::panicking::begin_panic_handler
               at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c\/library\std\src\panicking.rs:584
     1: core::panicking::panic_fmt
               at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c\/library\core\src\panicking.rs:143
     2: core::result::unwrap_failed
               at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c\/library\core\src\result.rs:1749
     3: enum$<core::result::Result<pyo3_build_config::impl_::InterpreterConfig,pyo3_build_config::errors::Error> >::expect<pyo3_build_config::impl_::InterpreterConfig,pyo3_build_config::errors::Error>
               at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c\library\core\src\result.rs:1022
     4: pyo3_build_config::get::closure$0
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\pyo3-build-config-0.16.3\src\lib.rs:83
     5: once_cell::sync::impl$6::get_or_init::closure$0<pyo3_build_config::impl_::InterpreterConfig,pyo3_build_config::get::closure_env$0>
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\once_cell-1.10.0\src\lib.rs:974
     6: once_cell::imp::impl$4::initialize::closure$0<pyo3_build_config::impl_::InterpreterConfig,once_cell::sync::impl$6::get_or_init::closure_env$0<pyo3_build_config::impl_::InterpreterConfig,pyo3_build_config::get::closure_env$0>,enum$<once_cell::sync::impl$6:
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\once_cell-1.10.0\src\imp_std.rs:95
     7: once_cell::imp::initialize_inner
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\once_cell-1.10.0\src\imp_std.rs:171
     8: once_cell::imp::OnceCell<pyo3_build_config::impl_::InterpreterConfig>::initialize<pyo3_build_config::impl_::InterpreterConfig,once_cell::sync::impl$6::get_or_init::closure_env$0<pyo3_build_config::impl_::InterpreterConfig,pyo3_build_config::get::closure_e
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\once_cell-1.10.0\src\imp_std.rs:93
     9: once_cell::sync::OnceCell<pyo3_build_config::impl_::InterpreterConfig>::get_or_try_init<pyo3_build_config::impl_::InterpreterConfig,once_cell::sync::impl$6::get_or_init::closure_env$0<pyo3_build_config::impl_::InterpreterConfig,pyo3_build_config::get::clo
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\once_cell-1.10.0\src\lib.rs:1014
    10: once_cell::sync::OnceCell<pyo3_build_config::impl_::InterpreterConfig>::get_or_init<pyo3_build_config::impl_::InterpreterConfig,pyo3_build_config::get::closure_env$0>
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\once_cell-1.10.0\src\lib.rs:974
    11: pyo3_build_config::get
               at C:\Users\nobsclement\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\pyo3-build-config-0.16.3\src\lib.rs:75
    12: build_script_build::configure_pyo3
               at .\build.rs:43
    13: build_script_build::main
               at .\build.rs:56
    14: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
               at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c\library\core\src\ops\function.rs:227
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...

Your operating system and version

Windows 10, Version 2004

Your Python version (python --version)

Python 3.9.10

Your Rust version (rustc --version)

rustc 1.60.0 (7737e0b5c 2022-04-04)

Your PyO3 version

0.16.3

How did you install python? Did you use a virtualenv?

Python was installed using the python.org installer for windows.

I used a venv to build my project.

Additional Info

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant