From ee36138f75cf4c9964183309dd764f5b85b1325e Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 24 Mar 2021 15:05:34 +0100 Subject: [PATCH] compat: Fix (only triggers notice when used) and enable SoCSDRAM compat. --- litex/compat/__init__.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/litex/compat/__init__.py b/litex/compat/__init__.py index 34e5cf2fb..72357f3eb 100644 --- a/litex/compat/__init__.py +++ b/litex/compat/__init__.py @@ -1,6 +1,8 @@ import sys import time +# Helpers ------------------------------------------------------------------------------------------ + def colorer(s, color="bright"): # FIXME: Move colorer to litex.common? header = { "bright": "\x1b[1m", @@ -12,6 +14,8 @@ def colorer(s, color="bright"): # FIXME: Move colorer to litex.common? trailer = "\x1b[0m" return header + str(s) + trailer +# Compat ------------------------------------------------------------------------------------------- + def compat_notice(name, date, info=""): print("Compat: {name} is {deprecated} since {date} and will soon no longer work, please {update}. {info}".format( name = colorer(name), @@ -26,14 +30,28 @@ def compat_notice(name, date, info=""): print(".", end="") sys.stdout.flush() print("thanks :)") - time.sleep(1) def add_compat(location): + # Integration. if location == "litex.soc.integration": - #compat_notice("SoCSDRAM", date="2020-03-24", info="Switch to SoCCore/add_sdram/soc_core_args instead.") - from litex.compat import soc_sdram - sys.modules["litex.soc.integration.soc_sdram"] = soc_sdram + class compat_soc_sdram: + noticed = False + def __getattr__(self, name): + if not self.noticed: + compat_notice("SoCSDRAM", date="2020-03-24", info="Switch to SoCCore/add_sdram/soc_core_args instead.") + self.noticed = True + from litex.compat import soc_sdram + return getattr(soc_sdram, name) + sys.modules["litex.soc.integration.soc_sdram"] = compat_soc_sdram() + # Cores. elif location == "litex.soc.cores": - compat_notice("litex.soc.cores.up5kspram", date="2020-03-24", info="Switch to litex.soc.cores.ram.") + class compat_up5kspram: + noticed = False + def __getattr__(self, name): + if not self.noticed: + compat_notice("litex.soc.cores.up5kspram", date="2020-03-24", info="Switch to litex.soc.cores.ram.") + self.noticed = True + from litex.soc.cores import ram + return getattr(ram, name) from litex.soc.cores import ram - sys.modules["litex.soc.cores.up5kspram"] = ram + sys.modules["litex.soc.cores.up5kspram"] = compat_up5kspram()