From 359a94356dba415cbd945e56126a326c59878e56 Mon Sep 17 00:00:00 2001 From: Tim Hutt Date: Tue, 5 Nov 2024 14:32:12 +0000 Subject: Enable Pylint in CI and fix its errors (#311) * Remove wildcard imports Use explicit imports rather than wildcards. This is more maintainable. * Enable Pylint in CI and fix its errors The main fixes were: * Specify encoding for all file opens. By default it depends on environment variables which is bad. * Use `with` to open files. Otherwise they don't necessarily get closed. There were also a few minor things like using `enumerate`, not using objects as default arguments, etc. In some cases I slightly refactored the code. --- sverilog_utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'sverilog_utils.py') diff --git a/sverilog_utils.py b/sverilog_utils.py index a3b7571..d2b26b6 100644 --- a/sverilog_utils.py +++ b/sverilog_utils.py @@ -1,7 +1,9 @@ import logging import pprint +from pathlib import Path -from shared_utils import * +from constants import csrs, csrs32 +from shared_utils import InstrDict pp = pprint.PrettyPrinter(indent=2) logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s") @@ -17,13 +19,12 @@ def make_sverilog(instr_dict: InstrDict): f" localparam logic [11:0] CSR_{name.upper()} = 12'h{hex(num)[2:]};\n" ) - sverilog_file = open("inst.sverilog", "w") - sverilog_file.write( + Path("inst.sverilog").write_text( f""" /* Automatically generated by parse_opcodes */ package riscv_instr; {names_str} endpackage -""" +""", + encoding="utf-8", ) - sverilog_file.close() -- cgit v1.1