Skip to content

Commit

Permalink
Changes to apio env options:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zapta committed Nov 18, 2024
1 parent fdfe975 commit fe706ee
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 63 deletions.
3 changes: 0 additions & 3 deletions apio/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -80,7 +79,6 @@ def cli(
list_: bool,
all_: bool,
force: bool,
platform: str,
project_dir: Path,
verbose: bool,
):
Expand All @@ -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,
)
Expand Down
11 changes: 0 additions & 11 deletions apio/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions apio/commands/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -206,7 +205,6 @@ def cli(
uninstall: bool,
fix: bool,
force: bool,
platform: str,
project_dir: Path,
sayyes: bool,
verbose: bool,
Expand All @@ -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,
)
Expand Down
4 changes: 3 additions & 1 deletion apio/commands/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""


Expand Down
3 changes: 0 additions & 3 deletions apio/commands/uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -77,7 +76,6 @@ def cli(
list_: bool,
all_: bool,
project_dir: Path,
platform: str,
sayyes: bool,
verbose: bool,
):
Expand All @@ -94,7 +92,6 @@ def cli(

# -- Load the resources.
resources = Resources(
platform_id_override=platform,
project_dir=project_dir,
project_scope=False,
)
Expand Down
16 changes: 13 additions & 3 deletions apio/env_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]


Expand Down
2 changes: 1 addition & 1 deletion apio/managers/old_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
10 changes: 3 additions & 7 deletions apio/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
29 changes: 10 additions & 19 deletions apio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions test/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand All @@ -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
Expand Down

0 comments on commit fe706ee

Please sign in to comment.