From 47677de744528c009e743dcf3be32eb366099e11 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 18 Nov 2021 22:40:44 +0530 Subject: [PATCH] Drop support for python 3.6 It is being EOLed next month (https://www.python.org/dev/peps/pep-0494/) which is when I expect the next kitty release as well --- .github/workflows/ci.yml | 6 +++--- __main__.py | 1 - gen-apc-parsers.py | 1 - gen-config.py | 1 - gen-key-constants.py | 1 - gen-wcwidth.py | 9 ++++----- kitty/constants.py | 16 ++-------------- kitty_tests/main.py | 8 +------- publish.py | 19 +++++++++---------- setup.py | 41 ++++++++++++++++++++-------------------- test.py | 1 - 11 files changed, 39 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0979d9a7c7..2043f133fbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,15 +20,15 @@ jobs: cc: [gcc, clang] include: - python: a - pyver: 3.6 + pyver: 3.7 sanitize: 0 - python: b - pyver: 3.7 + pyver: 3.8 sanitize: 1 - python: c - pyver: 3.8 + pyver: 3.9 sanitize: 1 diff --git a/__main__.py b/__main__.py index d133efb79f5..f668b990a0d 100644 --- a/__main__.py +++ b/__main__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal import os diff --git a/gen-apc-parsers.py b/gen-apc-parsers.py index 9f8557cc51c..67067101a72 100755 --- a/gen-apc-parsers.py +++ b/gen-apc-parsers.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2018, Kovid Goyal import subprocess diff --git a/gen-config.py b/gen-config.py index 56b566bd22b..c690b0c78e6 100755 --- a/gen-config.py +++ b/gen-config.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/gen-key-constants.py b/gen-key-constants.py index 88f570c15ea..81e366f8507 100755 --- a/gen-key-constants.py +++ b/gen-key-constants.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import string diff --git a/gen-wcwidth.py b/gen-wcwidth.py index 3a4a8a2083e..0c567130795 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import os @@ -255,7 +254,7 @@ def write_case(spec: Union[Tuple[int, ...], int], p: Callable[..., None]) -> Non if isinstance(spec, tuple): p('\t\tcase 0x{:x} ... 0x{:x}:'.format(*spec)) else: - p('\t\tcase 0x{:x}:'.format(spec)) + p(f'\t\tcase 0x{spec:x}:') @contextmanager @@ -353,10 +352,10 @@ def classes_to_regex(classes: Iterable[str], exclude: str = '') -> Iterable[str] def as_string(codepoint: int) -> str: if codepoint < 256: - return r'\x{:02x}'.format(codepoint) + return fr'\x{codepoint:02x}' if codepoint <= 0xffff: - return r'\u{:04x}'.format(codepoint) - return r'\U{:08x}'.format(codepoint) + return fr'\u{codepoint:04x}' + return fr'\U{codepoint:08x}' for spec in get_ranges(list(chars)): if isinstance(spec, tuple): diff --git a/kitty/constants.py b/kitty/constants.py index bd3cc1c226e..98362561c28 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -181,24 +181,12 @@ def resolve_custom_file(path: str) -> str: def list_kitty_resources(package: str = 'kitty') -> Iterable[str]: - if sys.version_info < (3, 7): - from importlib_resources import files - - def contents(package: str) -> Iterable[str]: - return (path.name for path in files(package).iterdir()) - else: - from importlib.resources import contents + from importlib.resources import contents return contents(package) def read_kitty_resource(name: str, package_name: str = 'kitty') -> bytes: - if sys.version_info < (3, 7): - from importlib_resources import files - - def read_binary(package: str, resource: str) -> bytes: - return (files(package) / resource).read_bytes() - else: - from importlib.resources import read_binary + from importlib.resources import read_binary return read_binary(package_name, name) diff --git a/kitty_tests/main.py b/kitty_tests/main.py index a0c71df25f2..a6ff84794bc 100644 --- a/kitty_tests/main.py +++ b/kitty_tests/main.py @@ -8,13 +8,7 @@ from typing import Callable, Generator, NoReturn, Sequence, Set, Iterable -if sys.version_info < (3, 7): - from importlib_resources import files - - def contents(package: str) -> Iterable[str]: - return (path.name for path in files(package).iterdir()) -else: - from importlib.resources import contents +from importlib.resources import contents def itertests(suite: unittest.TestSuite) -> Generator[unittest.TestCase, None, None]: diff --git a/publish.py b/publish.py index 144f2ba6d9b..0066b3cae26 100755 --- a/publish.py +++ b/publish.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import argparse @@ -28,7 +27,7 @@ raw = f.read() nv = re.search(r'^version: Version\s+=\s+Version\((\d+), (\d+), (\d+)\)', raw, flags=re.MULTILINE) if nv is not None: - version = '%s.%s.%s' % (nv.group(1), nv.group(2), nv.group(3)) + version = f'{nv.group(1)}.{nv.group(2)}.{nv.group(3)}' ap = re.search(r"^appname: str\s+=\s+'([^']+)'", raw, flags=re.MULTILINE) if ap is not None: appname = ap.group(1) @@ -68,7 +67,7 @@ def run_build(args: Any) -> None: def run_tag(args: Any) -> None: call('git push') call('git tag -s v{0} -m version-{0}'.format(version)) - call('git push origin v{0}'.format(version)) + call(f'git push origin v{version}') def run_man(args: Any) -> None: @@ -197,7 +196,7 @@ def write(*args: str) -> None: # }}} -class Base(object): # {{{ +class Base: # {{{ def info(self, *args: Any, **kwargs: Any) -> None: print(*args, **kwargs) @@ -293,7 +292,7 @@ def clean_older_releases(self, releases: Iterable[Dict[str, Any]]) -> None: release['tag_name']) for asset in release['assets']: r = self.requests.delete( - self.API + 'repos/%s/%s/releases/assets/%s' % ( + self.API + 'repos/{}/{}/releases/assets/{}'.format( self.username, self.reponame, asset['id'])) if r.status_code != 204: self.fail( @@ -303,7 +302,7 @@ def clean_older_releases(self, releases: Iterable[Dict[str, Any]]) -> None: def do_upload(self, url: str, path: str, desc: str, fname: str) -> requests.Response: mime_type = mimetypes.guess_type(fname)[0] or 'application/octet-stream' - self.info('Uploading to GitHub: %s (%s)' % (fname, mime_type)) + self.info(f'Uploading to GitHub: {fname} ({mime_type})') with ReadFileWithProgressReporting(path) as f: return self.requests.post( url, @@ -325,7 +324,7 @@ def already_exists(self, r: requests.Response) -> bool: return bool(error_code == 'already_exists') def existing_assets(self, release_id: str) -> Dict[str, str]: - url = self.API + 'repos/%s/%s/releases/%s/assets' % ( + url = self.API + 'repos/{}/{}/releases/{}/assets'.format( self.username, self.reponame, release_id) r = self.requests.get(url) if r.status_code != 200: @@ -341,7 +340,7 @@ def create_release(self) -> Dict[str, Any]: return dict(r.json()) if self.is_nightly: raise SystemExit('No existing nightly release found on GitHub') - url = self.API + 'repos/%s/%s/releases' % (self.username, self.reponame) + url = self.API + f'repos/{self.username}/{self.reponame}/releases' r = self.requests.post( url, data=json.dumps({ @@ -413,7 +412,7 @@ def current_branch() -> str: def require_git_master(branch: str = 'master') -> None: if current_branch() != branch: - raise SystemExit('You must be in the {} git branch'.format(branch)) + raise SystemExit(f'You must be in the {branch} git branch') def safe_read(path: str) -> str: @@ -490,7 +489,7 @@ def main() -> None: del actions[1:] else: try: - ans = input('Publish version \033[91m{}\033[m (y/n): '.format(version)) + ans = input(f'Publish version \033[91m{version}\033[m (y/n): ') except KeyboardInterrupt: ans = 'n' if ans.lower() != 'y': diff --git a/setup.py b/setup.py index 9bb94d1cbe4..2e311ddd0ef 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import argparse @@ -27,8 +26,8 @@ from glfw import glfw from glfw.glfw import Command, CompileKey -if sys.version_info[:2] < (3, 6): - raise SystemExit('kitty requires python >= 3.6') +if sys.version_info[:2] < (3, 7): + raise SystemExit('kitty requires python >= 3.7') base = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, base) del sys.path[0] @@ -104,7 +103,7 @@ def pkg_config(pkg: str, *args: str) -> List[str]: ) ) except subprocess.CalledProcessError: - raise SystemExit('The package {} was not found on your system'.format(error(pkg))) + raise SystemExit(f'The package {error(pkg)} was not found on your system') def pkg_version(package: str) -> Tuple[int, int]: @@ -118,7 +117,7 @@ def pkg_version(package: str) -> Tuple[int, int]: def at_least_version(package: str, major: int, minor: int = 0) -> None: - q = '{}.{}'.format(major, minor) + q = f'{major}.{minor}' if subprocess.run([PKGCONFIG, package, '--atleast-version=' + q] ).returncode != 0: qmajor = qminor = 0 @@ -185,10 +184,10 @@ def get_python_flags(cflags: List[str]) -> List[str]: if fw: for var in 'data include stdlib'.split(): val = sysconfig.get_path(var) - if val and '/{}.framework'.format(fw) in val: - fdir = val[:val.index('/{}.framework'.format(fw))] + if val and f'/{fw}.framework' in val: + fdir = val[:val.index(f'/{fw}.framework')] if os.path.isdir( - os.path.join(fdir, '{}.framework'.format(fw)) + os.path.join(fdir, f'{fw}.framework') ): framework_dir = fdir break @@ -406,8 +405,8 @@ def kitty_env() -> Env: # We add 4000 to the primary version because vim turns on SGR mouse mode # automatically if this version is high enough cppflags = ans.cppflags - cppflags.append('-DPRIMARY_VERSION={}'.format(version[0] + 4000)) - cppflags.append('-DSECONDARY_VERSION={}'.format(version[1])) + cppflags.append(f'-DPRIMARY_VERSION={version[0] + 4000}') + cppflags.append(f'-DSECONDARY_VERSION={version[1]}') cppflags.append('-DXT_VERSION="{}"'.format('.'.join(map(str, version)))) at_least_version('harfbuzz', 1, 5) cflags.extend(pkg_config('libpng', '--cflags-only-I')) @@ -484,7 +483,7 @@ def get_vcs_rev_defines(env: Env, src: str) -> List[str]: with open(os.path.join(gitloc, 'refs/heads/master')) as f: rev = f.read() - ans.append('KITTY_VCS_REV="{}"'.format(rev.strip())) + ans.append(f'KITTY_VCS_REV="{rev.strip()}"') return ans @@ -573,9 +572,9 @@ def wait() -> None: if verbose: print(' '.join(compile_cmd.cmd)) elif isatty: - print('\r\x1b[K[{}/{}] {}'.format(num, total, compile_cmd.desc), end='') + print(f'\r\x1b[K[{num}/{total}] {compile_cmd.desc}', end='') else: - print('[{}/{}] {}'.format(num, total, compile_cmd.desc), flush=True) + print(f'[{num}/{total}] {compile_cmd.desc}', flush=True) printed = True w = subprocess.Popen(compile_cmd.cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) workers[w.pid] = compile_cmd, w @@ -696,12 +695,12 @@ def compile_c_extension( cmd = kenv.cc + ['-MMD'] + cppflags + kenv.cflags cmd += ['-c', src] + ['-o', dest] key = CompileKey(original_src, os.path.basename(dest)) - desc = 'Compiling {} ...'.format(emphasis(desc_prefix + src)) + desc = f'Compiling {emphasis(desc_prefix + src)} ...' compilation_database.add_command(desc, cmd, partial(newer, dest, *dependecies_for(src, dest, headers)), key=key, keyfile=src) dest = os.path.join(build_dir, module + '.so') real_dest = module + '.so' os.makedirs(os.path.dirname(dest), exist_ok=True) - desc = 'Linking {} ...'.format(emphasis(desc_prefix + module)) + desc = f'Linking {emphasis(desc_prefix + module)} ...' # Old versions of clang don't like -pthread being passed to the linker # Don't treat linker warnings as errors (linker generates spurious # warnings on some old systems) @@ -755,7 +754,7 @@ def compile_glfw(compilation_database: CompilationDatabase) -> None: continue compile_c_extension( genv, 'kitty/glfw-' + module, compilation_database, - sources, all_headers, desc_prefix='[{}] '.format(module)) + sources, all_headers, desc_prefix=f'[{module}] ') def kittens_env() -> Env: @@ -784,7 +783,7 @@ def files( ) -> Tuple[str, List[str], List[str], str, Sequence[str], Sequence[str]]: sources = list(filter(filter_sources, list(extra_sources) + list_files(os.path.join('kittens', kitten, '*.c')))) headers = list_files(os.path.join('kittens', kitten, '*.h')) + list(extra_headers) - return kitten, sources, headers, 'kittens/{}/{}'.format(kitten, output), includes, libraries + return kitten, sources, headers, f'kittens/{kitten}/{output}', includes, libraries for kitten, sources, all_headers, dest, includes, libraries in ( files('unicode_input', 'unicode_names'), @@ -848,8 +847,8 @@ def build_launcher(args: Options, launcher_dir: str = '.', bundle_type: str = 's cflags.append('-O3') if bundle_type.endswith('-freeze'): cppflags.append('-DFOR_BUNDLE') - cppflags.append('-DPYVER="{}"'.format(sysconfig.get_python_version())) - cppflags.append('-DKITTY_LIB_DIR_NAME="{}"'.format(args.libdir_name)) + cppflags.append(f'-DPYVER="{sysconfig.get_python_version()}"') + cppflags.append(f'-DKITTY_LIB_DIR_NAME="{args.libdir_name}"') elif bundle_type == 'source': cppflags.append('-DFROM_SOURCE') if bundle_type.startswith('macos-'): @@ -859,8 +858,8 @@ def build_launcher(args: Options, launcher_dir: str = '.', bundle_type: str = 's elif bundle_type == 'source': klp = os.path.relpath('.', launcher_dir) else: - raise SystemExit('Unknown bundle type: {}'.format(bundle_type)) - cppflags.append('-DKITTY_LIB_PATH="{}"'.format(klp)) + raise SystemExit(f'Unknown bundle type: {bundle_type}') + cppflags.append(f'-DKITTY_LIB_PATH="{klp}"') pylib = get_python_flags(cflags) cppflags += shlex.split(os.environ.get('CPPFLAGS', '')) cflags += shlex.split(os.environ.get('CFLAGS', '')) diff --git a/test.py b/test.py index bad48976c5e..eb27cd99cdf 100755 --- a/test.py +++ b/test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import importlib