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

Not passing environment vars to subprocess #4737

Closed
syrusakbary opened this issue May 22, 2024 — with Linear · 1 comment · Fixed by #4756
Closed

Not passing environment vars to subprocess #4737

syrusakbary opened this issue May 22, 2024 — with Linear · 1 comment · Fixed by #4756
Assignees

Comments

Copy link
Member

Note: you'll need to use the #4735 PR which unblocks the process.

You can try this by doing:

git clone https://github.com/wasmer-examples/pip-wasmer.git
wasmer-dev run . --net

This will run python -m pip install flask.

And return something similar to:

➜  pip-wasmer wasmer-dev run . --net
Collecting flask
  Downloading flask-3.0.3-py3-none-any.whl.metadata (3.2 kB)
Collecting Werkzeug>=3.0.0 (from flask)
  Downloading werkzeug-3.0.3-py3-none-any.whl.metadata (3.7 kB)
Collecting Jinja2>=3.1.2 (from flask)
  Downloading jinja2-3.1.4-py3-none-any.whl.metadata (2.6 kB)
Collecting itsdangerous>=2.1.2 (from flask)
  Downloading itsdangerous-2.2.0-py3-none-any.whl.metadata (1.9 kB)
Collecting click>=8.1.3 (from flask)
  Downloading click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Collecting blinker>=1.6.2 (from flask)
  Downloading blinker-1.8.2-py3-none-any.whl.metadata (1.6 kB)
Collecting MarkupSafe>=2.0 (from Jinja2>=3.1.2->flask)
  Downloading MarkupSafe-2.1.5.tar.gz (19 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      Traceback (most recent call last):
        File "/cpython/lib/python3.12/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/cpython/lib/python3.12/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/cpython/lib/python3.12/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 112, in get_requires_for_build_wheel
          backend = _build_backend()
                    ^^^^^^^^^^^^^^^^
        File "/cpython/lib/python3.12/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 74, in _build_backend
          ep = os.environ['PEP517_BUILD_BACKEND']
               ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
        File "<frozen os>", line 685, in __getitem__
      KeyError: 'PEP517_BUILD_BACKEND'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

This is because the environment variables passed in site_packages/pip/_vendor/pyproject_hooks/_impl.py in call_hook:

extra_environ = {'PEP517_BUILD_BACKEND': self.build_backend}

Are not passed properly to the subprocess:

self._subprocess_runner(
   ...,
   extra_environ=extra_environ
)
@maminrayej maminrayej self-assigned this May 23, 2024
@syrusakbary
Copy link
Member Author

How to reproduce it minimally:

$ wasmer run python
>>> import subprocess; subprocess.run(["/bin/python"], env={"MY_NEW_VAR": "1"})
(new subprocess):
>>> import os; print(os.environ.get("MY_NEW_VAR"))
None

In native python works properly:

$ python3
>>> import subprocess; subprocess.run(["python3"], env={"MY_NEW_VAR": "1"})
(new subprocess):
>>> import os; print(os.environ.get("MY_NEW_VAR"))
1

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 a pull request may close this issue.

2 participants