ipyk-unlock 0.1.1__tar.gz

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.
@@ -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,38 @@
1
+ # ipyk-unlock
2
+
3
+ Minimal custom `ipykernel` launcher that swaps in `ipyk_unlock.unlock_kernel.UnlockKernel`.
4
+
5
+ ## Run
6
+
7
+ ```bash
8
+ python -m ipyku_launcher -f /path/to/connection.json
9
+ ```
10
+
11
+ ## Install kernelspec
12
+
13
+ ```bash
14
+ python -m ipyku_launcher install --sys-prefix
15
+ ```
16
+
17
+ Default kernelspec name is `python3-unlock` (on Python 3).
18
+
19
+ ## Install (local)
20
+
21
+ ```bash
22
+ pip install -e .
23
+ ```
24
+
25
+ For release tooling:
26
+
27
+ ```bash
28
+ pip install -e .[dev]
29
+ ```
30
+
31
+ ## Use in a kernelspec
32
+
33
+ Set `argv` in `kernel.json` to:
34
+
35
+ ```json
36
+ ["python", "-m", "ipyku_launcher", "-f", "{connection_file}"]
37
+ ```
38
+
@@ -0,0 +1,6 @@
1
+ __version__ = "0.1.1"
2
+
3
+
4
+ from .kernelapp import UnlockKernelApp, launch_new_instance
5
+ from .unlock_kernel import UnlockKernel
6
+
@@ -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,13 @@
1
+ README.md
2
+ ipyku_launcher.py
3
+ pyproject.toml
4
+ ipyk_unlock/__init__.py
5
+ ipyk_unlock/kernelapp.py
6
+ ipyk_unlock/kernelspec.py
7
+ ipyk_unlock/unlock_kernel.py
8
+ ipyk_unlock.egg-info/PKG-INFO
9
+ ipyk_unlock.egg-info/SOURCES.txt
10
+ ipyk_unlock.egg-info/dependency_links.txt
11
+ ipyk_unlock.egg-info/entry_points.txt
12
+ ipyk_unlock.egg-info/requires.txt
13
+ ipyk_unlock.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ipyku-launcher = ipyku_launcher:main
@@ -0,0 +1,7 @@
1
+ ipykernel>=7.1
2
+
3
+ [dev]
4
+ pytest
5
+ fastship>=0.0.6
6
+ build>=1.0.0
7
+ twine>=5.0.0
@@ -0,0 +1,2 @@
1
+ ipyk_unlock
2
+ ipyku_launcher
@@ -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()
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ipyk-unlock"
7
+ dynamic = ["version"]
8
+ description = "Minimal custom ipykernel launcher using a custom kernel subclass"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = ["ipykernel>=7.1"]
12
+
13
+ [project.optional-dependencies]
14
+ dev = ["pytest", "fastship>=0.0.6", "build>=1.0.0", "twine>=5.0.0"]
15
+
16
+ [project.urls]
17
+ Homepage = "https://github.com/fastai/ipyk-unlock"
18
+
19
+ [project.scripts]
20
+ ipyku-launcher = "ipyku_launcher:main"
21
+
22
+ [tool.setuptools.dynamic]
23
+ version = { attr = "ipyk_unlock.__version__" }
24
+
25
+ [tool.setuptools]
26
+ packages = ["ipyk_unlock"]
27
+ py-modules = ["ipyku_launcher"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+