Skip to content

Comments

IPython.utils._process_posix: import pexpect only when needed#14312

Merged
Carreau merged 1 commit intoipython:mainfrom
passagemath:lazy_import_pexpect
Jan 31, 2024
Merged

IPython.utils._process_posix: import pexpect only when needed#14312
Carreau merged 1 commit intoipython:mainfrom
passagemath:lazy_import_pexpect

Conversation

@mkoeppe
Copy link
Collaborator

@mkoeppe mkoeppe commented Jan 30, 2024

Delaying the import of pexpect to the first use.

This is needed to make import IPython work on Pyodide; see pyodide/pyodide#4452

@mkoeppe mkoeppe mentioned this pull request Jan 30, 2024
2 tasks
@hoodmane
Copy link
Contributor

I'd suggest adding a new file making a _process_emscripten:

def system(cmd):
    raise OSError("Not available")

def getoutput(cmd):
    raise OSError("Not available")

def check_pid(cmd):
    raise OSError("Not available")

def arg_split(s, posix=False, strict=True):
    """This one could be made to work but it's not clear if it would be useful..."""
    raise OSError("Not available")

and then apply this patch:

--- a/IPython/utils/process.py
+++ b/IPython/utils/process.py
@@ -15,6 +15,8 @@
     from ._process_win32 import system, getoutput, arg_split, check_pid
 elif sys.platform == 'cli':
     from ._process_cli import system, getoutput, arg_split, check_pid
+elif sys.platform == "emscripten":
+    from ._process_emscripten import system, getoutput, arg_split, check_pid
 else:
     from ._process_posix import system, getoutput, arg_split, check_pid

@Carreau Carreau added this to the 8.21 milestone Jan 31, 2024
@Carreau
Copy link
Member

Carreau commented Jan 31, 2024

I'm going to make a release soon, so I'm going to merge this, but +1 to extend with adding a _process_emscripten.py

@Carreau Carreau merged commit 4eab608 into ipython:main Jan 31, 2024
@hoodmane
Copy link
Contributor

Thanks @Carreau and @mkoeppe!

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 this pull request may close these issues.

3 participants