mirror of https://github.com/pyodide/pyodide.git
Create a pyodide-py package (#909)
This commit is contained in:
parent
3f6a8e2fad
commit
ce96a51d38
4
Makefile
4
Makefile
|
@ -186,7 +186,7 @@ root/.built: \
|
|||
$(PARSO_LIBS) \
|
||||
src/sitecustomize.py \
|
||||
src/webbrowser.py \
|
||||
src/pyodide.py \
|
||||
src/pyodide-py/ \
|
||||
cpython/remove_modules.txt
|
||||
rm -rf root
|
||||
mkdir -p root/lib
|
||||
|
@ -199,7 +199,7 @@ root/.built: \
|
|||
cp src/webbrowser.py root/lib/python$(PYMINOR)
|
||||
cp src/_testcapi.py root/lib/python$(PYMINOR)
|
||||
cp src/pystone.py root/lib/python$(PYMINOR)
|
||||
cp src/pyodide.py root/lib/python$(PYMINOR)/site-packages
|
||||
cp -r src/pyodide-py/pyodide/ $(SITEPACKAGES)
|
||||
( \
|
||||
cd root/lib/python$(PYMINOR); \
|
||||
rm -fr `cat ../../../cpython/remove_modules.txt`; \
|
||||
|
|
|
@ -17,7 +17,7 @@ import sys
|
|||
|
||||
for base_path in [".", ".."]:
|
||||
sys.path.insert(0, os.path.abspath(base_path))
|
||||
sys.path.insert(1, os.path.abspath(os.path.join(base_path, "src")))
|
||||
sys.path.insert(1, os.path.abspath(os.path.join(base_path, "src", "pyodide-py")))
|
||||
sys.path.insert(
|
||||
2, os.path.abspath(os.path.join(base_path, "packages", "micropip", "micropip"))
|
||||
)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
from ._base import open_url, eval_code, find_imports, as_nested_list
|
||||
from .console import get_completions
|
||||
|
||||
__version__ = "0.15.0"
|
||||
|
||||
__all__ = ["open_url", "eval_code", "find_imports", "as_nested_list", "get_completions"]
|
|
@ -5,10 +5,7 @@ A library of helper utilities for connecting Python to the browser environment.
|
|||
import ast
|
||||
from io import StringIO
|
||||
from textwrap import dedent
|
||||
from typing import Dict, List, Optional, Any
|
||||
|
||||
|
||||
__version__ = "0.15.0"
|
||||
from typing import Dict, List, Any
|
||||
|
||||
|
||||
def open_url(url: str) -> StringIO:
|
||||
|
@ -128,42 +125,3 @@ def as_nested_list(obj) -> List:
|
|||
return [as_nested_list(x) for x in it]
|
||||
except TypeError:
|
||||
return obj
|
||||
|
||||
|
||||
def get_completions(
|
||||
code: str, cursor: Optional[int] = None, namespaces: Optional[List] = None
|
||||
) -> List[str]:
|
||||
"""
|
||||
Get code autocompletion candidates
|
||||
|
||||
Note that this function requires to have the jedi module loaded.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
code
|
||||
the Python code to complete.
|
||||
cursor
|
||||
optional position in the code at which to autocomplete
|
||||
namespaces
|
||||
a list of namespaces
|
||||
|
||||
Returns
|
||||
-------
|
||||
a list of autocompleted modules
|
||||
"""
|
||||
import jedi
|
||||
import __main__
|
||||
|
||||
if namespaces is None:
|
||||
namespaces = [__main__.__dict__]
|
||||
|
||||
if cursor is None:
|
||||
cursor = len(code)
|
||||
code = code[:cursor]
|
||||
interp = jedi.Interpreter(code, namespaces)
|
||||
completions = interp.completions()
|
||||
|
||||
return [x.name for x in completions]
|
||||
|
||||
|
||||
__all__ = ["open_url", "eval_code", "find_imports", "as_nested_list", "get_completions"]
|
|
@ -0,0 +1,37 @@
|
|||
from typing import List, Optional
|
||||
|
||||
|
||||
def get_completions(
|
||||
code: str, cursor: Optional[int] = None, namespaces: Optional[List] = None
|
||||
) -> List[str]:
|
||||
"""
|
||||
Get code autocompletion candidates
|
||||
|
||||
Note that this function requires to have the jedi module loaded.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
code
|
||||
the Python code to complete.
|
||||
cursor
|
||||
optional position in the code at which to autocomplete
|
||||
namespaces
|
||||
a list of namespaces
|
||||
|
||||
Returns
|
||||
-------
|
||||
a list of autocompleted modules
|
||||
"""
|
||||
import jedi
|
||||
import __main__
|
||||
|
||||
if namespaces is None:
|
||||
namespaces = [__main__.__dict__]
|
||||
|
||||
if cursor is None:
|
||||
cursor = len(code)
|
||||
code = code[:cursor]
|
||||
interp = jedi.Interpreter(code, namespaces)
|
||||
completions = interp.completions()
|
||||
|
||||
return [x.name for x in completions]
|
|
@ -2,7 +2,7 @@ import sys
|
|||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
|
||||
sys.path.append(str(Path(__file__).parents[2] / "src"))
|
||||
sys.path.append(str(Path(__file__).parents[2] / "src" / "pyodide-py"))
|
||||
|
||||
from pyodide import find_imports # noqa: E402
|
||||
|
||||
|
|
Loading…
Reference in New Issue