mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-26 00:41:23 +02:00
lint: run mypy over contrib/devtools
This commit is contained in:
parent
4a8f4ac4fc
commit
1ef2138c0d
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
from typing import Dict, List, Set
|
||||||
|
|
||||||
MAPPING = {
|
MAPPING = {
|
||||||
'core_read.cpp': 'core_io.cpp',
|
'core_read.cpp': 'core_io.cpp',
|
||||||
@ -32,7 +33,7 @@ def module_name(path):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
files = dict()
|
files = dict()
|
||||||
deps = dict()
|
deps: Dict[str, Set[str]] = dict()
|
||||||
|
|
||||||
RE = re.compile("^#include <(.*)>")
|
RE = re.compile("^#include <(.*)>")
|
||||||
|
|
||||||
@ -59,12 +60,12 @@ for arg in sorted(files.keys()):
|
|||||||
deps[module].add(included_module)
|
deps[module].add(included_module)
|
||||||
|
|
||||||
# Loop to find the shortest (remaining) circular dependency
|
# Loop to find the shortest (remaining) circular dependency
|
||||||
have_cycle = False
|
have_cycle: bool = False
|
||||||
while True:
|
while True:
|
||||||
shortest_cycle = None
|
shortest_cycle = None
|
||||||
for module in sorted(deps.keys()):
|
for module in sorted(deps.keys()):
|
||||||
# Build the transitive closure of dependencies of module
|
# Build the transitive closure of dependencies of module
|
||||||
closure = dict()
|
closure: Dict[str, List[str]] = dict()
|
||||||
for dep in deps[module]:
|
for dep in deps[module]:
|
||||||
closure[dep] = []
|
closure[dep] = []
|
||||||
while True:
|
while True:
|
||||||
|
@ -157,7 +157,7 @@ def check_version(max_versions, version, arch) -> bool:
|
|||||||
def check_imported_symbols(filename) -> bool:
|
def check_imported_symbols(filename) -> bool:
|
||||||
elf = pixie.load(filename)
|
elf = pixie.load(filename)
|
||||||
cppfilt = CPPFilt()
|
cppfilt = CPPFilt()
|
||||||
ok = True
|
ok: bool = True
|
||||||
|
|
||||||
for symbol in elf.dyn_symbols:
|
for symbol in elf.dyn_symbols:
|
||||||
if not symbol.is_import:
|
if not symbol.is_import:
|
||||||
@ -172,7 +172,7 @@ def check_imported_symbols(filename) -> bool:
|
|||||||
def check_exported_symbols(filename) -> bool:
|
def check_exported_symbols(filename) -> bool:
|
||||||
elf = pixie.load(filename)
|
elf = pixie.load(filename)
|
||||||
cppfilt = CPPFilt()
|
cppfilt = CPPFilt()
|
||||||
ok = True
|
ok: bool = True
|
||||||
for symbol in elf.dyn_symbols:
|
for symbol in elf.dyn_symbols:
|
||||||
if not symbol.is_export:
|
if not symbol.is_export:
|
||||||
continue
|
continue
|
||||||
@ -184,7 +184,7 @@ def check_exported_symbols(filename) -> bool:
|
|||||||
return ok
|
return ok
|
||||||
|
|
||||||
def check_ELF_libraries(filename) -> bool:
|
def check_ELF_libraries(filename) -> bool:
|
||||||
ok = True
|
ok: bool = True
|
||||||
elf = pixie.load(filename)
|
elf = pixie.load(filename)
|
||||||
for library_name in elf.query_dyn_tags(pixie.DT_NEEDED):
|
for library_name in elf.query_dyn_tags(pixie.DT_NEEDED):
|
||||||
assert(isinstance(library_name, bytes))
|
assert(isinstance(library_name, bytes))
|
||||||
@ -207,7 +207,7 @@ def macho_read_libraries(filename) -> List[str]:
|
|||||||
return libraries
|
return libraries
|
||||||
|
|
||||||
def check_MACHO_libraries(filename) -> bool:
|
def check_MACHO_libraries(filename) -> bool:
|
||||||
ok = True
|
ok: bool = True
|
||||||
for dylib in macho_read_libraries(filename):
|
for dylib in macho_read_libraries(filename):
|
||||||
if dylib not in MACHO_ALLOWED_LIBRARIES:
|
if dylib not in MACHO_ALLOWED_LIBRARIES:
|
||||||
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
|
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
|
||||||
@ -227,7 +227,7 @@ def pe_read_libraries(filename) -> List[str]:
|
|||||||
return libraries
|
return libraries
|
||||||
|
|
||||||
def check_PE_libraries(filename) -> bool:
|
def check_PE_libraries(filename) -> bool:
|
||||||
ok = True
|
ok: bool = True
|
||||||
for dylib in pe_read_libraries(filename):
|
for dylib in pe_read_libraries(filename):
|
||||||
if dylib not in PE_ALLOWED_LIBRARIES:
|
if dylib not in PE_ALLOWED_LIBRARIES:
|
||||||
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
|
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
|
||||||
@ -260,7 +260,7 @@ def identify_executable(executable) -> Optional[str]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
retval = 0
|
retval: int = 0
|
||||||
for filename in sys.argv[1:]:
|
for filename in sys.argv[1:]:
|
||||||
try:
|
try:
|
||||||
etype = identify_executable(filename)
|
etype = identify_executable(filename)
|
||||||
@ -269,7 +269,7 @@ if __name__ == '__main__':
|
|||||||
retval = 1
|
retval = 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
failed = []
|
failed: List[str] = []
|
||||||
for (name, func) in CHECKS[etype]:
|
for (name, func) in CHECKS[etype]:
|
||||||
if not func(filename):
|
if not func(filename):
|
||||||
failed.append(name)
|
failed.append(name)
|
||||||
|
@ -102,7 +102,7 @@ if ! PYTHONWARNINGS="ignore" flake8 --ignore=B,C,E,F,I,N,W --select=$(IFS=","; e
|
|||||||
EXIT_CODE=1
|
EXIT_CODE=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! mypy --ignore-missing-imports $(git ls-files "test/functional/*.py"); then
|
if ! mypy --ignore-missing-imports $(git ls-files "test/functional/*.py" "contrib/devtools/*.py"); then
|
||||||
EXIT_CODE=1
|
EXIT_CODE=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user