Skip to content

Environment is not correctly updated on Windows on toolchain installation #3092

@winstxnhdw

Description

@winstxnhdw

Bug Description

_get_env() should update os.environ instead of returning a merged dict

On Windows, passing a custom env dict to subprocess does not affect how the OS searches for the executable. This means subprocess.check_output(["cargo", "--version"], env={**os.environ, **extra_env}) fails to find cargo.exe even though the merged dict contains the correct PATH.

To fix this, I am guessing we should update os.environ in place instead of returning a merged dict:

def _get_env() -> Optional[Dict[str, str]]:
    if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"):
        from puccinialin import setup_rust

        print("Rust not found, installing into a temporary directory")
        extra_env = setup_rust()
        os.environ.update(extra_env)
    return None

Related to konstin/puccinialin#16

Your maturin version (maturin --version)

1.12.6

Your Python version (python -V)

All Python versions

Your pip version (pip -V)

26.0.1

What bindings you're using

None

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

name: Install

on: [push]

jobs:
  install:
    runs-on: windows-latest

    steps:
      - name: Uninstall Rust
        run: rustup self uninstall -y

      - name: Install GxHash
        run: pip install gxhash

Workflow will fail when it should pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions