Files
gw-basic-2026/gwbasickernel/install.py
Eremey Valetov 3e8aaa298b Implement Jupyter kernel for GW-BASIC 2026
Persistent subprocess model: gwbasic reads BASIC from stdin and writes
output to stdout in piped mode (no banner, no prompts, unbuffered).
Sentinel protocol (PRINT "<<<GWDONE>>>") delimits output per cell.

Features: state persistence across cells, error detection and reporting,
tab completion for GW-BASIC keywords, %reset/%timeout/%new magic
commands, Ctrl+C forwarding, automatic process restart.

Includes setup.py for pip install, kernel.json spec, install script,
and 10-test smoke suite (all passing).
2026-03-29 05:51:37 -04:00

49 lines
1.5 KiB
Python

"""Install the GW-BASIC kernel into Jupyter."""
import argparse
import shutil
import sys
import tempfile
from pathlib import Path
def install_kernel(user=True, prefix=None):
from jupyter_client.kernelspec import KernelSpecManager
kernel_json = Path(__file__).parent / 'kernel.json'
with tempfile.TemporaryDirectory() as td:
dest = Path(td) / 'gwbasic'
dest.mkdir()
shutil.copy(kernel_json, dest / 'kernel.json')
ksm = KernelSpecManager()
ksm.install_kernel_spec(
str(dest), kernel_name='gwbasic', user=user, prefix=prefix,
)
print('GW-BASIC kernel installed successfully.')
print('Run "jupyter kernelspec list" to verify.')
def main():
parser = argparse.ArgumentParser(description='Install the GW-BASIC Jupyter kernel')
parser.add_argument('--user', action='store_true', default=True,
help='Install for the current user (default)')
parser.add_argument('--sys-prefix', action='store_true',
help='Install into sys.prefix (for virtualenvs)')
parser.add_argument('--prefix', type=str, default=None,
help='Install into a specific prefix')
args = parser.parse_args()
if args.sys_prefix:
install_kernel(user=False, prefix=sys.prefix)
elif args.prefix:
install_kernel(user=False, prefix=args.prefix)
else:
install_kernel(user=args.user)
if __name__ == '__main__':
main()