ipyk-unlock 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ipyk_unlock/__init__.py +6 -0
- ipyk_unlock/kernelapp.py +9 -0
- ipyk_unlock/kernelspec.py +69 -0
- ipyk_unlock/unlock_kernel.py +16 -0
- ipyk_unlock-0.1.1.dist-info/METADATA +52 -0
- ipyk_unlock-0.1.1.dist-info/RECORD +10 -0
- ipyk_unlock-0.1.1.dist-info/WHEEL +5 -0
- ipyk_unlock-0.1.1.dist-info/entry_points.txt +2 -0
- ipyk_unlock-0.1.1.dist-info/top_level.txt +2 -0
- ipyku_launcher.py +18 -0
ipyk_unlock/__init__.py
ADDED
ipyk_unlock/kernelapp.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from ipykernel.kernelapp import IPKernelApp
|
|
2
|
+
from traitlets import Type
|
|
3
|
+
|
|
4
|
+
class UnlockKernelApp(IPKernelApp):
|
|
5
|
+
kernel_class = Type("ipyk_unlock.unlock_kernel.UnlockKernel", klass="ipykernel.kernelbase.Kernel",
|
|
6
|
+
help="Kernel subclass used by this launcher.").tag(config=True)
|
|
7
|
+
subcommands = {"install": ("ipyk_unlock.kernelspec.InstallUnlockKernelSpecApp", "Install the Unlock kernel")}
|
|
8
|
+
|
|
9
|
+
launch_new_instance = UnlockKernelApp.launch_instance
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import errno
|
|
2
|
+
import platform
|
|
3
|
+
import shutil
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from ipykernel import kernelspec as ipks
|
|
7
|
+
from jupyter_client.kernelspec import KernelSpecManager
|
|
8
|
+
from traitlets import Unicode
|
|
9
|
+
|
|
10
|
+
KERNEL_NAME = f"{ipks.KERNEL_NAME}-unlock"
|
|
11
|
+
DISPLAY_NAME = f"Python {sys.version_info[0]} (unlock)"
|
|
12
|
+
|
|
13
|
+
def install(kernel_spec_manager: KernelSpecManager | None = None, user: bool = False, kernel_name: str = KERNEL_NAME,
|
|
14
|
+
display_name: str | None = None, prefix: str | None = None, profile: str | None = None,
|
|
15
|
+
env: dict[str, str] | None = None, frozen_modules: bool = False) -> str:
|
|
16
|
+
if kernel_spec_manager is None: kernel_spec_manager = KernelSpecManager()
|
|
17
|
+
if env is None: env = {}
|
|
18
|
+
if kernel_name != KERNEL_NAME and display_name is None: display_name = kernel_name
|
|
19
|
+
|
|
20
|
+
overrides = dict(display_name=display_name or DISPLAY_NAME, argv=ipks.make_ipkernel_cmd(mod="ipyku_launcher"))
|
|
21
|
+
extra_arguments = ["--profile", profile] if profile else None
|
|
22
|
+
|
|
23
|
+
if extra_arguments:
|
|
24
|
+
overrides["argv"] = ipks.make_ipkernel_cmd(mod="ipyku_launcher", extra_arguments=extra_arguments)
|
|
25
|
+
if display_name is None: overrides["display_name"] = "Python %i [profile=%s] (unlock)" % (sys.version_info[0], profile)
|
|
26
|
+
|
|
27
|
+
if sys.version_info >= (3, 11) and platform.python_implementation() == "CPython":
|
|
28
|
+
if not frozen_modules:
|
|
29
|
+
overrides["argv"] = ipks.make_ipkernel_cmd(mod="ipyku_launcher", extra_arguments=extra_arguments,
|
|
30
|
+
python_arguments=["-Xfrozen_modules=off"])
|
|
31
|
+
elif "PYDEVD_DISABLE_FILE_VALIDATION" not in env: env["PYDEVD_DISABLE_FILE_VALIDATION"] = "1"
|
|
32
|
+
|
|
33
|
+
if env: overrides["env"] = env
|
|
34
|
+
path = ipks.write_kernel_spec(overrides=overrides)
|
|
35
|
+
dest = kernel_spec_manager.install_kernel_spec(path, kernel_name=kernel_name, user=user, prefix=prefix)
|
|
36
|
+
shutil.rmtree(path)
|
|
37
|
+
return dest
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class InstallUnlockKernelSpecApp(ipks.InstallIPythonKernelSpecApp):
|
|
41
|
+
name = Unicode("ipyku-kernel-install")
|
|
42
|
+
|
|
43
|
+
def start(self) -> None:
|
|
44
|
+
import argparse
|
|
45
|
+
|
|
46
|
+
parser = argparse.ArgumentParser(prog=self.name, description="Install the Unlock kernel spec.")
|
|
47
|
+
parser.add_argument("--user", action="store_true", help="Install for the current user instead of system-wide")
|
|
48
|
+
parser.add_argument("--name", type=str, default=KERNEL_NAME,
|
|
49
|
+
help="Specify a name for the kernelspec. This is needed to have multiple kernels.")
|
|
50
|
+
parser.add_argument("--display-name", type=str, help="Specify the display name for the kernelspec.")
|
|
51
|
+
parser.add_argument("--profile", type=str, help="Specify an IPython profile to load.")
|
|
52
|
+
parser.add_argument("--prefix", type=str, help="Specify an install prefix for the kernelspec.")
|
|
53
|
+
parser.add_argument("--sys-prefix", action="store_const", const=sys.prefix, dest="prefix",
|
|
54
|
+
help="Install to Python's sys.prefix.")
|
|
55
|
+
parser.add_argument("--env", action="append", nargs=2, metavar=("ENV", "VALUE"),
|
|
56
|
+
help="Set environment variables for the kernel.")
|
|
57
|
+
parser.add_argument("--frozen_modules", action="store_true", help="Enable frozen modules for faster startup.")
|
|
58
|
+
opts = parser.parse_args(self.argv)
|
|
59
|
+
if opts.env: opts.env = dict(opts.env)
|
|
60
|
+
try:
|
|
61
|
+
dest = install(user=opts.user, kernel_name=opts.name, profile=opts.profile, prefix=opts.prefix,
|
|
62
|
+
display_name=opts.display_name, env=opts.env, frozen_modules=opts.frozen_modules)
|
|
63
|
+
except OSError as e:
|
|
64
|
+
if e.errno == errno.EACCES:
|
|
65
|
+
print(e, file=sys.stderr)
|
|
66
|
+
if opts.user: print("Perhaps you want `sudo` or `--user`?", file=sys.stderr)
|
|
67
|
+
self.exit(1)
|
|
68
|
+
raise
|
|
69
|
+
print(f"Installed kernelspec {opts.name} in {dest}")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from ipykernel.ipkernel import IPythonKernel
|
|
2
|
+
import contextlib
|
|
3
|
+
from . import __version__
|
|
4
|
+
|
|
5
|
+
class UnlockKernel(IPythonKernel):
|
|
6
|
+
implementation = "unlock-kernel"
|
|
7
|
+
implementation_version = __version__
|
|
8
|
+
language = "python"
|
|
9
|
+
language_version = "3.x"
|
|
10
|
+
language_info = dict(name="python", mimetype="text/x-python",
|
|
11
|
+
file_extension=".py", nbconvert_exporter="python")
|
|
12
|
+
banner = "Unlock kernel"
|
|
13
|
+
|
|
14
|
+
def __init__(self, *args, **kwargs):
|
|
15
|
+
super().__init__(*args, **kwargs)
|
|
16
|
+
self._main_asyncio_lock = contextlib.nullcontext()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ipyk-unlock
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Minimal custom ipykernel launcher using a custom kernel subclass
|
|
5
|
+
Project-URL: Homepage, https://github.com/fastai/ipyk-unlock
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: ipykernel>=7.1
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest; extra == "dev"
|
|
11
|
+
Requires-Dist: fastship>=0.0.6; extra == "dev"
|
|
12
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
13
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
14
|
+
|
|
15
|
+
# ipyk-unlock
|
|
16
|
+
|
|
17
|
+
Minimal custom `ipykernel` launcher that swaps in `ipyk_unlock.unlock_kernel.UnlockKernel`.
|
|
18
|
+
|
|
19
|
+
## Run
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
python -m ipyku_launcher -f /path/to/connection.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Install kernelspec
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m ipyku_launcher install --sys-prefix
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Default kernelspec name is `python3-unlock` (on Python 3).
|
|
32
|
+
|
|
33
|
+
## Install (local)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -e .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For release tooling:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -e .[dev]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Use in a kernelspec
|
|
46
|
+
|
|
47
|
+
Set `argv` in `kernel.json` to:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
["python", "-m", "ipyku_launcher", "-f", "{connection_file}"]
|
|
51
|
+
```
|
|
52
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
ipyku_launcher.py,sha256=NT0Q15g38eGQGAhYPNU9Ar1O-eePBILBJg66Qa9f-HE,411
|
|
2
|
+
ipyk_unlock/__init__.py,sha256=jZj21dSYQnFUE7VLVWjrTz9_lDA7p_B4-JRklgZS3ok,125
|
|
3
|
+
ipyk_unlock/kernelapp.py,sha256=GXjkPhyk2F6N4zmqQuCUnhsJJVOxBOqJJIpnKjnNzmc,468
|
|
4
|
+
ipyk_unlock/kernelspec.py,sha256=VvPAS8WvGeViHCjAKtmc8_qJPVsfBCoVWPFnouVPl34,3854
|
|
5
|
+
ipyk_unlock/unlock_kernel.py,sha256=l5u8YHW34z0OEDDb7FG69duUE4dJ7_5DM-atXZaOWus,570
|
|
6
|
+
ipyk_unlock-0.1.1.dist-info/METADATA,sha256=ocKg2fxA55I6-yOJWJm-Q7WxGBVNkMUF2TBwCJ5Q5HE,1040
|
|
7
|
+
ipyk_unlock-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
+
ipyk_unlock-0.1.1.dist-info/entry_points.txt,sha256=QIXY9X4Dqs-uWqin_zloGx5rvATs4-DcM5u1OTm1djo,55
|
|
9
|
+
ipyk_unlock-0.1.1.dist-info/top_level.txt,sha256=cT4vDFhvsHlFRCs2lGq3E6QpPCGhyfWfC1PO4FCSWCc,27
|
|
10
|
+
ipyk_unlock-0.1.1.dist-info/RECORD,,
|
ipyku_launcher.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Entry point for launching an IPython kernel.
|
|
3
|
+
|
|
4
|
+
This is separate from the ipykernel package so we can avoid doing imports until
|
|
5
|
+
after removing the cwd from sys.path.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
if sys.path[0] == "" or Path(sys.path[0]) == Path.cwd(): del sys.path[0]
|
|
14
|
+
from ipyk_unlock import kernelapp as app
|
|
15
|
+
app.launch_new_instance()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__": main()
|