Skip to content

Commit

Permalink
Merge pull request #25 from IRNAS/release/v0.3.0
Browse files Browse the repository at this point in the history
Release v0.3.0
  • Loading branch information
MarkoSagadin authored Oct 5, 2022
2 parents 7fac4c0 + b5d15d1 commit 1c0146e
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 50 deletions.
28 changes: 24 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [0.3.0] - 2022-10-05

### Added

- _bypass_ command, which can take any set of arguments that west command
supports and pass them directly to west tool.
- _util connect_ and _util rtt_ commands. With first you connect to the
device, with second you can observe RTT logs while connected.
- _build_ and _flash_ commands now support extra positional arguments after
double dash `--`. Run them with --help string to learn what do they do.

### Fixed

- Incorrect no toolchain message.
- \--force flag was not set as flag by Click.
- \--jlink-id should be of type str but it was not.
- No westdir related bug that came up in demonstration.

## [0.2.0] - 2022-10-03

### Added
Expand All @@ -14,16 +32,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
machine.
- Global _--echo_ flag which echoes every shell command before executing it.
- _update toolchain_ command - Command will download and install appropriate
version of toolchain based on the detected NCS version. If NCS version is
currently not supported it throws an error.
version of toolchain based on the detected NCS version. If NCS version is
currently not supported it throws an error.

### Changed

- Structure of the commands. Commands are now split into two groups: workspace
commands and system commands. This is reflected in the project directory
structure and help texts.
- Workspace commands will now use downloaded toolchain whenever they can.


## [0.1.42] - 2022-09-20

### Added
Expand All @@ -38,7 +56,9 @@ currently not supported it throws an error.
- Docker scripts for building and running docker containers, for development
purposes.

[Unreleased]: https://github.com/IRNAS/irnas-east-software/compare/v0.2.0...HEAD
[Unreleased]: https://github.com/IRNAS/irnas-east-software/compare/v0.3.0...HEAD

[0.3.0]: https://github.com/IRNAS/irnas-east-software/compare/v0.2.0...v0.3.0

[0.2.0]: https://github.com/IRNAS/irnas-east-software/compare/v0.1.42...v0.2.0

Expand Down
73 changes: 73 additions & 0 deletions patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
diff --git a/src/east/east_context.py b/src/east/east_context.py
index 30af453..54b5519 100644
--- a/src/east/east_context.py
+++ b/src/east/east_context.py
@@ -317,7 +317,7 @@ class EastContext:
self.ncs_version_supported = False
return
else:
- self.print(no_toolchain_msg)
+ self.print(no_toolchain_msg(self))
self.exit()

# Not supported, should we exit program or silently pass?
diff --git a/src/east/helper_functions.py b/src/east/helper_functions.py
index 694562a..bc7a610 100644
--- a/src/east/helper_functions.py
+++ b/src/east/helper_functions.py
@@ -195,19 +195,21 @@ To install it run:
\t[italic bold blue]east sys-setup
"""

-no_toolchain_msg = """Current [bold cyan] is supported but [bold red]instaled![/]
-
-To install it run:
-
-\t[italic bold blue]east update toolchain
-"""
-
not_in_west_workspace_msg = """[bold yellow]West workspace[/] was [bold red]not found![/]

This command can only be run [bold]inside[/] of a [bold yellow]West workspace[/].
"""


+def no_toolchain_msg(east):
+ return (
+ f"Current [bold cyan]NCS[/] [bold]{east.detected_ncs_version}[/] version is "
+ "supported but toolchain is [bold red]not installed![/]"
+ "\n\nTo install it run:"
+ "\n\n\t[italic bold blue]east update toolchain\n"
+ )
+
+
def ncs_version_not_supported_msg(east, supported_versions):
vers = "\n".join(
[f"[bold yellow]•[/] {ver}" for ver in supported_versions.strip().split("\n")]
diff --git a/src/east/workspace_commands/update_commands.py b/src/east/workspace_commands/update_commands.py
index 289a392..e9e799f 100644
--- a/src/east/workspace_commands/update_commands.py
+++ b/src/east/workspace_commands/update_commands.py
@@ -1,7 +1,12 @@
import click

from ..east_context import east_command_settings, east_group_settings
-from ..helper_functions import WestDirNotFound, get_ncs_version, west_topdir
+from ..helper_functions import (
+ WestDirNotFound,
+ get_ncs_version,
+ no_toolchain_msg,
+ west_topdir,
+)


@click.command(**east_command_settings)
@@ -21,7 +26,7 @@ You can reinstall it with [bold cyan]--force[/] flag.
@click.option(
"-f",
"--force",
- type=str,
+ is_flag=True,
help="Reinstall the toolchain, even if it is already installed.",
)
@click.pass_obj
13 changes: 8 additions & 5 deletions src/east/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import rich_click

from .east_context import EastContext, east_group_settings
from .system_commands import sys_setup
from .workspace_commands import build, clean, flash, update
from .system_commands import sys_setup, util
from .workspace_commands import build, bypass, clean, flash, update

rich_click.rich_click.MAX_WIDTH = 80
rich_click.rich_click.USE_RICH_MARKUP = True
Expand All @@ -13,14 +13,15 @@
"east": [
{
"name": "Workspace commands",
"commands": ["build", "flash", "clean", "update"],
"commands": ["build", "flash", "clean", "update", "bypass"],
},
{
"name": "System commands",
"commands": ["sys-setup"],
"commands": ["sys-setup", "util"],
},
],
"east update": [{"name": "Subcommands", "commands": ["west", "env", "toolchain"]}],
"east util": [{"name": "Subcommands", "commands": ["connect", "rtt"]}],
}


Expand All @@ -47,7 +48,7 @@ def cli(ctx, echo):
\b
\n\nNote that commands are split into two groups:
- [bold]Workspace:[/] Can only be run from inside of [bold yellow]West workspace[/],
- [bold]Workspace:[/] Can only be run from inside of [bold yellow]West workspace[/].
- [bold]System:[/] Can be run from anywhere.
"""
Expand All @@ -60,10 +61,12 @@ def cli(ctx, echo):


cli.add_command(build)
cli.add_command(bypass)
cli.add_command(flash)
cli.add_command(clean)
cli.add_command(update)
cli.add_command(sys_setup)
cli.add_command(util)


def main():
Expand Down
23 changes: 13 additions & 10 deletions src/east/east_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ def __init__(self, echo: bool = False):
# do not count.
self.cwd = os.getcwd()
self.echo = echo

# Create EAST_DIR and its parents if they do not exists
os.makedirs(EAST_DIR, exist_ok=True)

self.console = Console(width=80)
self.run(f"mkdir -p {EAST_DIR}")
self.ncs_version_installed = False
self.ncs_version_supported = False

Expand Down Expand Up @@ -108,9 +111,9 @@ def print_markdown(self, *objects, **kwargs):

self.print(Markdown(*objects, **markdown_kwargs), **print_kwargs)

def exit(self):
"""Exit program"""
sys.exit()
def exit(self, return_code: int = 1):
"""Exit program with given return_code"""
sys.exit(return_code)

def run(
self,
Expand Down Expand Up @@ -166,7 +169,7 @@ def execute(cmd, exit_on_err):
popen.stdout.close()
return_code = popen.wait()
if exit_on_err and return_code:
self.exit()
self.exit(return_code)

output = []

Expand All @@ -188,8 +191,8 @@ def execute(cmd, exit_on_err):
p.communicate()

# Should we exit on the error?
if exit_on_error and p.returncode != 0:
self.exit()
if exit_on_error and p.returncode:
self.exit(p.returncode)

def run_west(self, west_command: str, **kwargs) -> str:
"""Run wrapper which should be used when executing commands with west tool.
Expand Down Expand Up @@ -292,12 +295,12 @@ def pre_workspace_command_check(
"""
# Exit if we are not inside west workspace
if not self.west_dir_path:
self.print(not_in_west_workspace_msg)
self.print(not_in_west_workspace_msg, highlight=False)
self.exit()

# Exit if manager is not installed
if not self.check_exe(NRF_TOOLCHAIN_MANAGER_PATH):
self.print(no_toolchain_manager_msg)
self.print(no_toolchain_manager_msg, highlight=False)
self.exit()

# # Check if toolchain for detected ncs version is installed
Expand All @@ -317,7 +320,7 @@ def pre_workspace_command_check(
self.ncs_version_supported = False
return
else:
self.print(no_toolchain_msg)
self.print(no_toolchain_msg(self), highlight=False)
self.exit()

# Not supported, should we exit program or silently pass?
Expand Down
35 changes: 16 additions & 19 deletions src/east/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def check_python_version(east):
# Nicely print a list of supported python version in markdown
vers_str = [f"- v{ver['major']}.{ver['minor']}.x" for ver in vers]
east.print_markdown("\n".join(vers_str))
exit()
east.exit()


def download_file(task_id: TaskID, url: str, path: str):
Expand Down Expand Up @@ -125,16 +125,14 @@ class WestDirNotFound(RuntimeError):
"""Neither the current directory nor any parent has a west workspace."""


def west_topdir(start: Optional[PathType] = None, fall_back: bool = True) -> str:
def west_topdir(start: Optional[PathType] = None) -> str:
"""
Returns the path to the parent directory of the .west/
directory instead, where project repositories are stored.
Args:
start (Optional[PathType]): Directory from where to start searching, if not
given current directory is used.
fall_back (bool): Wheter to fallback to ZEPHYR_BASE variable as
start argument.
Returns:
Full path to parent directory of the .west/ folder.
Expand All @@ -147,13 +145,10 @@ def west_topdir(start: Optional[PathType] = None, fall_back: bool = True) -> str

parent_dir = cur_dir.parent
if cur_dir == parent_dir:
# At the root. Should we fall back?
if fall_back and os.environ.get("ZEPHYR_BASE"):
return west_topdir(os.environ["ZEPHYR_BASE"], fall_back=False)
else:
raise WestDirNotFound(
"Could not find a west workspace in this or any parent directory"
)
# We are at top level
raise WestDirNotFound(
"Could not find a west workspace in this or any parent directory"
)
cur_dir = parent_dir


Expand Down Expand Up @@ -188,26 +183,28 @@ def get_ncs_version(west_dir_path: str) -> str:
return ncs[0]["revision"]


no_toolchain_manager_msg = """[bold cyan]Nordic's Toolchain Manager[/] is [bold red]not installed[/] on this system!"
no_toolchain_manager_msg = """[bold cyan]Nordic's Toolchain Manager[/] is [bold red]not installed[/] on this system!
To install it run:
\t[italic bold blue]east sys-setup
"""

no_toolchain_msg = """Current [bold cyan] is supported but [bold red]instaled![/]
To install it run:
\t[italic bold blue]east update toolchain
"""

not_in_west_workspace_msg = """[bold yellow]West workspace[/] was [bold red]not found![/]
This command can only be run [bold]inside[/] of a [bold yellow]West workspace[/].
"""


def no_toolchain_msg(east):
return (
f"Current [bold cyan]NCS[/] [bold]{east.detected_ncs_version}[/] version is "
"supported but toolchain is [bold red]not installed![/]"
"\n\nTo install it run:"
"\n\n\t[italic bold blue]east update toolchain\n"
)


def ncs_version_not_supported_msg(east, supported_versions):
vers = "\n".join(
[f"[bold yellow]•[/] {ver}" for ver in supported_versions.strip().split("\n")]
Expand Down
1 change: 1 addition & 0 deletions src/east/system_commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .sys_setup import sys_setup
from .util_commands import util
2 changes: 1 addition & 1 deletion src/east/system_commands/sys_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def sys_setup(east):

if all([package["installed"] == True for package in packages]):
east.print("\n[green]All required system packages and programs are installed.")
east.exit()
east.exit(0)

# Download all required files, which are actually programs or installer scripts
paths = download_files(urls, CACHE_DIR)
Expand Down
Loading

0 comments on commit 1c0146e

Please sign in to comment.