From f22374ab83f62d712baa6feacc3a663a06435ba9 Mon Sep 17 00:00:00 2001 From: Jelle Licht Date: Thu, 18 Feb 2021 21:16:31 +0100 Subject: [PATCH] kernelspec: ensure path is writable before writing kernel.json. --- ipykernel/kernelspec.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ipykernel/kernelspec.py b/ipykernel/kernelspec.py index 36d3bbcfc..ceaa00be0 100644 --- a/ipykernel/kernelspec.py +++ b/ipykernel/kernelspec.py @@ -7,6 +7,7 @@ import json import os import shutil +import stat import sys import tempfile @@ -70,6 +71,12 @@ def write_kernel_spec(path=None, overrides=None, extra_arguments=None): # stage resources shutil.copytree(RESOURCES, path) + + # ensure path is writable + mask = os.stat(path).st_mode + if not mask & stat.S_IWUSR + os.chmod(path, mask | stat.S_IWUSR) + # write kernel.json kernel_dict = get_kernel_dict(extra_arguments)