diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 35ccc993c9..780dbf8186 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,7 +63,7 @@ variables: BOT_DOCKER_IMAGE_TAG: ":latest" ESP_IDF_DOC_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-3" - ESP_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-env-v5.0:2" + ESP_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-env-v5.0:3" AFL_FUZZER_TEST_IMAGE: "$CI_DOCKER_REGISTRY/afl-fuzzer-test-v5.0:2-1" CLANG_STATIC_ANALYSIS_IMAGE: "${CI_DOCKER_REGISTRY}/clang-static-analysis-v5.0:2-1" TARGET_TEST_ENV_IMAGE: "$CI_DOCKER_REGISTRY/target-test-env-v5.0:2" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 632952fb7a..8d4d2fdf49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,7 @@ repos: args: ['-f=lf'] - id: double-quote-string-fixer - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + rev: 5.0.4 hooks: - id: flake8 args: ['--config=.flake8', '--tee', '--benchmark'] diff --git a/components/espcoredump/espcoredump.py b/components/espcoredump/espcoredump.py index 0dc03dd603..b17f234b56 100755 --- a/components/espcoredump/espcoredump.py +++ b/components/espcoredump/espcoredump.py @@ -51,8 +51,8 @@ def main(): # type: () -> None # pass the extra_gdbinit_file if the build is reproducible kwargs['extra_gdbinit_file'] = get_prefix_map_gdbinit_path(kwargs['prog']) - del(kwargs['debug']) - del(kwargs['operation']) + del kwargs['debug'] + del kwargs['operation'] espcoredump = CoreDump(**kwargs) temp_core_files = None diff --git a/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py b/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py index 6c5d18edff..0211514a46 100755 --- a/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py +++ b/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py @@ -107,7 +107,7 @@ class CertificateBundle: if start is True: crt += strg - if(count == 0): + if count == 0: raise InputError('No certificate found') status('Successfully added %d certificates' % count) diff --git a/components/spiffs/spiffsgen.py b/components/spiffs/spiffsgen.py index 9a1dae4ad6..45f84492f8 100755 --- a/components/spiffs/spiffsgen.py +++ b/components/spiffs/spiffsgen.py @@ -167,7 +167,7 @@ class SpiffsObjLuPage(SpiffsPage): img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + SpiffsPage._len_dict[self.build_config.obj_id_len], obj_id) - assert(len(img) <= self.build_config.page_size) + assert len(img) <= self.build_config.page_size img += b'\xFF' * (self.build_config.page_size - len(img)) @@ -249,7 +249,7 @@ class SpiffsObjIndexPage(SpiffsObjPageWithIdx): img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + SpiffsPage._len_dict[self.build_config.page_ix_len], page) - assert(len(img) <= self.build_config.page_size) + assert len(img) <= self.build_config.page_size img += b'\xFF' * (self.build_config.page_size - len(img)) @@ -275,7 +275,7 @@ class SpiffsObjDataPage(SpiffsObjPageWithIdx): img += self.contents - assert(len(img) <= self.build_config.page_size) + assert len(img) <= self.build_config.page_size img += b'\xFF' * (self.build_config.page_size - len(img)) @@ -374,7 +374,7 @@ class SpiffsBlock(object): for page in self.pages: img += page.to_binary() - assert(len(img) <= self.build_config.block_size) + assert len(img) <= self.build_config.block_size img += b'\xFF' * (self.build_config.block_size - len(img)) return img diff --git a/examples/system/esp_timer/pytest_esp_timer.py b/examples/system/esp_timer/pytest_esp_timer.py index 229a95afb8..4a7924282f 100644 --- a/examples/system/esp_timer/pytest_esp_timer.py +++ b/examples/system/esp_timer/pytest_esp_timer.py @@ -48,22 +48,22 @@ def test_esp_timer(dut: Dut) -> None: logging.info('Start time: {} us'.format(start_time)) match = dut.expect(TIMER_DUMP_LINE_REGEX, timeout=2) - assert(match.group(1).decode('utf8') == 'periodic' and int(match.group(2)) == INITIAL_TIMER_PERIOD) + assert match.group(1).decode('utf8') == 'periodic' and int(match.group(2)) == INITIAL_TIMER_PERIOD match = dut.expect(TIMER_DUMP_LINE_REGEX, timeout=2) - assert(match.group(1).decode('utf8') == 'one-shot' and int(match.group(2)) == 0) + assert match.group(1).decode('utf8') == 'one-shot' and int(match.group(2)) == 0 for i in range(0, 5): match = dut.expect(PERIODIC_TIMER_REGEX, timeout=2) cur_time = int(match.group(1)) diff = start_time + (i + 1) * INITIAL_TIMER_PERIOD - cur_time logging.info('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff)) - assert(abs(diff) < 100) + assert abs(diff) < 100 match = dut.expect(ONE_SHOT_REGEX, timeout=3) one_shot_timer_time = int(match.group(1)) diff = start_time + ONE_SHOT_TIMER_PERIOD - one_shot_timer_time logging.info('One-shot timer, time: {} us, diff: {}'.format(one_shot_timer_time, diff)) - assert(abs(diff) < 350) + assert abs(diff) < 350 match = dut.expect(RESTART_REGEX, timeout=3) start_time = int(match.group(1)) @@ -74,7 +74,7 @@ def test_esp_timer(dut: Dut) -> None: cur_time = int(match.group(1)) diff = start_time + (i + 1) * FINAL_TIMER_PERIOD - cur_time logging.info('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff)) - assert(abs(diff) < 100) + assert abs(diff) < 100 match = dut.expect(LIGHT_SLEEP_ENTER_REGEX, timeout=2) sleep_enter_time = int(match.group(1)) @@ -85,13 +85,13 @@ def test_esp_timer(dut: Dut) -> None: logging.info('Enter sleep: {}, exit sleep: {}, slept: {}'.format( sleep_enter_time, sleep_exit_time, sleep_time)) - assert(abs(sleep_time - LIGHT_SLEEP_TIME) < 1000) + assert abs(sleep_time - LIGHT_SLEEP_TIME) < 1000 for i in range(5, 7): match = dut.expect(PERIODIC_TIMER_REGEX, timeout=2) cur_time = int(match.group(1)) diff = abs(start_time + (i + 1) * FINAL_TIMER_PERIOD - cur_time) logging.info('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff)) - assert(diff < 100) + assert diff < 100 dut.expect(STOP_REGEX, timeout=2) diff --git a/examples/system/light_sleep/pytest_light_sleep.py b/examples/system/light_sleep/pytest_light_sleep.py index 4f9025aa59..4b0fc8c9a7 100644 --- a/examples/system/light_sleep/pytest_light_sleep.py +++ b/examples/system/light_sleep/pytest_light_sleep.py @@ -39,7 +39,7 @@ def test_light_sleep(dut: Dut) -> None: match = dut.expect(EXIT_SLEEP_REGEX) logging.info('Got second sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3))) # sleep time error should be less than 1ms - assert(match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1) + assert match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1 # this time we'll test gpio wakeup dut.expect_exact(ENTERING_SLEEP_STR) @@ -48,7 +48,7 @@ def test_light_sleep(dut: Dut) -> None: time.sleep(1) match = dut.expect(EXIT_SLEEP_PIN_REGEX) logging.info('Got third sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3))) - assert(int(match.group(3)) < WAKEUP_INTERVAL_MS) + assert int(match.group(3)) < WAKEUP_INTERVAL_MS dut.expect(WAITING_FOR_GPIO_STR) logging.info('Is waiting for GPIO...') @@ -62,9 +62,9 @@ def test_light_sleep(dut: Dut) -> None: time.sleep(1) match = dut.expect(EXIT_SLEEP_UART_REGEX) logging.info('Got third sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3))) - assert(int(match.group(3)) < WAKEUP_INTERVAL_MS) + assert int(match.group(3)) < WAKEUP_INTERVAL_MS logging.info('Went to sleep again') match = dut.expect(EXIT_SLEEP_REGEX) - assert(match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1) + assert match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1 logging.info('Woke up from timer again') diff --git a/tools/ci/python_packages/ttfw_idf/IDFDUT.py b/tools/ci/python_packages/ttfw_idf/IDFDUT.py index f3d69becc1..aa4e106abb 100644 --- a/tools/ci/python_packages/ttfw_idf/IDFDUT.py +++ b/tools/ci/python_packages/ttfw_idf/IDFDUT.py @@ -216,7 +216,7 @@ class IDFDUT(DUT.SerialDUT): if expected_rom_class and type(inst) != expected_rom_class: raise RuntimeError('Target not expected') return inst.read_mac() is not None, get_target_by_rom_class(type(inst)) - except(FatalError, RuntimeError): + except (FatalError, RuntimeError): return False, None finally: if inst is not None: diff --git a/tools/gen_esp_err_to_name.py b/tools/gen_esp_err_to_name.py index b4957d967c..5d80e02f61 100755 --- a/tools/gen_esp_err_to_name.py +++ b/tools/gen_esp_err_to_name.py @@ -83,9 +83,9 @@ class ErrItem(object): base = '_BASE' if self.file == other.file: - if self.name.endswith(base) and not(other.name.endswith(base)): + if self.name.endswith(base) and not other.name.endswith(base): return 1 - elif not(self.name.endswith(base)) and other.name.endswith(base): + elif not self.name.endswith(base) and other.name.endswith(base): return -1 self_key = self.file + self.name diff --git a/tools/idf_tools.py b/tools/idf_tools.py index eaef2fcee2..37f2b9ce0a 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -599,14 +599,14 @@ class IDFTool(object): self.versions = OrderedDict() # type: Dict[str, IDFToolVersion] def add_version(self, version): # type: (IDFToolVersion) -> None - assert(type(version) is IDFToolVersion) + assert type(version) is IDFToolVersion self.versions[version.version] = version def get_path(self): # type: () -> str return os.path.join(global_idf_tools_path or '', 'tools', self.name) def get_path_for_version(self, version): # type: (str) -> str - assert(version in self.versions) + assert version in self.versions return os.path.join(self.get_path(), version) def get_export_paths(self, version): # type: (str) -> List[str] @@ -732,7 +732,7 @@ class IDFTool(object): self.versions_installed.append(version) def download(self, version): # type: (str) -> None - assert(version in self.versions) + assert version in self.versions download_obj = self.versions[version].get_download_for_platform(self._platform) if not download_obj: fatal('No packages for tool {} platform {}!'.format(self.name, self._platform)) @@ -768,12 +768,12 @@ class IDFTool(object): def install(self, version): # type: (str) -> None # Currently this is called after calling 'download' method, so here are a few asserts # for the conditions which should be true once that method is done. - assert (version in self.versions) + assert version in self.versions download_obj = self.versions[version].get_download_for_platform(self._platform) - assert (download_obj is not None) + assert download_obj is not None archive_name = os.path.basename(download_obj.url) archive_path = os.path.join(global_idf_tools_path or '', 'dist', archive_name) - assert (os.path.isfile(archive_path)) + assert os.path.isfile(archive_path) dest_dir = self.get_path_for_version(version) if os.path.exists(dest_dir): warn('destination path already exists, removing') diff --git a/tools/kconfig_new/gen_kconfig_doc.py b/tools/kconfig_new/gen_kconfig_doc.py index 9cacb27d01..67479921e6 100644 --- a/tools/kconfig_new/gen_kconfig_doc.py +++ b/tools/kconfig_new/gen_kconfig_doc.py @@ -170,7 +170,7 @@ def get_link_anchor(node): try: return 'CONFIG_%s' % node.item.name except AttributeError: - assert(node_is_menu(node)) # only menus should have no item.name + assert node_is_menu(node) # only menus should have no item.name # for menus, build a link anchor out of the parents result = [] diff --git a/tools/ldgen/ldgen/generation.py b/tools/ldgen/ldgen/generation.py index f4e87d849e..2b67dec896 100644 --- a/tools/ldgen/ldgen/generation.py +++ b/tools/ldgen/ldgen/generation.py @@ -134,9 +134,9 @@ class EntityNode: def add_child(self, entity): child_specificity = self.entity.specificity.value + 1 - assert (child_specificity <= Entity.Specificity.SYMBOL.value) + assert child_specificity <= Entity.Specificity.SYMBOL.value name = entity[Entity.Specificity(child_specificity)] - assert (name and name != Entity.ALL) + assert name and name != Entity.ALL child = [c for c in self.children if c.name == name] assert (len(child) <= 1) @@ -174,7 +174,7 @@ class EntityNode: for sections in self.get_output_sections(): placement = self.placements[sections] if placement.is_significant(): - assert (placement.node == self) + assert placement.node == self keep = False sort = None diff --git a/tools/ldgen/ldgen/output_commands.py b/tools/ldgen/ldgen/output_commands.py index 7df4a85210..ae8e2b7027 100644 --- a/tools/ldgen/ldgen/output_commands.py +++ b/tools/ldgen/ldgen/output_commands.py @@ -65,7 +65,7 @@ class InputSectionDesc: """ def __init__(self, entity, sections, exclusions=None, keep=False, sort=None): - assert (entity.specificity != Entity.Specificity.SYMBOL) + assert entity.specificity != Entity.Specificity.SYMBOL self.entity = entity self.sections = set(sections) @@ -73,8 +73,8 @@ class InputSectionDesc: self.exclusions = set() if exclusions: - assert (not [e for e in exclusions if e.specificity == Entity.Specificity.SYMBOL or - e.specificity == Entity.Specificity.NONE]) + assert not [e for e in exclusions if e.specificity == Entity.Specificity.SYMBOL or + e.specificity == Entity.Specificity.NONE] self.exclusions = set(exclusions) else: self.exclusions = set() diff --git a/tools/mkuf2.py b/tools/mkuf2.py index e76bae895f..393338d08e 100755 --- a/tools/mkuf2.py +++ b/tools/mkuf2.py @@ -66,7 +66,7 @@ class UF2Writer(object): md5_part = self._to_uint32(addr) md5_part += self._to_uint32(len_chunk) md5_part += hashlib.md5(chunk).digest() - assert(len(md5_part) == self.UF2_MD5_PART_SIZE) + assert len(md5_part) == self.UF2_MD5_PART_SIZE block += md5_part block += b'\x00' * (self.UF2_DATA_SIZE - self.UF2_MD5_PART_SIZE - len_chunk) diff --git a/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py b/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py index c4f28d27b9..f87c376357 100644 --- a/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py +++ b/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py @@ -31,7 +31,7 @@ def set_server_cert_cn(ip): '-CAkey', _path('ca.key'), '-CAcreateserial', '-out', _path('srv.crt'), '-days', '360']] for args in arg_list: if subprocess.check_call(args) != 0: - raise('openssl command {} failed'.format(args)) + raise RuntimeError('openssl command {} failed'.format(args)) # Publisher class creating a python client to send/receive published data from esp-mqtt client @@ -264,7 +264,7 @@ def connection_tests(dut, cases, dut_ip): dut.expect('MQTT_EVENT_ERROR: Test={}'.format(test_nr), timeout=30) dut.expect('ESP-TLS ERROR: ESP_ERR_MBEDTLS_SSL_HANDSHAKE_FAILED') # expect ... handshake error (PEER_DID_NOT_RETURN_A_CERTIFICATE) if 'PEER_DID_NOT_RETURN_A_CERTIFICATE' not in s.get_last_ssl_error(): - raise('Unexpected ssl error from the server {}'.format(s.get_last_ssl_error())) + raise RuntimeError('Unexpected ssl error from the server {}'.format(s.get_last_ssl_error())) for case in ['CONFIG_EXAMPLE_CONNECT_CASE_MUTUAL_AUTH', 'CONFIG_EXAMPLE_CONNECT_CASE_MUTUAL_AUTH_KEY_PWD']: # These cases connect to server with both server and client verification (client key might be password protected)