Skip to content

Commit

Permalink
Drop support for python 3.6
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kovidgoyal committed Nov 18, 2021
1 parent bfdb09d commit 47677de
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 65 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion __main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>

import os
Expand Down
1 change: 0 additions & 1 deletion gen-apc-parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>

import subprocess
Expand Down
1 change: 0 additions & 1 deletion gen-config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>


Expand Down
1 change: 0 additions & 1 deletion gen-key-constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>

import string
Expand Down
9 changes: 4 additions & 5 deletions gen-wcwidth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

import os
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 2 additions & 14 deletions kitty/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 1 addition & 7 deletions kitty_tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
19 changes: 9 additions & 10 deletions publish.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

import argparse
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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({
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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':
Expand Down
41 changes: 20 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>

import argparse
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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-'):
Expand All @@ -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', ''))
Expand Down
1 change: 0 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>

import importlib
Expand Down

0 comments on commit 47677de

Please sign in to comment.