diff --git a/kitty/boss.py b/kitty/boss.py index 3e4b5e2d8..0dfb8a6a0 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -6,7 +6,6 @@ import atexit import json import os import re -import socket from functools import partial from gettext import gettext as _ from weakref import WeakValueDictionary @@ -43,6 +42,7 @@ def initialize_renderer(): def listen_on(spec): + import socket family, address, socket_path = parse_address_spec(spec) s = socket.socket(family) atexit.register(remove_socket_file, s, socket_path) diff --git a/kitty/cli.py b/kitty/cli.py index b1500a6a5..45689dc82 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -4,7 +4,6 @@ import os import re -import subprocess import sys from collections import deque @@ -349,6 +348,7 @@ def print_help_for_seq(seq, usage, message, appname): text = '\n'.join(blocks) + '\n\n' + version() if print_help_for_seq.allow_pager and sys.stdout.isatty(): + import subprocess p = subprocess.Popen(['less', '-isRXF'], stdin=subprocess.PIPE) p.communicate(text.encode('utf-8')) raise SystemExit(p.wait()) @@ -577,6 +577,7 @@ def create_opts(args, debug_config=False): print(version(add_rev=True)) print(' '.join(os.uname())) if is_macos: + import subprocess print(' '.join(subprocess.check_output(['sw_vers']).decode('utf-8').splitlines()).strip()) else: print('Running under:', green('Wayland' if is_wayland else 'X11')) diff --git a/kitty/config.py b/kitty/config.py index 015cfefb2..63ebdf8f3 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -7,7 +7,6 @@ import json import os import re import sys -import tempfile from collections import namedtuple from contextlib import contextmanager @@ -449,6 +448,7 @@ def build_ansi_color_table(opts=defaults): def atomic_save(data, path): + import tempfile fd, p = tempfile.mkstemp(dir=os.path.dirname(path), suffix='.tmp') try: with os.fdopen(fd, 'wb') as f: diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 5198884c5..14b3b6617 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -4,7 +4,6 @@ import json import re -import socket import sys import types from functools import partial @@ -41,6 +40,7 @@ will only work if this process is run within an existing kitty window. def do_io(to, send, no_response): + import socket send = ('@kitty-cmd' + json.dumps(send)).encode('ascii') send = b'\x1bP' + send + b'\x1b\\' if to: diff --git a/kitty/utils.py b/kitty/utils.py index 723dacc3e..e39eececf 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -8,11 +8,8 @@ import fcntl import math import os import re -import socket import string -import subprocess import sys -import tempfile from contextlib import contextmanager from time import monotonic @@ -121,6 +118,7 @@ def command_for_open(program='default'): def open_cmd(cmd, arg=None, cwd=None): + import subprocess if arg is not None: cmd = list(cmd) cmd.append(arg) @@ -201,6 +199,8 @@ def remove_socket_file(s, path=None): def single_instance_unix(name): + import socket + import tempfile home = os.path.expanduser('~') candidates = [tempfile.gettempdir(), home] if is_macos: @@ -239,6 +239,7 @@ def single_instance_unix(name): def single_instance(group_id=None): + import socket name = '{}-ipc-{}'.format(appname, os.geteuid()) if group_id: name += '-{}'.format(group_id) @@ -264,6 +265,7 @@ def single_instance(group_id=None): def parse_address_spec(spec): + import socket protocol, rest = spec.split(':', 1) socket_path = None if protocol == 'unix':