From 333fb362ca972f98bde08f8d9ffbc295eb99eb5b Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 25 Mar 2021 16:22:33 +0100 Subject: [PATCH] Move import Compat directly to litex_boards.__init__.py and simplify. --- litex_boards/__init__.py | 63 ++++++++++++++++++++++++++++++ litex_boards/platforms/__init__.py | 48 ----------------------- litex_boards/targets/__init__.py | 48 ----------------------- 3 files changed, 63 insertions(+), 96 deletions(-) diff --git a/litex_boards/__init__.py b/litex_boards/__init__.py index e69de29..4116787 100644 --- a/litex_boards/__init__.py +++ b/litex_boards/__init__.py @@ -0,0 +1,63 @@ +import os +import sys +import glob +import importlib + +# Boards Vendors. + +vendors = [ + "1bitsquared", + "colorlight", + "digilent", + "enclustra", + "gsd", + "hackaday", + "kosagi", + "lattice", + "lambdaconcept", + "linsn", + "numato", + "qmtech", + "radiona", + "rhsresearchllc", + "saanlima", + "scarabhardware", + "siglent", + "sqrl", + "terasic", + "trenz", + "xilinx", +] + +# Get all platforms/targets. +litex_boards_dir = os.path.dirname(os.path.realpath(__file__)) +platforms = glob.glob(f"{litex_boards_dir}/platforms/*.py") +targets = glob.glob(f"{litex_boards_dir}/targets/*.py") + +# For each platform: +for platform in platforms: + platform = os.path.basename(platform) + platform = platform.replace(".py", "") + # Verify if a Vendor prefix is present in platform name, if so create the short import to + # allow the platform to be imported with the full name or short name ex: + # from litex_boards.platforms import digilent_arty or + # from litex_boards.platforms import arty + if platform.split("_")[0] in vendors: + short_platform = platform[len(platform.split("_")[0])+1:] + p = importlib.import_module(f"litex_boards.platforms.{platform}") + vars()[short_platform] = p + sys.modules[f"litex_boards.platforms.{short_platform}"] = p + +# For each target: +for target in targets: + target = os.path.basename(target) + target = target.replace(".py", "") + # Verify if a Vendor prefix is present in target name, if so create the short import to + # allow the target to be imported with the full name or short name ex: + # from litex_boards.targets import digilent_arty or + # from litex_boards.targets import arty + if target.split("_")[0] in vendors: + short_target = target[len(target.split("_")[0])+1:] + t = importlib.import_module(f"litex_boards.targets.{target}") + vars()[short_target] = t + sys.modules[f"litex_boards.targets.{short_target}"] = t diff --git a/litex_boards/platforms/__init__.py b/litex_boards/platforms/__init__.py index 0c2ce4b..e69de29 100644 --- a/litex_boards/platforms/__init__.py +++ b/litex_boards/platforms/__init__.py @@ -1,48 +0,0 @@ -import os -import sys -import glob -import importlib - -# Boards Vendors. - -vendors = [ - "1bitsquared", - "colorlight", - "digilent", - "enclustra", - "gsd", - "hackaday" - "kosagi", - "lattice", - "lambdaconcept", - "linsn", - "numato", - "qmtech", - "radiona", - "rhsresearchllc", - "saanlima", - "scarabhardware", - "siglent", - "sqrl", - "terasic", - "trenz", - "xilinx", -] - -# Get all platforms. -platforms_dir = os.path.dirname(os.path.realpath(__file__)) -platforms = glob.glob(f"{platforms_dir}/*.py") - -# For each platform: -for platform in platforms: - platform = os.path.basename(platform) - platform = platform.replace(".py", "") - # Verify if a Vendor prefix is present in platform name, if so create the short import to - # allow the platform to be imported with the full name or short name ex: - # from litex_boards.platforms import digilent_arty or - # from litex_boards.platforms import arty - if platform.split("_")[0] in vendors: - short_platform = platform[len(platform.split("_")[0])+1:] - p = importlib.import_module(f"litex_boards.platforms.{platform}") - vars()[short_platform] = p - sys.modules[f"litex_boards.platforms.{short_platform}"] = p diff --git a/litex_boards/targets/__init__.py b/litex_boards/targets/__init__.py index 7df3249..e69de29 100644 --- a/litex_boards/targets/__init__.py +++ b/litex_boards/targets/__init__.py @@ -1,48 +0,0 @@ -import os -import sys -import glob -import importlib - -# Boards Vendors. - -vendors = [ - "1bitsquared", - "colorlight", - "digilent", - "enclustra", - "gsd", - "hackaday" - "kosagi", - "lattice", - "lambdaconcept", - "linsn", - "numato", - "qmtech", - "radiona", - "rhsresearchllc", - "saanlima", - "scarabhardware", - "siglent", - "sqrl", - "terasic", - "trenz", - "xilinx", -] - -# Get all targets. -targets_dir = os.path.dirname(os.path.realpath(__file__)) -targets = glob.glob(f"{targets_dir}/*.py") - -# For each target: -for target in targets: - target = os.path.basename(target) - target = target.replace(".py", "") - # Verify if a Vendor prefix is present in target name, if so create the short import to - # allow the target to be imported with the full name or short name ex: - # from litex_boards.targets import digilent_arty or - # from litex_boards.targets import arty - if target.split("_")[0] in vendors: - short_target = target[len(target.split("_")[0])+1:] - t = importlib.import_module(f"litex_boards.targets.{target}") - vars()[short_target] = t - sys.modules[f"litex_boards.targets.{short_target}"] = t