Skip to content

Commit

Permalink
BNG line numbers in DEBUG log (#365)
Browse files Browse the repository at this point in the history
BNG errors and warnings often given line numbers referring to the BNGL
file. This PR adds line numbers to the BNGL output shown in PySB's
DEBUG log.
  • Loading branch information
alubbock committed Jun 6, 2018
1 parent 5648121 commit 833f1b3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pysb/bng.py
Expand Up @@ -445,8 +445,11 @@ def execute(self, reload_netfile=False, skip_file_actions=True):
output += '\n readFile({file=>"%s",skip_actions=>%d})\n' \
% (filename, int(skip_file_actions))
output += bng_commands
self._logger.debug('BNG command file contents:\n\n' + output)
bng_file.write(output)
lines = output.split('\n')
line_number_format = 'L{{:0{}d}} {{}}'.format(int(numpy.ceil(numpy.log10(len(lines)))))
output = '\n'.join(line_number_format.format(ln + 1, line) for ln, line in enumerate(lines))
self._logger.debug('BNG command file contents:\n' + output)

# Reset the command queue, in case execute() is called again
self.command_queue.close()
Expand Down

0 comments on commit 833f1b3

Please sign in to comment.