Skip to content

Commit 2d1f063

Browse files
committed
fpga: fixed a new pylint complain about to use f-strings
1 parent 2d05221 commit 2d1f063

File tree

4 files changed

+34
-44
lines changed

4 files changed

+34
-44
lines changed

fpga/tool/__init__.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright (C) 2019-2020 INTI
3-
# Copyright (C) 2019-2020 Rodrigo A. Melo
3+
# Copyright (C) 2019-2021 Rodrigo A. Melo
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -37,10 +37,8 @@
3737
def check_value(value, values):
3838
"""Check if VALUE is included in VALUES."""
3939
if value not in values:
40-
raise ValueError(
41-
'{} is not a valid value [{}]'
42-
.format(value, ", ".join(values))
43-
)
40+
joined_values = ", ".join(values)
41+
raise ValueError(f'{value} is not a valid value [{joined_values}]')
4442

4543

4644
def run(command, capture):
@@ -163,27 +161,27 @@ def _create_gen_script(self, tasks):
163161
# Paths and files
164162
files = []
165163
if self.presynth:
166-
files.append(' fpga_file {}.edif'.format(self.project))
164+
files.append(f' fpga_file {self.project}.edif')
167165
else:
168166
for path in self.paths:
169-
files.append(' fpga_include {}'.format(tcl_path(path)))
167+
files.append(f' fpga_include {tcl_path(path)}')
170168
for file in self.files['verilog']:
171-
files.append(' fpga_file {}'.format(tcl_path(file[0])))
169+
files.append(f' fpga_file {tcl_path(file[0])}')
172170
for file in self.files['vhdl']:
173171
if file[1] is None:
174-
files.append(' fpga_file {}'.format(tcl_path(file[0])))
172+
files.append(f' fpga_file {tcl_path(file[0])}')
175173
else:
176-
files.append(' fpga_file {} {}'.format(
177-
tcl_path(file[0]), file[1]
178-
))
174+
files.append(
175+
f' fpga_file {tcl_path(file[0])} {file[1]}'
176+
)
179177
for file in self.files['design']:
180-
files.append(' fpga_design {}'.format(tcl_path(file[0])))
178+
files.append(f' fpga_design {tcl_path(file[0])}')
181179
for file in self.files['constraint']:
182-
files.append(' fpga_file {}'.format(tcl_path(file[0])))
180+
files.append(f' fpga_file {tcl_path(file[0])}')
183181
# Parameters
184182
params = []
185183
for param in self.params:
186-
params.append('{{ {} {} }}'.format(param[0], param[1]))
184+
params.append(f'{{ {param[0]} {param[1]} }}')
187185
# Script creation
188186
template = os.path.join(os.path.dirname(__file__), 'template.tcl')
189187
with open(template, 'r') as file:
@@ -206,7 +204,7 @@ def _create_gen_script(self, tasks):
206204
tcl = tcl.replace('#POSTSYN_CMDS#', '\n'.join(self.cmds['postsyn']))
207205
tcl = tcl.replace('#POSTIMP_CMDS#', '\n'.join(self.cmds['postimp']))
208206
tcl = tcl.replace('#POSTBIT_CMDS#', '\n'.join(self.cmds['postbit']))
209-
with open('%s.tcl' % self._TOOL, 'w') as file:
207+
with open(f'{self._TOOL}.tcl', 'w') as file:
210208
file.write(tcl)
211209

212210
def generate(self, to_task, from_task, capture):
@@ -217,15 +215,13 @@ def generate(self, to_task, from_task, capture):
217215
from_index = TASKS.index(from_task)
218216
if from_index > to_index:
219217
raise ValueError(
220-
'initial task "{}" cannot be later than the last task "{}"'
221-
.format(from_task, to_task)
218+
f'initial task "{from_task}" cannot be later than the ' +
219+
f'last task "{to_task}"'
222220
)
223221
tasks = " ".join(TASKS[from_index:to_index+1])
224222
self._create_gen_script(tasks)
225223
if not which(self._GEN_PROGRAM):
226-
raise RuntimeError(
227-
'program "{}" not found'.format(self._GEN_PROGRAM)
228-
)
224+
raise RuntimeError(f'program "{self._GEN_PROGRAM}" not found')
229225
return run(self._GEN_COMMAND, capture)
230226

231227
def set_bitstream(self, path):
@@ -235,9 +231,7 @@ def set_bitstream(self, path):
235231
def transfer(self, devtype, position, part, width, capture):
236232
"""Transfer a bitstream."""
237233
if not which(self._TRF_PROGRAM):
238-
raise RuntimeError(
239-
'program "{}" not found'.format(self._TRF_PROGRAM)
240-
)
234+
raise RuntimeError(f'program "{self._TRF_PROGRAM}" not found')
241235
check_value(devtype, self._DEVTYPES)
242236
check_value(position, range(10))
243237
isinstance(part, str)
@@ -247,7 +241,7 @@ def transfer(self, devtype, position, part, width, capture):
247241
if not self.bitstream and devtype not in ['detect', 'unlock']:
248242
bitstream = []
249243
for ext in self._BIT_EXT:
250-
bitstream.extend(glob('**/*.{}'.format(ext), recursive=True))
244+
bitstream.extend(glob(f'**/*.{ext}', recursive=True))
251245
if len(bitstream) == 0:
252246
raise FileNotFoundError('bitStream not found')
253247
self.bitstream = bitstream[0]

fpga/tool/ise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright (C) 2019-2020 INTI
3-
# Copyright (C) 2019-2020 Rodrigo A. Melo
3+
# Copyright (C) 2019-2021 Rodrigo A. Melo
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -132,7 +132,7 @@ def set_part(self, part):
132132
device, speed, package = re.findall(r'(\w+)-(\w+)-(\w+)', part)[0]
133133
if len(speed) > len(package):
134134
speed, package = package, speed
135-
part = "{}-{}-{}".format(device, speed, package)
135+
part = f'{device}-{speed}-{package}'
136136
except IndexError:
137137
raise ValueError(
138138
'Part must be DEVICE-SPEED-PACKAGE or DEVICE-PACKAGE-SPEED'

fpga/tool/libero.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright (C) 2019-2020 INTI
3-
# Copyright (C) 2019-2020 Rodrigo A. Melo
3+
# Copyright (C) 2019-2021 Rodrigo A. Melo
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -64,7 +64,7 @@ def set_part(self, part):
6464
speed, package = package, speed
6565
if speed == '':
6666
speed = 'STD'
67-
part = "{}-{}-{}".format(device, speed, package)
67+
part = f'{device}-{speed}-{package}'
6868
except IndexError:
6969
raise ValueError(
7070
'Part must be DEVICE-SPEED-PACKAGE or DEVICE-PACKAGE'

fpga/tool/openflow.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright (C) 2020 INTI
3-
# Copyright (C) 2020 Rodrigo A. Melo
3+
# Copyright (C) 2020-2021 Rodrigo A. Melo
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ def _configure(self):
6060
command = engine.get('command', 'docker') + ' run --rm'
6161
volumes = '-v ' + ('-v ').join(engine.get('volumes', ['$HOME:$HOME']))
6262
work = '-w ' + engine.get('work', '$PWD')
63-
self.oci_engine = '{} {} {}'.format(command, volumes, work)
63+
self.oci_engine = f'{command} {volumes} {work}'
6464
# Containers
6565
defaults = {
6666
'ghdl': 'ghdl/synth:beta',
@@ -90,7 +90,7 @@ def set_part(self, part):
9090
self.part['device'] = aux[0]
9191
self.part['package'] = aux[1]
9292
elif len(aux) == 3:
93-
self.part['device'] = '{}-{}'.format(aux[0], aux[1])
93+
self.part['device'] = f'{aux[0]}-{aux[1]}'
9494
self.part['package'] = aux[2]
9595
else:
9696
raise ValueError('Part must be DEVICE-PACKAGE')
@@ -103,33 +103,29 @@ def _create_gen_script(self, tasks):
103103
# Verilog includes
104104
paths = []
105105
for path in self.paths:
106-
paths.append('verilog_defaults -add -I{}'.format(path))
106+
paths.append(f'verilog_defaults -add -I{path}')
107107
# Files
108108
constraints = []
109109
verilogs = []
110110
vhdls = []
111111
for file in self.files['vhdl']:
112112
lib = ''
113113
if file[1] is not None:
114-
lib = '--work={}'.format(file[1])
115-
vhdls.append('{} -a $FLAGS {} {}'.format(
116-
self.tools['ghdl'], lib, file[0])
117-
)
114+
lib = f'--work={file[1]}'
115+
vhdls.append(f'{self.tools["ghdl"]} -a $FLAGS {lib} {file[0]}')
118116
for file in self.files['verilog']:
119117
if file[0].endswith('.sv'):
120-
verilogs.append('read_verilog -sv -defer {}'.format(file[0]))
118+
verilogs.append(f'read_verilog -sv -defer {file[0]}')
121119
else:
122-
verilogs.append('read_verilog -defer {}'.format(file[0]))
120+
verilogs.append(f'read_verilog -defer {file[0]}')
123121
for file in self.files['constraint']:
124122
constraints.append(file[0])
125123
if len(vhdls) > 0:
126-
verilogs = ['ghdl $FLAGS {}'.format(self.top)]
124+
verilogs = [f'ghdl $FLAGS {self.top}']
127125
# Parameters
128126
params = []
129127
for param in self.params:
130-
params.append('chparam -set {} {} {}'.format(
131-
param[0], param[1], self.top
132-
))
128+
params.append(f'chparam -set {param[0]} {param[1]} {self.top}')
133129
# Script creation
134130
template = os.path.join(os.path.dirname(__file__), 'template.sh')
135131
with open(template, 'r') as file:
@@ -165,7 +161,7 @@ def _create_gen_script(self, tasks):
165161
tool_nextpnr_ecp5=self.tools['nextpnr-ecp5'],
166162
tool_ecppack=self.tools['ecppack']
167163
)
168-
with open('%s.sh' % self._TOOL, 'w') as file:
164+
with open(f'{self._TOOL}.sh', 'w') as file:
169165
file.write(text)
170166

171167
def generate(self, to_task, from_task, capture):

0 commit comments

Comments
 (0)