Skip to content

Commit

Permalink
Refactoring and formatting (nasa/fprime#2407)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x48piraj committed Jan 10, 2024
1 parent d062360 commit 3080397
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 58 deletions.
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 @@ workdir
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
18 changes: 2 additions & 16 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, get_toolchain

# Attempt to get pkg_resources from "setuptools"
try:
Expand Down Expand Up @@ -68,21 +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",
]
tools = get_toolchain()
for tool in tools:
for possible in possibilities:
try:
Expand Down
18 changes: 13 additions & 5 deletions 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, run_sysinfo
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
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 @@ -112,9 +120,9 @@ def add_special_parsers(
)

subparsers.add_parser(
"sysinfo",
description=help_text.long("sysinfo"),
help=help_text.short("sysinfo"),
"version-check",
description=help_text.long("version-check"),
help=help_text.short("version-check"),
parents=[common],
add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down Expand Up @@ -220,7 +228,7 @@ def add_special_parsers(
return {
"hash-to-file": run_hash_to_file,
"info": run_info,
"sysinfo": run_sysinfo,
"version-check": run_version_check,
"new": run_new,
"format": run_code_format,
}
Expand Down
52 changes: 24 additions & 28 deletions src/fprime/util/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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
- version-check: Print out versions to help debugging
@author thomas-bc
"""
Expand All @@ -18,7 +18,7 @@

from fprime.fbuild.builder import Build, InvalidBuildCacheException
from fprime.util.code_formatter import ClangFormatter
from .versioning import VersionException
from .versioning import VersionException, get_toolchain
from fprime.util.cookiecutter_wrapper import (
new_component,
new_deployment,
Expand Down Expand Up @@ -186,50 +186,46 @@ def run_code_format(
return clang_formatter.execute(build, parsed.path, ({}, parsed.pass_through))


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

print(f"Python version: {sys.version_info.major}{sys.version_info.minor}.{sys.version_info.micro}")
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]

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
except ImportError: # Python >=3.6
print("[WARNING] Cannot import 'subprocess'. ")

try:
import pip

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

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

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",
]
tools = get_toolchain()
print("Pip packages:")
for tool in tools:
try:
version = pkg_resources.get_distribution(tool).version
print(f"{tool} version: {version}")
except (OSError, VersionException) as exc:
print(f"[WARNING] {exc}")
try:
version = pkg_resources.get_distribution(tool).version
print(f" {tool}=={version}")
except (OSError, VersionException) as exc:
print(f"[WARNING] {exc}")
8 changes: 4 additions & 4 deletions src/fprime/util/help_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@
'{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
"version-check": f"""Print out toolchain versions to help debugging
'{EXECUTABLE} sysinfo' is used to display information about toolchain versions. It will output details such as
'{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 sysinfo command as a tool for debugging and comprehending the dependencies for {EXECUTABLE}.
before exiting. Users can utilize the version-check command as a tool for debugging and comprehending the dependencies for {EXECUTABLE}.
'{EXECUTABLE} sysinfo' will print information about toolchain versions for debugging purposes.
'{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
18 changes: 18 additions & 0 deletions src/fprime/util/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ class VersionException(Exception):
pass


def get_toolchain():
return [
"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
10 changes: 5 additions & 5 deletions test/fprime/util/commands_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import unittest
from fprime.util.commands import run_code_format, run_hash_to_file, run_info, run_new, run_sysinfo


class CommandsTestCases(unittest.TestCase):
Expand All @@ -22,10 +21,10 @@ def test_generate_command(self):
def test_purge_command(self):
pass

def test_fppcheck_command(self):
def test_fpp_check_command(self):
pass

def test_fpptoxml_command(self):
def test_fpp_to_xml_command(self):
pass

def test_visualize_command(self):
Expand All @@ -34,7 +33,7 @@ def test_visualize_command(self):
def test_impl_command(self):
pass

def test_hashtofile_command(self):
def test_hash_to_file_command(self):
pass

def test_info_command(self):
Expand All @@ -46,8 +45,9 @@ def test_new_command(self):
def test_format_command(self):
pass

def test_sysinfo_command(self):
def test_version_check_command(self):
pass


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

0 comments on commit 3080397

Please sign in to comment.