Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions py5jupyter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -33,10 +33,12 @@ def _jupyter_labextension_paths():
from `src` directory into <jupyter path>/labextensions/<dest> directory
during widget installation
"""
return [{
'src': 'labextension',
'dest': 'jupyter-py5',
}]
return [
{
"src": "labextension",
"dest": "jupyter-py5",
}
]


def _jupyter_nbextension_paths():
Expand All @@ -55,9 +57,11 @@ def _jupyter_nbextension_paths():
require: Path to importable AMD Javascript module inside the
<jupyter path>/nbextensions/<dest> directory
"""
return [{
'section': 'notebook',
'src': 'nbextension',
'dest': 'py5jupyter',
'require': 'py5jupyter/extension'
}]
return [
{
"section": "notebook",
"src": "nbextension",
"dest": "py5jupyter",
"require": "py5jupyter/extension",
}
]
4 changes: 2 additions & 2 deletions py5jupyter/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand All @@ -17,5 +17,5 @@
# along with this library. If not, see <https://www.gnu.org/licenses/>.
#
# *****************************************************************************
version_info = (0, 2, 0, 'a0')
version_info = (0, 2, 0, "a0")
__version__ = ".".join(map(str, version_info))
2 changes: 1 addition & 1 deletion py5jupyter/kernels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion py5jupyter/kernels/py5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion py5jupyter/kernels/py5/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down
35 changes: 21 additions & 14 deletions py5jupyter/kernels/py5/install.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -38,16 +38,15 @@
def install_py5_kernel_spec(user=True, prefix=None):
with TemporaryDirectory() as td:
os.chmod(td, 0o755) # Starts off as 700, not user readable
with open(Path(td) / 'kernel.json', 'w') as f:
with open(Path(td) / "kernel.json", "w") as f:
json.dump(kernel_json, f, sort_keys=True)

# Copy any resources
for file in (Path(__file__).parent / 'resources').glob('*'):
for file in (Path(__file__).parent / "resources").glob("*"):
shutil.copy(file, Path(td) / file.name)

print('Installing py5 Jupyter kernel spec')
KernelSpecManager().install_kernel_spec(
td, 'py5', user=user, prefix=prefix)
print("Installing py5 Jupyter kernel spec")
KernelSpecManager().install_kernel_spec(td, "py5", user=user, prefix=prefix)


def _is_root():
Expand All @@ -59,13 +58,21 @@ def _is_root():

def main(argv=None):
ap = argparse.ArgumentParser()
ap.add_argument('--user', action='store_true',
help="Install to the per-user kernels registry. Default if not root.")
ap.add_argument('--sys-prefix', action='store_true',
help="Install to sys.prefix (e.g. a virtualenv or conda env)")
ap.add_argument('--prefix',
help="Install to the given prefix. "
"Kernelspec will be installed in {PREFIX}/share/jupyter/kernels/")
ap.add_argument(
"--user",
action="store_true",
help="Install to the per-user kernels registry. Default if not root.",
)
ap.add_argument(
"--sys-prefix",
action="store_true",
help="Install to sys.prefix (e.g. a virtualenv or conda env)",
)
ap.add_argument(
"--prefix",
help="Install to the given prefix. "
"Kernelspec will be installed in {PREFIX}/share/jupyter/kernels/",
)
args = ap.parse_args(argv)

if args.sys_prefix:
Expand All @@ -76,5 +83,5 @@ def main(argv=None):
install_py5_kernel_spec(user=args.user, prefix=args.prefix)


if __name__ == '__main__':
if __name__ == "__main__":
main()
54 changes: 31 additions & 23 deletions py5jupyter/kernels/py5/kernel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -30,13 +30,10 @@
from py5_tools import __version__ as __py5_version__

_PY5_HELP_LINKS = [
{"text": "py5 Documentation", "url": "http://py5coding.org/"},
{
'text': 'py5 Documentation',
'url': 'http://py5coding.org/'
},
{
'text': 'py5 Function Reference',
'url': 'http://py5coding.org/reference/sketch.html'
"text": "py5 Function Reference",
"url": "http://py5coding.org/reference/sketch.html",
},
]

Expand All @@ -51,39 +48,50 @@
from py5_tools import sketch_portal
"""

_KERNEL_STARTUP = (_MACOSX_PRE_STARTUP if sys.platform == 'darwin' else "") + _DEFAULT_STARTUP
_KERNEL_STARTUP = (
_MACOSX_PRE_STARTUP if sys.platform == "darwin" else ""
) + _DEFAULT_STARTUP


class Py5Shell(ZMQInteractiveShell):

ast_transformers = List([TransformDynamicVariablesToCalls(), Py5CodeValidation()]).tag(config=True)
ast_transformers = List(
[TransformDynamicVariablesToCalls(), Py5CodeValidation()]
).tag(config=True)

banner2 = Unicode("py5 " + __py5_version__ + " | py5 kernel 0.1.3a0 | A Python Jupyter kernel plus py5 in imported mode").tag(config=True)
banner2 = Unicode(
"py5 "
+ __py5_version__
+ " | py5 kernel 0.1.3a0 | A Python Jupyter kernel plus py5 in imported mode"
).tag(config=True)


InteractiveShellABC.register(Py5Shell)


class Py5Kernel(IPythonKernel):
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
allow_none=True)
shell = Instance(
"IPython.core.interactiveshell.InteractiveShellABC", allow_none=True
)
shell_class = Type(Py5Shell)

help_links = List([*IPythonKernel.help_links.default(),
*_PY5_HELP_LINKS]).tag(config=True)
help_links = List([*IPythonKernel.help_links.default(), *_PY5_HELP_LINKS]).tag(
config=True
)

implementation = 'py5'
implementation_version = '0.1.3a0'
implementation = "py5"
implementation_version = "0.1.3a0"


class Py5App(IPKernelApp):
name = 'py5-kernel'
name = "py5-kernel"

kernel_class = Type('py5jupyter.kernels.py5.Py5Kernel',
klass='ipykernel.kernelbase.Kernel').tag(config=True)
kernel_class = Type(
"py5jupyter.kernels.py5.Py5Kernel", klass="ipykernel.kernelbase.Kernel"
).tag(config=True)

exec_lines = List(Unicode(), [
_KERNEL_STARTUP
]).tag(config=True)
exec_lines = List(Unicode(), [_KERNEL_STARTUP]).tag(config=True)

extensions = List(Unicode(), ['py5_tools.magics', 'py5_tools.magics.py5bot']).tag(config=True)
extensions = List(Unicode(), ["py5_tools.magics", "py5_tools.magics.py5bot"]).tag(
config=True
)
2 changes: 1 addition & 1 deletion py5jupyter/kernels/py5bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion py5jupyter/kernels/py5bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down
43 changes: 28 additions & 15 deletions py5jupyter/kernels/py5bot/install.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# *****************************************************************************
#
# Part of the py5jupyter (& py5) library
# Copyright (C) 2022-2023 Jim Schmitz
# Copyright (C) 2022-2024 Jim Schmitz
#
# This library is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -29,7 +29,13 @@


kernel_json = {
"argv": [sys.executable, "-m", "py5jupyter.kernels.py5bot", "-f", "{connection_file}"],
"argv": [
sys.executable,
"-m",
"py5jupyter.kernels.py5bot",
"-f",
"{connection_file}",
],
"display_name": "py5bot",
"language": "python",
}
Expand All @@ -38,16 +44,15 @@
def install_py5bot_kernel_spec(user=True, prefix=None):
with TemporaryDirectory() as td:
os.chmod(td, 0o755) # Starts off as 700, not user readable
with open(Path(td) / 'kernel.json', 'w') as f:
with open(Path(td) / "kernel.json", "w") as f:
json.dump(kernel_json, f, sort_keys=True)

# Copy any resources
for file in (Path(__file__).parent / 'resources').glob('*'):
for file in (Path(__file__).parent / "resources").glob("*"):
shutil.copy(file, Path(td) / file.name)

print('Installing py5bot Jupyter kernel spec')
KernelSpecManager().install_kernel_spec(
td, 'py5bot', user=user, prefix=prefix)
print("Installing py5bot Jupyter kernel spec")
KernelSpecManager().install_kernel_spec(td, "py5bot", user=user, prefix=prefix)


def _is_root():
Expand All @@ -59,13 +64,21 @@ def _is_root():

def main(argv=None):
ap = argparse.ArgumentParser()
ap.add_argument('--user', action='store_true',
help="Install to the per-user kernels registry. Default if not root.")
ap.add_argument('--sys-prefix', action='store_true',
help="Install to sys.prefix (e.g. a virtualenv or conda env)")
ap.add_argument('--prefix',
help="Install to the given prefix. "
"Kernelspec will be installed in {PREFIX}/share/jupyter/kernels/")
ap.add_argument(
"--user",
action="store_true",
help="Install to the per-user kernels registry. Default if not root.",
)
ap.add_argument(
"--sys-prefix",
action="store_true",
help="Install to sys.prefix (e.g. a virtualenv or conda env)",
)
ap.add_argument(
"--prefix",
help="Install to the given prefix. "
"Kernelspec will be installed in {PREFIX}/share/jupyter/kernels/",
)
args = ap.parse_args(argv)

if args.sys_prefix:
Expand All @@ -76,5 +89,5 @@ def main(argv=None):
install_py5bot_kernel_spec(user=args.user, prefix=args.prefix)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading