jlpmapp.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """A Jupyter-aware wrapper for the yarn package manager"""
  2. import os
  3. # Copyright (c) Jupyter Development Team.
  4. # Distributed under the terms of the Modified BSD License.
  5. import sys
  6. from jupyterlab_server.process import subprocess, which
  7. HERE = os.path.dirname(os.path.abspath(__file__))
  8. YARN_PATH = os.path.join(HERE, "staging", "yarn.js")
  9. def execvp(cmd, argv):
  10. """Execvp, except on Windows where it uses Popen.
  11. The first argument, by convention, should point to the filename
  12. associated with the file being executed.
  13. Python provides execvp on Windows, but its behavior is problematic
  14. (Python bug#9148).
  15. """
  16. cmd = which(cmd)
  17. if os.name == "nt":
  18. import signal
  19. import sys
  20. p = subprocess.Popen([cmd] + argv[1:])
  21. # Don't raise KeyboardInterrupt in the parent process.
  22. # Set this after spawning, to avoid subprocess inheriting handler.
  23. signal.signal(signal.SIGINT, signal.SIG_IGN)
  24. p.wait()
  25. sys.exit(p.returncode)
  26. else:
  27. os.execvp(cmd, argv) # noqa S606
  28. def main(argv=None):
  29. """Run node and return the result."""
  30. # Make sure node is available.
  31. argv = argv or sys.argv[1:]
  32. execvp("node", ["node", YARN_PATH, *argv])