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
3737def 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
4644def 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 ]
0 commit comments