Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version check command #190

Merged
merged 8 commits into from
Jan 16, 2024
12 changes: 11 additions & 1 deletion src/fprime/util/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from fprime.fbuild.target import Target
from fprime.fpp.cli import add_fpp_parsers
from fprime.util.build_helper import load_build
from fprime.util.commands import run_code_format, run_hash_to_file, run_info, run_new
from fprime.util.commands import run_code_format, run_hash_to_file, run_info, run_new, run_sysinfo

Check failure on line 19 in src/fprime/util/cli.py

View workflow job for this annotation

GitHub Actions / Spell checking

`sysinfo` is not a recognized word. (unrecognized-spelling)
from fprime.util.help_text import HelpText
from fprime.fpp.visualize import add_fpp_viz_parsers
from fprime.fpp.impl import add_fpp_impl_parsers
thomas-bc marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -111,6 +111,15 @@
formatter_class=argparse.RawDescriptionHelpFormatter,
)

subparsers.add_parser(
"sysinfo",

Check failure on line 115 in src/fprime/util/cli.py

View workflow job for this annotation

GitHub Actions / Spell checking

`sysinfo` is not a recognized word. (unrecognized-spelling)
description=help_text.long("sysinfo"),

Check failure on line 116 in src/fprime/util/cli.py

View workflow job for this annotation

GitHub Actions / Spell checking

`sysinfo` is not a recognized word. (unrecognized-spelling)
help=help_text.short("sysinfo"),

Check failure on line 117 in src/fprime/util/cli.py

View workflow job for this annotation

GitHub Actions / Spell checking

`sysinfo` is not a recognized word. (unrecognized-spelling)
parents=[common],
add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter,
)

# New functionality
new_parser = subparsers.add_parser(
"new",
Expand Down Expand Up @@ -211,6 +220,7 @@
return {
"hash-to-file": run_hash_to_file,
"info": run_info,
"sysinfo": run_sysinfo,

Check failure on line 223 in src/fprime/util/cli.py

View workflow job for this annotation

GitHub Actions / Spell checking

`sysinfo` is not a recognized word. (unrecognized-spelling)
thomas-bc marked this conversation as resolved.
Show resolved Hide resolved
"new": run_new,
"format": run_code_format,
}
Expand Down
52 changes: 52 additions & 0 deletions src/fprime/util/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- hash-to-file: Processes hash-to-file to locate file
- new: Creates a new component, deployment, or project
- format: Formats code using clang-format
- sysinfo: Print out versions to help debugging

@author thomas-bc
"""
Expand All @@ -17,6 +18,7 @@

from fprime.fbuild.builder import Build, InvalidBuildCacheException
from fprime.util.code_formatter import ClangFormatter
from .versioning import VersionException
from fprime.util.cookiecutter_wrapper import (
new_component,
new_deployment,
Expand Down Expand Up @@ -182,3 +184,53 @@ def run_code_format(
for filename in parsed.files:
clang_formatter.stage_file(Path(filename))
return clang_formatter.execute(build, parsed.path, ({}, parsed.pass_through))


def run_sysinfo(
base: Build, parsed: argparse.Namespace, _: Dict[str, str], __: Dict[str, str], ___
):
"""Print out versions to help debugging"""

thomas-bc marked this conversation as resolved.
Show resolved Hide resolved
print(f"Python version: {sys.version_info.major}{sys.version_info.minor}.{sys.version_info.micro}")

try:
import subprocess
cmake_version = subprocess.check_output(['cmake', '--version']).decode('utf-8').splitlines()[0].split()[2]
print(f"CMake version: {cmake_version}")
except ImportError: # Python >=3.6
print("[WARNING] Cannot import 'subprocess'. ")

try:
import pip
print(f"Pip version: {pip.__version__}")
except ModuleNotFoundError: # Python >=3.6
print("[WARNING] Cannot import 'Pip'.")

try:
import pkg_resources
except ModuleNotFoundError: # Python >=3.6
print("[WARNING] Cannot import 'pkg_resources'. Will not check tool versions.")
return

tools = [
0x48piraj marked this conversation as resolved.
Show resolved Hide resolved
"fprime-tools",
"fprime-gds",
"fprime-fpp-to-xml",
"fprime-fpp-to-json",
"fprime-fpp-to-cpp",
"fprime-fpp-syntax",
"fprime-fpp-locate-uses",
"fprime-fpp-locate-defs",
"fprime-fpp-from-xml",
"fprime-fpp-format",
"fprime-fpp-filenames",
"fprime-fpp-depend",
"fprime-fpp-check",
]
for tool in tools:
try:
version = pkg_resources.get_distribution(tool).version
print(f"{tool} version: {version}")
0x48piraj marked this conversation as resolved.
Show resolved Hide resolved
break
except (OSError, VersionException) as exc:
print(f"[WARNING] {exc}")
10 changes: 9 additions & 1 deletion src/fprime/util/help_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,22 @@
""",
"info": f"""Print contextual target and build cache information before exiting

'{EXECUTABLE} info' is used to print contextual information to the user before exiting. It will print the available]
'{EXECUTABLE} info' is used to print contextual information to the user before exiting. It will print the available
commands within the current context (working directory, '-p/--path', '-r/--root', etc.) and then exit. Users may
use the info command as a way to test and understand how {EXECUTABLE} is mapping to the context and targets used. info
may also be used to locate the artifact output folders within the build cache in order to see generated files, compiler
outputs, etc.

'{EXECUTABLE} info' will print information for both normal and unit testing builds when possible. If '--build-cache' is
specified then only the information for that build cache will be printed.
""",
"sysinfo": f"""Print out toolchain versions to help debugging

'{EXECUTABLE} sysinfo' is used to display information about toolchain versions. It will output details such as
the installed Python version, the installed Pip version, and version information for all the necessary tools for fprime
before exiting. Users can utilize the sysinfo command as a tool for debugging and comprehending the dependencies for {EXECUTABLE}.

'{EXECUTABLE} sysinfo' will print information about toolchain versions for debugging purposes.

Check warning on line 259 in src/fprime/util/help_text.py

View workflow job for this annotation

GitHub Actions / Spell checking

`sysinfo` is not a recognized word -- found 12 times. (limited-references)
""",
"hash-to-file": f"""Convert FW_ASSERT file id hash to file path

Expand Down
Loading