Skip to content

Commit

Permalink
[flake8] Fixed reported issues
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Jan 5, 2024
1 parent d7392d5 commit 6f7d425
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ repos:
hooks:
- id: autoflake8
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8
exclude: ^kibot/mcpyrate/
args: [--count, --statistics]
additional_dependencies:
- flake8-bugbear==22.1.11
- flake8-comprehensions==3.8.0
- flake8_2020==1.6.1
- flake8-bugbear>=22.1.11
- flake8-comprehensions>=3.8.0
- flake8_2020>=1.6.1
- flake8-docstrings
- mccabe==0.6.1
- pycodestyle==2.8.0
- pyflakes==2.4.0
- mccabe>=0.6.1
- pycodestyle>=2.8.0
- pyflakes>=2.4.0
# Sorting imports is dangerous.
# - repo: https://github.com/PyCQA/isort
# rev: 5.10.1
Expand Down
4 changes: 2 additions & 2 deletions kibot/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def _parse_import_outputs(self, outs, explicit_outs, fn_rel, data, imported):
if explicit_outs:
logger.warning(W_NOOUTPUTS+"No outputs found in `{}`".format(fn_rel))
else:
logger.debug('Outputs loaded from `{}`: {}'.format(fn_rel, (c.name for c in sel_outs)))
logger.debug('Outputs loaded from `{}`: {}'.format(fn_rel, [c.name for c in sel_outs]))
if outs is None and explicit_outs and 'outputs' not in data:
logger.warning(W_NOOUTPUTS+"No outputs found in `{}`".format(fn_rel))
return sel_outs
Expand All @@ -364,7 +364,7 @@ def _parse_import_preflights(self, pre, explicit_pres, fn_rel, data, imported):
if explicit_pres:
logger.warning(W_NOPREFLIGHTS+"No preflights found in `{}`".format(fn_rel))
else:
logger.debug('Preflights loaded from `{}`: {}'.format(fn_rel, (c._name for c in sel_pres)))
logger.debug('Preflights loaded from `{}`: {}'.format(fn_rel, [c._name for c in sel_pres]))
if pre is None and explicit_pres and 'preflight' not in data:
logger.warning(W_NOPREFLIGHTS+"No preflights found in `{}`".format(fn_rel))
return sel_pres
Expand Down
4 changes: 2 additions & 2 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def iu_to_svg(values, svg_precision):
For tuples we assume the result is SVG coordinates, for 1 value a scale """
if GS.ki5:
if isinstance(values, tuple):
return (int(round(x*KICAD5_SVG_SCALE)) for x in values)
return tuple(int(round(x*KICAD5_SVG_SCALE)) for x in values)
return values*KICAD5_SVG_SCALE
if GS.ki7:
if isinstance(values, tuple):
Expand All @@ -634,7 +634,7 @@ def iu_to_svg(values, svg_precision):
# KiCad 6
mult = 10.0 ** (svg_precision - 6)
if isinstance(values, tuple):
return (int(round(x*mult)) for x in values)
return tuple(int(round(x*mult)) for x in values)
return values*mult

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion kibot/kicad/v6_sch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ def check_exp_hierarchy(self):
# 0 or 1 can't be different
continue
ref_c = l_ins[0]
if any(map(lambda c: self.compare_component(ref_c, c), l_ins[1:])):
if any((self.compare_component(ref_c, c) for c in l_ins[1:])):
return True
# No variant
return False
Expand Down
4 changes: 2 additions & 2 deletions kibot/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def log(self, level, msg, *args, **kwargs):
if isinstance(msg, tuple):
msg = ' '.join(map(str, msg))
if sys.version_info >= (3, 8):
super(self.__class__, self).debug(msg, stacklevel=2, *args, **kwargs) # pragma: no cover (Py38)
super(self.__class__, self).debug(msg, *args, **kwargs, stacklevel=2) # pragma: no cover (Py38)
else:
super(self.__class__, self).debug(msg, *args, **kwargs)

Expand All @@ -140,7 +140,7 @@ def debugl(self, level, msg, *args, **kwargs):
if isinstance(msg, tuple):
msg = ' '.join(map(str, msg))
if sys.version_info >= (3, 8):
super(self.__class__, self).debug(msg, stacklevel=2, *args, **kwargs) # pragma: no cover (Py38)
super(self.__class__, self).debug(msg, *args, **kwargs, stacklevel=2) # pragma: no cover (Py38)
else:
super(self.__class__, self).debug(msg, *args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion kibot/optionable.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def expand_filename_both(self, name, is_sch=True, make_safe=True):
# Replace KiCad 6 variables first
name = GS.expand_text_variables(name)
# Determine if we need to expand SCH and/or PCB related data
has_dep_exp = any(map(lambda x: x in name, PATTERNS_DEP))
has_dep_exp = any((x in name for x in PATTERNS_DEP))
do_sch = is_sch and has_dep_exp
# logger.error(name + ' is_sch ' +str(is_sch)+" "+ str(do_sch))
# raise
Expand Down
6 changes: 3 additions & 3 deletions kibot/out_base_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def create_colored_tht_resistor(self, ori, name, bars, r_len):
m = coo_re.match(ln)
if m:
index = prev_ln
points = list(map(lambda x: tuple(map(float, x.split(' '))), m.group(1).split(',')))
points = [(float(v) for v in x.split(' ')) for x in m.group(1).split(',')]
x_len = (points[0][X]-points[2][X])*2.54*2
if abs(x_len-r_len) < 0.01:
logger.debug(' - Found horizontal: {}'.format(round(x_len, 2)))
Expand Down Expand Up @@ -418,7 +418,7 @@ def do_colored_tht_resistor(self, name, c, changed):
bars[bar] = ord(val_str[bar])-ord('0')
# Make sure we don't have digits that can't be represented
rest = val_str[dig_bars:]
if rest and not all(map(lambda x: x == '0', rest)):
if rest and not all((x == '0' for x in rest)):
logger.warning(W_RESVALISSUE+'Digits not represented in {} {} ({} %)'.format(c.ref, c.value, tol))
bars[nbars-1] = tol_color
# For 20% remove the last bar
Expand Down Expand Up @@ -550,7 +550,7 @@ def filter_components(self, highlight=None, force_wrl=False):
GS.load_sch()
all_comps = GS.sch.get_components()
if (GS.global_kicad_dnp_applies_to_3D and
any(map(lambda c: c.kicad_dnp is not None and c.kicad_dnp, all_comps))):
any((c.kicad_dnp is not None and c.kicad_dnp for c in all_comps))):
# One or more components are DNP, remove them
reset_filters(all_comps)
all_comps_hash = {c.ref: c for c in all_comps}
Expand Down
4 changes: 2 additions & 2 deletions kibot/out_boardview.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def convert(pcb, brd):
pcb.GetBoardPolygonOutlines(outlines)
outline = outlines.Outline(0)
outline_points = [outline.GetPoint(n) for n in range(outline.GetPointCount())]
outline_maxx = max(map(lambda p: p.x, outline_points))
outline_maxy = max(map(lambda p: p.y, outline_points))
outline_maxx = max((p.x for p in outline_points))
outline_maxy = max((p.y for p in outline_points))

brd.write("0\n") # unknown

Expand Down
2 changes: 1 addition & 1 deletion kibot/svgutils/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class LineElement(FigureElement):

def __init__(self, points, width=1, color="black"):
linedata = "M{} {} ".format(*points[0])
linedata += " ".join(map(lambda x: "L{} {}".format(*x), points[1:]))
linedata += " ".join(("L{} {}".format(*x) for x in points[1:]))
line = etree.Element(
SVG + "path", {"d": linedata, "stroke-width": str(width), "stroke": color}
)
Expand Down
8 changes: 4 additions & 4 deletions kibot/var_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ def search_reference_rect(self, ref):
def move_objects(self):
""" Move all objects by self._moved """
logger.debug('Moving all PCB elements by '+point_str(self._moved))
any(map(lambda x: x.Move(self._moved), GS.get_modules()))
any(map(lambda x: x.Move(self._moved), GS.board.GetDrawings()))
any(map(lambda x: x.Move(self._moved), GS.board.GetTracks()))
any(map(lambda x: x.Move(self._moved), GS.board.Zones()))
any((x.Move(self._moved) for x in GS.get_modules()))
any((x.Move(self._moved) for x in GS.board.GetDrawings()))
any((x.Move(self._moved) for x in GS.board.GetTracks()))
any((x.Move(self._moved) for x in GS.board.Zones()))

def center_objects(self):
""" Move all objects in the PCB so it gets centered """
Expand Down
6 changes: 3 additions & 3 deletions tests/test_plot/test_kicost.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def convert2csv(ctx, xlsx, skip_empty=False, sheet=None):
subprocess.check_output(cmd)
with open(csv, 'rt') as f:
content = f.read()
content = re.sub(r'(\$|Prj) date:,[^,]+', r'\1 date:,', content, 3)
content = re.sub(r'KiCost[^,]+', 'KiCost', content, 1)
content = re.sub(r'(\$|Prj) date:,[^,]+', r'\1 date:,', content, count=3)
content = re.sub(r'KiCost[^,]+', 'KiCost', content, count=1)
content = re.sub(r'KiCad Version:,[^,]+', 'KiCad Version:,', content)
content = re.sub(r'Created:,[^,]+', 'Created:,', content, 1)
content = re.sub(r'Created:,[^,]+', 'Created:,', content, count=1)
with open(csv, 'wt') as f:
f.write(content)

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ def compare_image(self, image, reference=None, diff='diff.png', ref_out_dir=Fals
# logging.debug('MSE={} ({})'.format(m.group(1), m.group(2)))
s = res.decode()
# Remove error messages generated by KiCad 7 plotted PDFs
s = re.sub(r'^\s+\*+.*', '', s, 0, re.M)
s = re.sub(r'^\s+Output may be incorrect.*', '', s, 0, re.M)
s = re.sub(r'^\s+\*+.*', '', s, count=0, flags=re.M)
s = re.sub(r'^\s+Output may be incorrect.*', '', s, count=0, flags=re.M)
s = s.strip()
ae = int(s)
logging.debug('AE=%d' % ae)
Expand Down

0 comments on commit 6f7d425

Please sign in to comment.