mirror of
https://github.com/espressif/esptool.git
synced 2025-10-16 23:06:31 +08:00
feat: Use ruff instead of flake8 and black both in pre-commit and CI
This commit is contained in:
@@ -128,12 +128,12 @@ check_python_style:
|
|||||||
codequality: code_quality_report.json
|
codequality: code_quality_report.json
|
||||||
when: on_failure
|
when: on_failure
|
||||||
script:
|
script:
|
||||||
# This step installs any 'dev' dependencies (ie flake8, Black)
|
# This step installs any 'dev' dependencies (ie ruff)
|
||||||
# The runner should cache the downloads, so still quite fast.
|
# The runner should cache the downloads, so still quite fast.
|
||||||
- pip install -e .[dev] --prefer-binary
|
- pip install -e .[dev] --prefer-binary
|
||||||
- python -m flake8 --exit-zero --format gl-codeclimate --output-file code_quality_report.json
|
- python -m ruff check --exit-zero --output-format=gitlab --output-file=code_quality_report.json
|
||||||
- python -m flake8
|
- python -m ruff check
|
||||||
- python -m black --check --diff .
|
- python -m ruff format
|
||||||
|
|
||||||
.run_esptool: &run_esptool |
|
.run_esptool: &run_esptool |
|
||||||
esptool.py --help
|
esptool.py --help
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: 6.1.0
|
rev: v0.1.14
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: ruff # Runs ruff linter (replaces flake8)
|
||||||
additional_dependencies: [flake8-import-order]
|
args: [--fix, --exit-non-zero-on-fix] # --fix for fixing errors
|
||||||
- repo: https://github.com/psf/black
|
- id: ruff-format
|
||||||
rev: 23.11.0
|
|
||||||
hooks:
|
|
||||||
- id: black
|
|
||||||
- repo: https://github.com/espressif/conventional-precommit-linter
|
- repo: https://github.com/espressif/conventional-precommit-linter
|
||||||
rev: v1.4.0
|
rev: v1.4.0
|
||||||
hooks:
|
hooks:
|
||||||
|
59
.ruff.toml
Normal file
59
.ruff.toml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# https://docs.astral.sh/ruff/settings/
|
||||||
|
# Exclude a variety of commonly ignored directories.
|
||||||
|
exclude = [
|
||||||
|
".eggs",
|
||||||
|
".git",
|
||||||
|
"__pycache__"
|
||||||
|
]
|
||||||
|
|
||||||
|
line-length = 88
|
||||||
|
|
||||||
|
select = ['E', 'F', 'W']
|
||||||
|
ignore = ["E203"]
|
||||||
|
|
||||||
|
# Assume Python 3.7
|
||||||
|
target-version = "py37"
|
||||||
|
|
||||||
|
[per-file-ignores]
|
||||||
|
|
||||||
|
|
||||||
|
# tests often manipulate sys.path before importing the main tools, so ignore import order violations
|
||||||
|
"test/*.py" = ["E402"]
|
||||||
|
|
||||||
|
# multiple spaces after ',' and long lines - used for visual layout of eFuse data
|
||||||
|
"espefuse/efuse/*/mem_definition.py" = ["E241", "E501"]
|
||||||
|
"espefuse/efuse/*/operations.py" = ["E241", "E501", "F401"]
|
||||||
|
"espefuse/efuse/*/fields.py" = ["E241", "E501"]
|
||||||
|
|
||||||
|
# ignore long lines - used for RS encoding pairs
|
||||||
|
"test/test_modules.py" = ["E501"]
|
||||||
|
|
||||||
|
# don't check for unused imports in __init__.py files
|
||||||
|
"__init__.py" = ["F401"]
|
||||||
|
|
||||||
|
# allow definition from star imports in docs config
|
||||||
|
"docs/conf_common.py" = ["F405"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[lint]
|
||||||
|
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||||
|
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
|
||||||
|
# McCabe complexity (`C901`) by default.
|
||||||
|
select = ["E4", "E7", "E9", "F"]
|
||||||
|
ignore = []
|
||||||
|
|
||||||
|
# Allow fix for all enabled rules (when `--fix`) is provided.
|
||||||
|
fixable = ["ALL"]
|
||||||
|
unfixable = []
|
||||||
|
|
||||||
|
# Allow unused variables when underscore-prefixed.
|
||||||
|
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||||
|
|
||||||
|
|
||||||
|
# ruff-format hook configuration
|
||||||
|
[format]
|
||||||
|
quote-style = "double"
|
||||||
|
indent-style = "space"
|
||||||
|
docstring-code-format = true
|
||||||
|
|
@@ -58,8 +58,9 @@ class CheckArgValue(object):
|
|||||||
elif efuse.efuse_type.startswith("bytes"):
|
elif efuse.efuse_type.startswith("bytes"):
|
||||||
if new_value is None:
|
if new_value is None:
|
||||||
raise esptool.FatalError(
|
raise esptool.FatalError(
|
||||||
"New value required for efuse '{}' "
|
"New value required for efuse '{}' (given None)".format(
|
||||||
"(given None)".format(efuse.name)
|
efuse.name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if len(new_value) * 8 != efuse.bitarray.len:
|
if len(new_value) * 8 != efuse.bitarray.len:
|
||||||
raise esptool.FatalError(
|
raise esptool.FatalError(
|
||||||
|
@@ -368,15 +368,14 @@ class EfuseMacField(EfuseField):
|
|||||||
|
|
||||||
|
|
||||||
class EfuseKeyPurposeField(EfuseField):
|
class EfuseKeyPurposeField(EfuseField):
|
||||||
|
# fmt: off
|
||||||
KEY_PURPOSES = [
|
KEY_PURPOSES = [
|
||||||
# fmt: off
|
|
||||||
("USER", 0, None), # User purposes (software-only use)
|
("USER", 0, None), # User purposes (software-only use)
|
||||||
("XTS_AES_128_KEY", 1, None), # (whole 256bits) flash/PSRAM encryption
|
("XTS_AES_128_KEY", 1, None), # (whole 256bits) flash/PSRAM encryption
|
||||||
("XTS_AES_128_KEY_DERIVED_FROM_128_EFUSE_BITS", 2, None), # (lo 128bits) flash/PSRAM encryption
|
("XTS_AES_128_KEY_DERIVED_FROM_128_EFUSE_BITS", 2, None), # (lo 128bits) flash/PSRAM encryption
|
||||||
("SECURE_BOOT_DIGEST", 3, "DIGEST"),
|
("SECURE_BOOT_DIGEST", 3, "DIGEST"),
|
||||||
# (hi 128bits) Secure Boot key digest
|
# (hi 128bits) Secure Boot key digest
|
||||||
# fmt: on
|
] # fmt: on
|
||||||
]
|
|
||||||
|
|
||||||
KEY_PURPOSES_NAME = [name[0] for name in KEY_PURPOSES]
|
KEY_PURPOSES_NAME = [name[0] for name in KEY_PURPOSES]
|
||||||
DIGEST_KEY_PURPOSES = [name[0] for name in KEY_PURPOSES if name[2] == "DIGEST"]
|
DIGEST_KEY_PURPOSES = [name[0] for name in KEY_PURPOSES if name[2] == "DIGEST"]
|
||||||
|
@@ -1252,7 +1252,7 @@ class ELFFile(object):
|
|||||||
nobits_secitons = [s for s in all_sections if s[1] == ELFFile.SEC_TYPE_NOBITS]
|
nobits_secitons = [s for s in all_sections if s[1] == ELFFile.SEC_TYPE_NOBITS]
|
||||||
|
|
||||||
# search for the string table section
|
# search for the string table section
|
||||||
if not (shstrndx * self.LEN_SEC_HEADER) in section_header_offsets:
|
if (shstrndx * self.LEN_SEC_HEADER) not in section_header_offsets:
|
||||||
raise FatalError("ELF file has no STRTAB section at shstrndx %d" % shstrndx)
|
raise FatalError("ELF file has no STRTAB section at shstrndx %d" % shstrndx)
|
||||||
_, sec_type, _, sec_size, sec_offs = read_section_header(
|
_, sec_type, _, sec_size, sec_offs = read_section_header(
|
||||||
shstrndx * self.LEN_SEC_HEADER
|
shstrndx * self.LEN_SEC_HEADER
|
||||||
|
@@ -892,8 +892,9 @@ def image_info(args):
|
|||||||
ESP8266V2FirmwareImage.IMAGE_V2_MAGIC,
|
ESP8266V2FirmwareImage.IMAGE_V2_MAGIC,
|
||||||
]:
|
]:
|
||||||
raise FatalError(
|
raise FatalError(
|
||||||
"This is not a valid image "
|
"This is not a valid image " "(invalid magic number: {:#x})".format(
|
||||||
"(invalid magic number: {:#x})".format(magic)
|
magic
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.chip == "auto":
|
if args.chip == "auto":
|
||||||
|
27
setup.cfg
27
setup.cfg
@@ -1,27 +0,0 @@
|
|||||||
[flake8]
|
|
||||||
exclude = .git,__pycache__,.eggs,build
|
|
||||||
ignore =
|
|
||||||
# multiple spaces before operator - used for visual indent of constants in some files
|
|
||||||
E221,
|
|
||||||
|
|
||||||
per-file-ignores =
|
|
||||||
# tests often manipulate sys.path before importing the main tools, so ignore import order violations
|
|
||||||
test/*.py: E402,
|
|
||||||
|
|
||||||
# multiple spaces after ',' and long lines - used for visual layout of eFuse data
|
|
||||||
espefuse/efuse/*/mem_definition.py: E241, E501,
|
|
||||||
espefuse/efuse/*/operations.py: E241, E501, F401,
|
|
||||||
espefuse/efuse/*/fields.py: E241, E501,
|
|
||||||
|
|
||||||
# ignore long lines - used for RS encoding pairs
|
|
||||||
test/test_modules.py: E501,
|
|
||||||
|
|
||||||
# don't check for unused imports in __init__.py files
|
|
||||||
__init__.py: F401,
|
|
||||||
|
|
||||||
# allow definition from star imports in docs config
|
|
||||||
docs/conf_common.py: F405,
|
|
||||||
|
|
||||||
# Compatibility with Black
|
|
||||||
max-line-length = 88
|
|
||||||
extend-ignore = E203, W503,
|
|
5
setup.py
5
setup.py
@@ -108,12 +108,9 @@ setup(
|
|||||||
setup_requires=(["wheel"] if "bdist_wheel" in sys.argv else []),
|
setup_requires=(["wheel"] if "bdist_wheel" in sys.argv else []),
|
||||||
extras_require={
|
extras_require={
|
||||||
"dev": [
|
"dev": [
|
||||||
"flake8>=3.2.0",
|
"ruff>=0.1.14",
|
||||||
"flake8-import-order",
|
|
||||||
"flake8-gl-codeclimate",
|
|
||||||
"pyelftools",
|
"pyelftools",
|
||||||
"coverage~=6.0",
|
"coverage~=6.0",
|
||||||
"black",
|
|
||||||
"pre-commit",
|
"pre-commit",
|
||||||
"pytest",
|
"pytest",
|
||||||
"pytest-rerunfailures",
|
"pytest-rerunfailures",
|
||||||
|
Reference in New Issue
Block a user