Skip to content

Commit

Permalink
fix kernelspec print output (#933)
Browse files Browse the repository at this point in the history
- typos in log -> print migration, where deferred formatting doesn't work
- keep errors written to stderr
  • Loading branch information
minrk authored Feb 16, 2023
1 parent 9df6ac3 commit dc0eaba
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions jupyter_client/kernelspecapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def path_key(item):

print("Available kernels:")
for kernelname, path in sorted(paths.items(), key=path_key):
print(" %s %s", kernelname.ljust(name_len), path)
print(f" {kernelname.ljust(name_len)} {path}")
else:
print(json.dumps({"kernelspecs": specs}, indent=2))
return specs
Expand Down Expand Up @@ -140,7 +140,7 @@ def parse_command_line(self, argv):
if self.extra_args:
self.sourcedir = self.extra_args[0]
else:
print("No source directory specified.")
print("No source directory specified.", file=sys.stderr)
self.exit(1)

def start(self):
Expand All @@ -157,14 +157,12 @@ def start(self):
)
except OSError as e:
if e.errno == errno.EACCES:
print(e)
print(e, file=sys.stderr)
if not self.user:
print(
"Perhaps you want to install with `sudo` or `--user`?",
)
print("Perhaps you want to install with `sudo` or `--user`?", file=sys.stderr)
self.exit(1)
elif e.errno == errno.EEXIST:
print("A kernel spec is already present at %s", e.filename)
print(f"A kernel spec is already present at {e.filename}", file=sys.stderr)
self.exit(1)
raise

Expand Down Expand Up @@ -209,7 +207,8 @@ def start(self):
if not (self.force or self.answer_yes):
print("Kernel specs to remove:")
for name in self.spec_names:
print(" %s\t%s", name.ljust(20), name.ljust(20))
path = spec_paths.get(name, name)
print(f" {name.ljust(20)}\t{path.ljust(20)}")
answer = input("Remove %i kernel specs [y/N]: " % len(self.spec_names))
if not answer.lower().startswith("y"):
return
Expand All @@ -224,7 +223,7 @@ def start(self):
self.exit(1)
else:
raise
print("Removed %s", path)
print(f"Removed {path}")


class InstallNativeKernelSpec(JupyterApp):
Expand Down Expand Up @@ -295,7 +294,7 @@ def start(self):
name_len = len(sorted(provisioners, key=lambda name: len(name))[-1])

for name in sorted(provisioners):
print(" %s %s", name.ljust(name_len), provisioners[name])
print(f" {name.ljust(name_len)} {provisioners[name]}")


class KernelSpecApp(Application):
Expand Down

0 comments on commit dc0eaba

Please sign in to comment.