Skip to content

Commit

Permalink
Fix lint errors in contrib folder
Browse files Browse the repository at this point in the history
  • Loading branch information
dcorral committed Mar 20, 2023
1 parent 47c4cc6 commit 692850d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions contrib/devtools/clang-format-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def main():
filename = None
lines_by_file = {}
for line in sys.stdin:
match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line)
match = re.search('^+++ (.*?/){%s}(S*)' % args.p, line)
if match:
filename = match.group(2)
if filename is None:
Expand All @@ -119,7 +119,7 @@ def main():
if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
continue

match = re.search('^@@.*\+(\d+)(,(\d+))?', line)
match = re.search('^@@.*+(d+)(,(d+))?', line)
if match:
start_line = int(match.group(1))
line_count = 1
Expand Down
15 changes: 6 additions & 9 deletions contrib/devtools/copyright_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def applies_to_file(filename):
for excluded_dir in EXCLUDE_DIRS:
if filename.startswith(excluded_dir):
return False
return ((EXCLUDE_COMPILED.match(filename) is None) and
(INCLUDE_COMPILED.match(filename) is not None))
return ((EXCLUDE_COMPILED.match(filename) is None) and (INCLUDE_COMPILED.match(filename) is not None))

################################################################################
# obtain list of files in repo according to INCLUDE and EXCLUDE
Expand Down Expand Up @@ -71,7 +70,7 @@ def get_filenames_to_examine(base_directory):
################################################################################


COPYRIGHT_WITH_C = 'Copyright \(c\)'
COPYRIGHT_WITH_C = 'Copyright (c)'
COPYRIGHT_WITHOUT_C = 'Copyright'
ANY_COPYRIGHT_STYLE = '(%s|%s)' % (COPYRIGHT_WITH_C, COPYRIGHT_WITHOUT_C)

Expand All @@ -90,8 +89,8 @@ def compile_copyright_regex(copyright_style, year_style, name):
EXPECTED_HOLDER_NAMES = [
"Satoshi Nakamoto\n",
"The Bitcoin Core developers\n",
"BitPay Inc\.\n",
"University of Illinois at Urbana-Champaign\.\n",
"BitPay Inc.\n",
"University of Illinois at Urbana-Champaign.\n",
"Pieter Wuille\n",
"Wladimir J. van der Laan\n",
"Jeff Garzik\n",
Expand Down Expand Up @@ -330,7 +329,7 @@ def write_file_lines(filename, file_lines):
# update header years execution
################################################################################

COPYRIGHT = 'Copyright \(c\)'
COPYRIGHT = 'Copyright (c)'
YEAR = "20[0-9][0-9]"
YEAR_RANGE = '(%s)(-%s)?' % (YEAR, YEAR)
HOLDER = 'The Bitcoin Core developers'
Expand Down Expand Up @@ -369,9 +368,7 @@ def create_updated_copyright_line(line, last_git_change_year):
start_year, end_year = parse_year_range(year_range)
if end_year == last_git_change_year:
return line
return (before_copyright + copyright_splitter +
year_range_to_str(start_year, last_git_change_year) + ' ' +
' '.join(space_split[1:]))
return (before_copyright + copyright_splitter + year_range_to_str(start_year, last_git_change_year) + ' ' + ' '.join(space_split[1:]))

def update_updatable_copyright(filename):
file_lines = read_file_lines(filename)
Expand Down
2 changes: 1 addition & 1 deletion contrib/devtools/security-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def check_PE_HIGH_ENTROPY_VA(executable):
if arch == 'i386:x86-64':
reqbits = IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
else: # Unnecessary on 32-bit
assert(arch == 'i386')
assert (arch == 'i386')
reqbits = 0
return (bits & reqbits) == reqbits

Expand Down
2 changes: 1 addition & 1 deletion contrib/devtools/symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def read_libraries(filename):
for line in stdout.splitlines():
tokens = line.split()
if len(tokens)>2 and tokens[1] == '(NEEDED)':
match = re.match('^Shared library: \[(.*)\]$', ' '.join(tokens[2:]))
match = re.match('^Shared library: [(.*)]$', ' '.join(tokens[2:]))
if match:
libraries.append(match.group(1))
else:
Expand Down
7 changes: 3 additions & 4 deletions contrib/linearize/linearize-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def uint32(x):
return x & 0xffffffff

def bytereverse(x):
return uint32(( ((x) << 24) | (((x) << 8) & 0x00ff0000) |
(((x) >> 8) & 0x0000ff00) | ((x) >> 24) ))
return uint32(( ((x) << 24) | (((x) << 8) & 0x00ff0000) | (((x) >> 8) & 0x0000ff00) | ((x) >> 24) ))

def bufreverse(in_buf):
out_words = []
Expand Down Expand Up @@ -263,12 +262,12 @@ def run(self):
f = open(sys.argv[1], encoding="utf8")
for line in f:
# skip comment lines
m = re.search('^\s*#', line)
m = re.search('^s*#', line)
if m:
continue

# parse key=value lines
m = re.search('^(\w+)\s*=\s*(\S.*)$', line)
m = re.search('^(w+)s*=s*(S.*)$', line)
if m is None:
continue
settings[m.group(1)] = m.group(2)
Expand Down
6 changes: 3 additions & 3 deletions contrib/linearize/linearize-hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
if rpc.response_is_error(resp_obj):
print('JSON-RPC: error at height', height+x, ': ', resp_obj['error'], file=sys.stderr)
sys.exit(1)
assert(resp_obj['id'] == x) # assume replies are in-sequence
assert (resp_obj['id'] == x) # assume replies are in-sequence
if settings['rev_hash_bytes'] == 'true':
resp_obj['result'] = hex_switchEndian(resp_obj['result'])
print(resp_obj['result'])
Expand All @@ -106,12 +106,12 @@ def get_rpc_cookie():
f = open(sys.argv[1], encoding="utf8")
for line in f:
# skip comment lines
m = re.search('^\s*#', line)
m = re.search('^s*#', line)
if m:
continue

# parse key=value lines
m = re.search('^(\w+)\s*=\s*(\S.*)$', line)
m = re.search('^(w+)s*=s*(S.*)$', line)
if m is None:
continue
settings[m.group(1)] = m.group(2)
Expand Down
6 changes: 3 additions & 3 deletions contrib/seeds/generate-seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ def name_to_ipv6(addr):
if i == 0 or i == (len(addr)-1): # skip empty component at beginning or end
continue
x += 1 # :: skips to suffix
assert(x < 2)
assert (x < 2)
else: # two bytes per component
val = int(comp, 16)
sub[x].append(val >> 8)
sub[x].append(val & 0xff)
nullbytes = 16 - len(sub[0]) - len(sub[1])
assert((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0))
assert ((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0))
return bytearray(sub[0] + ([0] * nullbytes) + sub[1])
elif addr.startswith('0x'): # IPv4-in-little-endian
return pchIPv4 + bytearray(reversed(a2b_hex(addr[2:])))
else:
raise ValueError('Could not parse address %s' % addr)

def parse_spec(s, defaultport):
match = re.match('\[([0-9a-fA-F:]+)\](?::([0-9]+))?$', s)
match = re.match('[([0-9a-fA-F:]+)](?::([0-9]+))?$', s)

This comment has been minimized.

Copy link
@shohamc1

shohamc1 Mar 21, 2023

Contributor

Do these still work? The recommended way to fix this is by adding r before the string.

https://www.flake8rules.com/rules/W605.html

This comment has been minimized.

Copy link
@dcorral

dcorral Mar 21, 2023

Author Contributor

Fixed

if match: # ipv6
host = match.group(1)
port = match.group(2)
Expand Down

0 comments on commit 692850d

Please sign in to comment.