# support


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

Check and install kernel support in a selected Python environment.

`KERNEL_PACKAGES` lists the required distributions.
[`as_installed`](https://vedicreader.github.io/kunda/support.html#as_installed)
adds versions from the host environment.

``` python
HOST_PY, INSPECTOR, KERNEL_PACKAGES
```

    ((3, 11),
     ('dhrishti',),
     ('ipykernel', 'ipymini', 'kernmini', 'fastcore', 'microio'))

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L38"
target="_blank" style="float:right; font-size:smaller">source</a>

### work_dir

``` python
def work_dir(
    cwd:NoneType=None
):
```

*`cwd` as a string, falling back to a writable directory when the
process inherited `/` or a read-only bundle.*

[`work_dir`](https://vedicreader.github.io/kunda/support.html#work_dir)
returns a supplied directory as text. A missing directory uses the
current working directory.

``` python
work_dir(Path('/repo/notebooks'))
```

    '/repo/notebooks'

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L46"
target="_blank" style="float:right; font-size:smaller">source</a>

### support_paths

``` python
def support_paths():
```

*The `sys.path` entries
[`bootstrap_src`](https://vedicreader.github.io/kunda/spec.html#bootstrap_src)
hands a kernel to borrow from.*

[`support_paths`](https://vedicreader.github.io/kunda/support.html#support_paths)
returns existing absolute import paths. Relative and missing paths are
excluded.

Each interpreter path has one shared probe lock.

``` python
test_is(_lock_for('/a/.venv/bin/python'), _lock_for('/a/.venv/bin/python'))
assert _lock_for('/a/.venv/bin/python') is not _lock_for('/b/.venv/bin/python')
```

[`_run`](https://vedicreader.github.io/kunda/support.html#_run) always
returns `returncode`, `stdout`, and `stderr`. Process-start failures
become a non-zero result.

``` python
p = _run(['/definitely/not/a/python', '-c', 'pass'])
p.returncode, p.stderr
```

    (127, "[Errno 2] No such file or directory: '/definitely/not/a/python'")

[`_last_line`](https://vedicreader.github.io/kunda/support.html#_last_line)
returns the last non-empty line, or an empty string.

``` python
_last_line('Traceback (most recent call last):\n  File "<string>", line 1\nImportError: numpy ABI\n\n')
```

    'ImportError: numpy ABI'

A module probe returns `available`, `version`, and `error`.

``` python
tmp = TemporaryDirectory(); d = Path(tmp.name)
(d/'borrowed.py').write_text('__version__ = "1.2"')
_probe(sys.executable, 'borrowed', paths=[str(d)])
```

    {'available': True, 'version': '1.2', 'error': ''}

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L85"
target="_blank" style="float:right; font-size:smaller">source</a>

### kernel_support

``` python
def kernel_support(
    python
):
```

*Importability of both supported kernel launchers in `python`.*

[`kernel_support`](https://vedicreader.github.io/kunda/support.html#kernel_support)
probes both kernel launchers in the selected interpreter.

``` python
ok = kernel_support(sys.executable)['ipymini']
gone = kernel_support('/definitely/not/a/python')['ipymini']
ok, gone
```

    ({'available': True, 'version': '0.1.21', 'error': ''},
     {'available': False,
      'version': '',
      'error': "[Errno 2] No such file or directory: '/definitely/not/a/python'"})

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L102"
target="_blank" style="float:right; font-size:smaller">source</a>

### import_failure

``` python
def import_failure(
    err
):
```

*Whether bootstrap failed on an inspector import.*

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L91"
target="_blank" style="float:right; font-size:smaller">source</a>

### inspector_support

``` python
def inspector_support(
    python, refresh:bool=False
):
```

*Check whether `python` can import the live-variable inspector,
returning what blocked it if not.*

[`inspector_support`](https://vedicreader.github.io/kunda/support.html#inspector_support)
caches one result per interpreter for `INSPECTOR_TTL` seconds.
[`import_failure`](https://vedicreader.github.io/kunda/support.html#import_failure)
recognizes a missing or broken inspector import.

``` python
inspector_support(sys.executable), import_failure("ModuleNotFoundError: No module named 'dhrishti'")
```

    {'available': False,
     'version': '',
     'error': "ModuleNotFoundError: No module named 'dhrishti'"}

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L107"
target="_blank" style="float:right; font-size:smaller">source</a>

### installable

``` python
def installable(
    python
):
```

*Whether anything may install into `python`. Never this one, and never
inside a signed bundle.*

[`installable`](https://vedicreader.github.io/kunda/support.html#installable)
rejects a missing path, the current interpreter, and interpreters inside
a macOS application bundle.

``` python
installable(sys.executable), installable('/repo/.venv/bin/python')
```

    (False, True)

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L115"
target="_blank" style="float:right; font-size:smaller">source</a>

### as_installed

``` python
def as_installed(
    names:tuple=('ipykernel', 'ipymini', 'kernmini', 'fastcore', 'microio')
):
```

*Pin `names` to the versions this process runs; leave unpinned what it
doesn’t have, so installs stay compatible with the host.*

[`as_installed`](https://vedicreader.github.io/kunda/support.html#as_installed)
pins names to versions installed in the host process.

``` python
as_installed(['fastcore', 'ipymini', 'not_a_real_package'])
```

    ['fastcore==2.2.19', 'ipymini==0.1.21', 'not_a_real_package']

[`_attempts`](https://vedicreader.github.io/kunda/support.html#_attempts)
tries `uv` when available and always includes `python -m pip install`.

``` python
_attempts('/nowhere/bin/python', ['ipymini==0.1.21'])[-1]
```

    ['/nowhere/bin/python', '-m', 'pip', 'install', 'ipymini==0.1.21']

[`_log`](https://vedicreader.github.io/kunda/support.html#_log) records
the command, return code, and bounded output.

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L139"
target="_blank" style="float:right; font-size:smaller">source</a>

### install_kernel_support

``` python
def install_kernel_support(
    python, packages:NoneType=None
):
```

*Install kernel packages via uv or pip; verify the import works after,
so failures name the package not the installer.*

[`install_kernel_support`](https://vedicreader.github.io/kunda/support.html#install_kernel_support)
succeeds only when installation completes and both launchers import.

------------------------------------------------------------------------

<a
href="https://github.com/vedicreader/kunda/blob/main/kunda/support.py#L154"
target="_blank" style="float:right; font-size:smaller">source</a>

### install_inspector_support

``` python
def install_inspector_support(
    python, packages:tuple=('dhrishti',)
):
```

*Give `python` its own copy of what the inspector imports, then ask it
again.*

[`install_inspector_support`](https://vedicreader.github.io/kunda/support.html#install_inspector_support)
installs Dhrishti and probes it again.
