From 507ffb72b5ac1897daccb3089abcdfb4d28d1295 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 3 Nov 2022 09:49:51 +0100 Subject: [PATCH] colorer: Avoid duplication and move it to litex/gen. --- litex/__init__.py | 2 ++ litex/compat/__init__.py | 16 ++-------------- litex/gen/common.py | 13 +++++++++++++ litex/soc/cores/clock/common.py | 2 +- litex/soc/integration/builder.py | 6 ++++-- litex/soc/integration/soc.py | 14 +++----------- litex_setup.py | 2 +- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/litex/__init__.py b/litex/__init__.py index 636b7914f..5e2790c06 100644 --- a/litex/__init__.py +++ b/litex/__init__.py @@ -2,6 +2,8 @@ import sys from litex.tools.litex_client import RemoteClient +# Python-Data Import Helper ------------------------------------------------------------------------ + def get_data_mod(data_type, data_name): """Get the pythondata-{}-{} module or raise a useful error message.""" imp = "import pythondata_{}_{} as dm".format(data_type, data_name) diff --git a/litex/compat/__init__.py b/litex/compat/__init__.py index 3e6377c3a..b8ae8fcb8 100644 --- a/litex/compat/__init__.py +++ b/litex/compat/__init__.py @@ -1,22 +1,10 @@ import sys import time -# Helpers ------------------------------------------------------------------------------------------ - -def colorer(s, color="bright"): # FIXME: Move colorer to litex.common? - header = { - "bright": "\x1b[1m", - "green": "\x1b[32m", - "cyan": "\x1b[36m", - "red": "\x1b[31m", - "yellow": "\x1b[33m", - "underline": "\x1b[4m"}[color] - trailer = "\x1b[0m" - return header + str(s) + trailer - -# Compat ------------------------------------------------------------------------------------------- +# Compatibility Layer ------------------------------------------------------------------------------ def compat_notice(name, date, info=""): + from litex.gen import colorer print("Compat: {name} is {deprecated} since {date} and will soon no longer work, please {update}. {info}".format( name = colorer(name), deprecated = colorer("deprecated", color="red"), diff --git a/litex/gen/common.py b/litex/gen/common.py index b30047600..e4f108d9e 100644 --- a/litex/gen/common.py +++ b/litex/gen/common.py @@ -6,6 +6,19 @@ from migen import * +# Generic Helpers ---------------------------------------------------------------------------------- + +def colorer(s, color="bright"): + header = { + "bright": "\x1b[1m", + "green": "\x1b[32m", + "cyan": "\x1b[36m", + "red": "\x1b[31m", + "yellow": "\x1b[33m", + "underline": "\x1b[4m"}[color] + trailer = "\x1b[0m" + return header + str(s) + trailer + # Bit/Bytes Reversing ------------------------------------------------------------------------------ def reverse_bits(s): diff --git a/litex/soc/cores/clock/common.py b/litex/soc/cores/clock/common.py index 1dda879bf..a7341de0e 100644 --- a/litex/soc/cores/clock/common.py +++ b/litex/soc/cores/clock/common.py @@ -9,7 +9,7 @@ import math from migen import Record -from litex.soc.integration.soc import colorer +from litex.gen import colorer logging.basicConfig(level=logging.INFO) diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index dfd195677..7c4abccaf 100644 --- a/litex/soc/integration/builder.py +++ b/litex/soc/integration/builder.py @@ -19,10 +19,12 @@ import struct import shutil from litex import get_data_mod +from litex.gen import colorer + from litex.build.tools import write_to_file -from litex.soc.integration import export, soc_core -from litex.soc.integration.soc import colorer + from litex.soc.cores import cpu +from litex.soc.integration import export, soc_core # Helpers ------------------------------------------------------------------------------------------ diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 87aa67d67..525aad395 100755 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -15,6 +15,9 @@ import datetime from math import log2, ceil from migen import * + +from litex.gen import colorer + from litex.gen import LiteXModule from litex.soc.cores import cpu @@ -33,17 +36,6 @@ logging.basicConfig(level=logging.INFO) def auto_int(x): return int(x, 0) -def colorer(s, color="bright"): - header = { - "bright": "\x1b[1m", - "green": "\x1b[32m", - "cyan": "\x1b[36m", - "red": "\x1b[31m", - "yellow": "\x1b[33m", - "underline": "\x1b[4m"}[color] - trailer = "\x1b[0m" - return header + str(s) + trailer - def build_time(with_time=True): fmt = "%Y-%m-%d %H:%M:%S" if with_time else "%Y-%m-%d" return datetime.datetime.fromtimestamp(time.time()).strftime(fmt) diff --git a/litex_setup.py b/litex_setup.py index f1deedba8..a379158ea 100755 --- a/litex_setup.py +++ b/litex_setup.py @@ -16,7 +16,7 @@ python3 = sys.executable # Helpers ------------------------------------------------------------------------------------------ -def colorer(s, color="bright"): # FIXME: Move colorer to litex.common? +def colorer(s, color="bright"): header = { "bright" : "\x1b[1m", "green" : "\x1b[1m\x1b[32m",