1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-01 10:52:19 +01:00

Drop Python 2 Support (#793)

* Remove Python 2 support

* Remove u-strings

* Remove docker symlinks

* Remove from travis

* Update requirements

* Upgrade flake8/pylint

* Fixes

* Manual

* Run pyupgrade

* Lint

* Remove base_int

* Fix

* Update platformio_api.py

* Update component.cpp
This commit is contained in:
Otto Winter
2019-12-07 18:28:55 +01:00
committed by GitHub
parent b5714cd70f
commit 056c72d50d
78 changed files with 815 additions and 1097 deletions

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: api_options.proto

View File

@@ -39,12 +39,12 @@ content = prot.read_bytes()
d = descriptor.FileDescriptorSet.FromString(content)
def indent_list(text, padding=u' '):
def indent_list(text, padding=' '):
return [padding + line for line in text.splitlines()]
def indent(text, padding=u' '):
return u'\n'.join(indent_list(text, padding))
def indent(text, padding=' '):
return '\n'.join(indent_list(text, padding))
def camel_to_snake(name):
@@ -432,7 +432,7 @@ class SInt64Type(TypeInfo):
class RepeatedTypeInfo(TypeInfo):
def __init__(self, field):
super(RepeatedTypeInfo, self).__init__(field)
super().__init__(field)
self._ti = TYPE_INFO[field.type](field)
@property

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
import os.path

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
#!/usr/bin/env python3
import codecs
import collections
@@ -105,7 +104,7 @@ def lint_re_check(regex, **kwargs):
err = func(fname, match)
if err is None:
continue
errors.append("{} See line {}.".format(err, lineno))
errors.append(f"{err} See line {lineno}.")
return errors
return decor(new_func)
return decorator
@@ -134,7 +133,7 @@ def lint_ino(fname):
return "This file extension (.ino) is not allowed. Please use either .cpp or .h"
@lint_file_check(exclude=['*{}'.format(f) for f in file_types] + [
@lint_file_check(exclude=[f'*{f}' for f in file_types] + [
'.clang-*', '.dockerignore', '.editorconfig', '*.gitignore', 'LICENSE', 'pylintrc',
'MANIFEST.in', 'docker/Dockerfile*', 'docker/rootfs/*', 'script/*',
])
@@ -177,7 +176,7 @@ CPP_RE_EOL = r'\s*?(?://.*?)?$'
def highlight(s):
return '\033[36m{}\033[0m'.format(s)
return f'\033[36m{s}\033[0m'
@lint_re_check(r'^#define\s+([a-zA-Z0-9_]+)\s+([0-9bx]+)' + CPP_RE_EOL,
@@ -268,7 +267,7 @@ def lint_constants_usage():
def relative_cpp_search_text(fname, content):
parts = fname.split('/')
integration = parts[2]
return '#include "esphome/components/{}'.format(integration)
return f'#include "esphome/components/{integration}'
@lint_content_find_check(relative_cpp_search_text, include=['esphome/components/*.cpp'])
@@ -284,7 +283,7 @@ def lint_relative_cpp_import(fname):
def relative_py_search_text(fname, content):
parts = fname.split('/')
integration = parts[2]
return 'esphome.components.{}'.format(integration)
return f'esphome.components.{integration}'
@lint_content_find_check(relative_py_search_text, include=['esphome/components/*.py'],
@@ -303,7 +302,7 @@ def lint_relative_py_import(fname):
def lint_namespace(fname, content):
expected_name = re.match(r'^esphome/components/([^/]+)/.*',
fname.replace(os.path.sep, '/')).group(1)
search = 'namespace {}'.format(expected_name)
search = f'namespace {expected_name}'
if search in content:
return None
return 'Invalid namespace found in C++ file. All integration C++ files should put all ' \
@@ -380,7 +379,7 @@ for fname in files:
run_checks(LINT_POST_CHECKS, 'POST')
for f, errs in sorted(errors.items()):
print("\033[0;32m************* File \033[1;32m{}\033[0m".format(f))
print(f"\033[0;32m************* File \033[1;32m{f}\033[0m")
for err in errs:
print(err)
print()

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import print_function

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import print_function

View File

@@ -12,11 +12,11 @@ temp_header_file = os.path.join(root_path, '.temp-clang-tidy.cpp')
def shlex_quote(s):
if not s:
return u"''"
return "''"
if re.search(r'[^\w@%+=:,./-]', s) is None:
return s
return u"'" + s.replace(u"'", u"'\"'\"'") + u"'"
return "'" + s.replace("'", "'\"'\"'") + "'"
def build_all_include():
@@ -29,7 +29,7 @@ def build_all_include():
if ext in filetypes:
path = os.path.relpath(path, root_path)
include_p = path.replace(os.path.sep, '/')
headers.append('#include "{}"'.format(include_p))
headers.append(f'#include "{include_p}"')
headers.sort()
headers.append('')
content = '\n'.join(headers)
@@ -47,7 +47,7 @@ def build_compile_commands():
gcc_flags = json.load(f)
exec_path = gcc_flags['execPath']
include_paths = gcc_flags['gccIncludePaths'].split(',')
includes = ['-I{}'.format(p) for p in include_paths]
includes = [f'-I{p}' for p in include_paths]
cpp_flags = gcc_flags['gccDefaultCppFlags'].split(' ')
defines = [flag for flag in cpp_flags if flag.startswith('-D')]
command = [exec_path]
@@ -102,7 +102,7 @@ def splitlines_no_ends(string):
def changed_files():
for remote in ('upstream', 'origin'):
command = ['git', 'merge-base', '{}/dev'.format(remote), 'HEAD']
command = ['git', 'merge-base', f'{remote}/dev', 'HEAD']
try:
merge_base = splitlines_no_ends(get_output(*command))[0]
break
@@ -124,7 +124,7 @@ def filter_changed(files):
if not files:
print(" No changed files!")
for c in files:
print(" {}".format(c))
print(f" {c}")
return files

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import print_function
@@ -61,7 +61,7 @@ def main():
continue
file_ = line[0]
linno = line[1]
msg = (u':'.join(line[3:])).strip()
msg = (':'.join(line[3:])).strip()
print_error(file_, linno, msg)
errors += 1
@@ -74,7 +74,7 @@ def main():
continue
file_ = line[0]
linno = line[1]
msg = (u':'.join(line[2:])).strip()
msg = (':'.join(line[2:])).strip()
print_error(file_, linno, msg)
errors += 1