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
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,5 @@
www
wxgui
xml
version-check

Check warning on line 284 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Spell checking

ignoring entry because it contains non alpha characters (non-alpha-in-dictionary)
0x48piraj
19 changes: 2 additions & 17 deletions src/fprime/util/build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from fprime.fbuild.cli import get_target
from fprime.fbuild.target import NoSuchTargetException

from .versioning import VersionException, get_version
from .versioning import VersionException, get_version, FPRIME_PIP_PACKAGES

# Attempt to get pkg_resources from "setuptools"
try:
Expand Down Expand Up @@ -68,22 +68,7 @@ def validate_tools_from_requirements(build: Build):
return

# Now check each required tool for fprime
tools = [
"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:
for tool in FPRIME_PIP_PACKAGES:
for possible in possibilities:
try:
package_version_check(tool, possible)
Expand Down
20 changes: 19 additions & 1 deletion src/fprime/util/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
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_version_check,
)
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 @@ -56,6 +62,8 @@ def skip_build_loading(parsed):
"""
if parsed.command == "new" and parsed.new_project:
return True
if parsed.command == "version-check":
return True
return False


Expand Down Expand Up @@ -111,6 +119,15 @@ def add_special_parsers(
formatter_class=argparse.RawDescriptionHelpFormatter,
)

subparsers.add_parser(
"version-check",
description=help_text.long("version-check"),
help=help_text.short("version-check"),
parents=[common],
add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter,
)

# New functionality
new_parser = subparsers.add_parser(
"new",
Expand Down Expand Up @@ -211,6 +228,7 @@ def add_special_parsers(
return {
"hash-to-file": run_hash_to_file,
"info": run_info,
"version-check": run_version_check,
"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
- version-check: 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, FPRIME_PIP_PACKAGES
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_version_check(
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
try:
import platform

print(f"Python version: {platform.python_version()}")
print(f"Operating System: {platform.system()}")
print(f"CPU Architecture: {platform.machine()}")
print(f"Platform: {platform.platform()}")
except ImportError: # Python >=3.6
print("[WARNING] Cannot import 'platform'.")

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

print("Pip packages:")
for tool in FPRIME_PIP_PACKAGES:
try:
version = pkg_resources.get_distribution(tool).version
print(f" {tool}=={version}")
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.
""",
"version-check": f"""Print out toolchain versions to help debugging

'{EXECUTABLE} version-check' 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 version-check command as a tool for debugging and comprehending the dependencies for {EXECUTABLE}.

'{EXECUTABLE} version-check' will print information about toolchain versions for debugging purposes.
""",
"hash-to-file": f"""Convert FW_ASSERT file id hash to file path

Expand Down
17 changes: 17 additions & 0 deletions src/fprime/util/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ class VersionException(Exception):
pass


FPRIME_PIP_PACKAGES = [
"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",
]


def get_version(package: str, requirements: Path):
"""Get the version as specified in the requirements file

Expand Down
53 changes: 53 additions & 0 deletions test/fprime/util/commands_unit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
(test) fprime-utils commands:

Tests the F prime util commands.
@author 0x48piraj
"""

import unittest


class CommandsTestCases(unittest.TestCase):
thomas-bc marked this conversation as resolved.
Show resolved Hide resolved
def test_build_command(self):
pass

def test_check_command(self):
pass

def test_generate_command(self):
pass

def test_purge_command(self):
pass

def test_fpp_check_command(self):
pass

def test_fpp_to_xml_command(self):
pass

def test_visualize_command(self):
pass

def test_impl_command(self):
pass

def test_hash_to_file_command(self):
pass

def test_info_command(self):
pass

def test_new_command(self):
pass

def test_format_command(self):
pass

def test_version_check_command(self):
pass


if __name__ == "__main__":
unittest.main()
Loading