Skip to content

Commit 9a80a71

Browse files
committed
Build: Report actionable error during pip install if npm is not installed
The error now displays like this: Building wheels for collected packages: pminit Building wheel for pminit (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for pminit (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [38 lines of output] PythonMonkey Build Error: * It appears npm is not installed on this system. * npm is required for PythonMonkey to build. * Please install NPM and Node.js before installing PythonMonkey. * Refer to the documentation for installing NPM and Node.js here: https://nodejs.org/en/download Traceback (most recent call last): File "/tmp/pip-req-build-75mp6ch1/post-install-hook.py", line 38, in <module> main() File "/tmp/pip-req-build-75mp6ch1/post-install-hook.py", line 33, in main raise Exception("PythonMonkey build error: Unable to find npm on the system.") Exception: PythonMonkey build error: Unable to find npm on the system. Traceback (most recent call last): File "/home/will/.local/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module> main() File "/home/will/.local/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "/home/will/.local/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel return _build_backend().build_wheel(wheel_directory, config_settings, File "/tmp/pip-build-env-emge0d96/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/api.py", line 57, in build_wheel return WheelBuilder.make_in( File "/tmp/pip-build-env-emge0d96/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 88, in make_in wb.build(target_dir=directory) File "/tmp/pip-build-env-emge0d96/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 123, in build self._build(zip_file) File "/tmp/pip-build-env-emge0d96/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 172, in _build self._run_build_script(self._package.build_script) File "/tmp/pip-build-env-emge0d96/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 232, in _run_build_script subprocess.check_call([self.executable.as_posix(), build_script]) File "/usr/lib/python3.10/subprocess.py", line 369, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/usr/bin/python3', 'post-install-hook.py']' returned non-zero exit status 1. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pminit Failed to build pminit ERROR: Could not build wheels for pminit, which is required to install pyproject.toml-based projects
1 parent ae133ef commit 9a80a71

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

python/pminit/post-install-hook.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
22
import sys
3+
import shutil
34

45
def execute(cmd: str):
56
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
@@ -14,7 +15,25 @@ def execute(cmd: str):
1415
raise subprocess.CalledProcessError(return_code, cmd)
1516

1617
def main():
17-
execute("cd pythonmonkey && npm i --no-package-lock") # do not update package-lock.json
18+
node_package_manager = 'ynpm'
19+
# check if npm is installed on the system
20+
if (shutil.which(node_package_manager) is None):
21+
print("""
22+
23+
PythonMonkey Build Error:
24+
25+
26+
* It appears npm is not installed on this system.
27+
* npm is required for PythonMonkey to build.
28+
* Please install NPM and Node.js before installing PythonMonkey.
29+
* Refer to the documentation for installing NPM and Node.js here: https://nodejs.org/en/download
30+
31+
32+
""")
33+
raise Exception("PythonMonkey build error: Unable to find npm on the system.")
34+
else:
35+
execute(f"cd pythonmonkey && {node_package_manager} i --no-package-lock") # do not update package-lock.json
1836

1937
if __name__ == "__main__":
2038
main()
39+

0 commit comments

Comments
 (0)