From fe706ee770e11882135af72737233dd03270c8f8 Mon Sep 17 00:00:00 2001 From: Zapta Date: Sun, 17 Nov 2024 19:07:17 -0800 Subject: [PATCH] Changes to apio env options: 1. Added an env option called APIO_PLATFORM to override platform id and and deleted the --platform option from the commands that had it. 2. Renamed APIO_PKG_HOME to APIO_PACKAGES_HOME and changed its semantic such that the packages are installed directly under it and not under a 'packages' directory. In other words, it overrides ~/.apio/packages. --- apio/commands/install.py | 3 --- apio/commands/options.py | 11 ----------- apio/commands/packages.py | 3 --- apio/commands/system.py | 4 +++- apio/commands/uninstall.py | 3 --- apio/env_options.py | 16 +++++++++++++--- apio/managers/old_installer.py | 2 +- apio/resources.py | 10 +++------- apio/util.py | 29 ++++++++++------------------- test/conftest.py | 8 ++++---- test/test_end_to_end.py | 10 ++-------- 11 files changed, 36 insertions(+), 63 deletions(-) diff --git a/apio/commands/install.py b/apio/commands/install.py index bf11fb89..14adf7d9 100644 --- a/apio/commands/install.py +++ b/apio/commands/install.py @@ -70,7 +70,6 @@ def install_packages( @options.all_option_gen(help="Install all packages.") @options.force_option_gen(help="Force the packages installation.") @options.project_dir_option -@options.platform_option @options.verbose_option def cli( ctx: Context, @@ -80,7 +79,6 @@ def cli( list_: bool, all_: bool, force: bool, - platform: str, project_dir: Path, verbose: bool, ): @@ -99,7 +97,6 @@ def cli( # -- Load the resources. We don't care about project specific resources. resources = Resources( - platform_id_override=platform, project_dir=project_dir, project_scope=False, ) diff --git a/apio/commands/options.py b/apio/commands/options.py index 3257153a..8cf9611f 100644 --- a/apio/commands/options.py +++ b/apio/commands/options.py @@ -196,17 +196,6 @@ def pack_option_gen( ) -# -- NOTE: Not using -p to avoid conflict with --project-dir. -platform_option = click.option( - "platform", # Var name. - "--platform", - type=str, - metavar="platform_id", - help=("(Advanced, for developers) Platform id override."), - cls=cmd_util.ApioOption, -) - - project_dir_option = click.option( "project_dir", # Var name. "-p", diff --git a/apio/commands/packages.py b/apio/commands/packages.py index 0e66e6f4..b56d35b5 100644 --- a/apio/commands/packages.py +++ b/apio/commands/packages.py @@ -193,7 +193,6 @@ def _list(resources: Resources, verbose: bool) -> int: @fix_option @options.force_option_gen(help="Force installation.") @options.project_dir_option -@options.platform_option @options.sayyes @options.verbose_option def cli( @@ -206,7 +205,6 @@ def cli( uninstall: bool, fix: bool, force: bool, - platform: str, project_dir: Path, sayyes: bool, verbose: bool, @@ -227,7 +225,6 @@ def cli( # -- Load the resources. We don't care about project specific resources. resources = Resources( - platform_id_override=platform, project_dir=project_dir, project_scope=False, ) diff --git a/apio/commands/system.py b/apio/commands/system.py index 65f3eccb..9d88ba76 100644 --- a/apio/commands/system.py +++ b/apio/commands/system.py @@ -76,10 +76,12 @@ apio system --lsusb # List USB devices apio system --lsserial # List serial devices apio system --info # Show platform id and info. - apio system --platforms # Show supported platforms The flags --lstdi, --lsusb, --lsserial, and --info are exclusive and cannot be mixed in the same command. + +[Advanced] The system configuration can be overriden using the system env +variable APIO_HOME_DIR, APIO_PACKAGES_DIR, APIO_PLATFORM. """ diff --git a/apio/commands/uninstall.py b/apio/commands/uninstall.py index 84dbdbee..77e0a7f1 100644 --- a/apio/commands/uninstall.py +++ b/apio/commands/uninstall.py @@ -66,7 +66,6 @@ def _uninstall(packages: list, resources: Resources, sayyes, verbose: bool): @options.list_option_gen(help="List all installed packages.") @options.all_option_gen(help="Uninstall all packages.") @options.project_dir_option -@options.platform_option @options.sayyes @options.verbose_option def cli( @@ -77,7 +76,6 @@ def cli( list_: bool, all_: bool, project_dir: Path, - platform: str, sayyes: bool, verbose: bool, ): @@ -94,7 +92,6 @@ def cli( # -- Load the resources. resources = Resources( - platform_id_override=platform, project_dir=project_dir, project_scope=False, ) diff --git a/apio/env_options.py b/apio/env_options.py index 3133a3f1..91292d6a 100644 --- a/apio/env_options.py +++ b/apio/env_options.py @@ -14,16 +14,26 @@ import os from typing import List -# -- Env variable to override the apio home dir ~/.apio +# -- Env variable to override the apio home dir ~/.apio. If specified, +# -- it will contains the profile.json file and if APIO_PACKAGES_DIR is not +# -- specified, the 'packages' directory with the individual packages. APIO_HOME_DIR = "APIO_HOME_DIR" # -- Env variable to override the apio packages dir ~/.apio/packages. -APIO_PKG_DIR = "APIO_PKG_DIR" +# -- If specified, it contains the installed packages directories such as +# -- 'examples' or 'tools-oss-cad-suite. +APIO_PACKAGES_DIR = "APIO_PACKAGES_DIR" +# -- Env variable to override the platform id that is determined automatically +# -- from the system properties. If specified, the value should match one +# -- of the platforms specified in resources/platforms.json. +APIO_PLATFORM = "APIO_PLATFORM" +# -- List of all supported env options. _SUPPORTED_APIO_VARS = [ APIO_HOME_DIR, - APIO_PKG_DIR, + APIO_PACKAGES_DIR, + APIO_PLATFORM, ] diff --git a/apio/managers/old_installer.py b/apio/managers/old_installer.py index 1a69c506..7718d99c 100644 --- a/apio/managers/old_installer.py +++ b/apio/managers/old_installer.py @@ -86,7 +86,7 @@ def __init__( # -- Folder name were the packages are stored # -- # -- NOTE: we shouldn't assume the directory name since it can be - # -- overriden with APIO_PKG_DIR but since this old installer is + # -- overriden with APIO_PACKAGES_DIR but since this old installer is # -- going away, we leave this as is. (Nov 2024) dirname = "packages" diff --git a/apio/resources.py b/apio/resources.py index bbbc2488..934ac9b1 100644 --- a/apio/resources.py +++ b/apio/resources.py @@ -82,7 +82,6 @@ def __init__( self, *, project_scope: bool, - platform_id_override: str = "", project_dir: Optional[Path] = None, ): """Initializes the Resources object. 'project dir' is an optional path @@ -112,9 +111,7 @@ def __init__( self.platforms = self._load_resource(PLATFORMS_JSON) # -- Determine the platform_id for this APIO session. - self.platform_id = self._determine_platform_id( - platform_id_override, self.platforms - ) + self.platform_id = self._determine_platform_id(self.platforms) # -- Read the apio packages information self.all_packages = self._load_resource(PACKAGES_JSON) @@ -588,12 +585,11 @@ def list_fpgas(self): click.secho(f"Total: {len(self.fpgas)} fpgas\n") @staticmethod - def _determine_platform_id( - platform_id_override: str, platforms: Dict[str, Dict] - ) -> str: + def _determine_platform_id(platforms: Dict[str, Dict]) -> str: """Determines and returns the platform io based on system info and optional override.""" # -- Use override and get from the underlying system. + platform_id_override = env_options.get(env_options.APIO_PLATFORM) if platform_id_override: platform_id = platform_id_override else: diff --git a/apio/util.py b/apio/util.py index 811b385c..331f994e 100644 --- a/apio/util.py +++ b/apio/util.py @@ -189,7 +189,7 @@ def get_packages_dir() -> Path: """Return the base directory of apio packages. Packages are installed in the following folder: * Default: $APIO_HOME_DIR/packages - * $APIO_PKG_DIR/packages: if the APIO_PKG_DIR env variable is set + * $APIO_PACKAGES_DIR: if the APIO_PACKAGES_DIR env variable is set * INPUT: - pkg_name: Package name (Ex. 'examples') * OUTPUT: @@ -198,30 +198,21 @@ def get_packages_dir() -> Path: - or None if the packageis not installed """ - # -- Get the apio home dir: - # -- Ex. '/home/obijuan/.apio' - apio_home_dir = get_home_dir() - - # -- Get the APIO_PKG_DIR env variable + # -- Get the APIO_PACKAGES_DIR env variable # -- It returns None if it was not defined - apio_pkg_dir_env = env_options.get(env_options.APIO_PKG_DIR) + packaged_dir_override = env_options.get(env_options.APIO_PACKAGES_DIR) - # -- Get the pkg base dir. It is what the APIO_PKG_DIR env variable - # -- says, or the default folder if None - if apio_pkg_dir_env: - pkg_home_dir = Path(apio_pkg_dir_env) + # -- If specified, use the override. + if packaged_dir_override: + pkg_home_dir = Path(packaged_dir_override) - # -- Default value + # -- Else, use the default value. else: - pkg_home_dir = apio_home_dir - - # -- Create the package folder - # -- Ex '/home/obijuan/.apio/packages/tools-oss-cad-suite' - package_dir = pkg_home_dir / "packages" + # -- Ex '/home/obijuan/.apio/packages/tools-oss-cad-suite' + pkg_home_dir = get_home_dir() / "packages" # -- Return the folder if it exists - # if package_dir.exists(): - return package_dir + return pkg_home_dir def call(cmd): diff --git a/test/conftest.py b/test/conftest.py index 620cf4ab..6345002b 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -38,18 +38,18 @@ def decorator(): # -- Set a strange directory for executing # -- apio: it contains spaces and unicode characters # -- for testing. It should work - cwd = str(Path.cwd() / " ñ") + cwd = Path.cwd() / " ñ" # -- Debug if DEBUG: print("") print(" --> configenv():") - print(f" apio working directory: {cwd}") + print(f" apio working directory: {str(cwd)}") # -- Set the apio home dir and apio packages dir to # -- this test folder - environ["APIO_HOME_DIR"] = cwd - environ["APIO_PKG_DIR"] = cwd + environ["APIO_HOME_DIR"] = str(cwd) + environ["APIO_PACKAGES_DIR"] = str(cwd / "packages") environ["TESTING"] = "" return decorator diff --git a/test/test_end_to_end.py b/test/test_end_to_end.py index e26f2bcd..8625c561 100644 --- a/test/test_end_to_end.py +++ b/test/test_end_to_end.py @@ -85,18 +85,12 @@ def test_end_to_end1(clirunner, validate_cliresult, configenv, offline): assert "Installing package 'examples'" in result.output assert "was already installed" in result.output - # -- Execute - # -- "apio packages - # -- --install examples - # -- --platform windows_amd64 - # -- --force" + # -- Execute "apio packages --install examples --force" result = clirunner.invoke( cmd_packages, [ "--install", "examples", - "--platform", - "windows_amd64", "--force", ], ) @@ -105,7 +99,7 @@ def test_end_to_end1(clirunner, validate_cliresult, configenv, offline): assert "Download" in result.output assert "Package 'examples' installed successfully" in result.output - # -- Execute "apio packages --install --list" + # -- Execute "apio packages --list" result = clirunner.invoke(cmd_packages, ["--list"]) assert result.exit_code == 0, result.output assert "No errors" in result.output