Skip to content

Commit

Permalink
Merge pull request #117 from MOV-AI/dev
Browse files Browse the repository at this point in the history
Release DP-1518
  • Loading branch information
AlexFernandes-MOVAI authored Feb 21, 2025
2 parents f8704e2 + 238eba4 commit 3602e1e
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 32 deletions.
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-docstring-first # checks if docstring is before code
- id: check-json # checks if json files are valid
- id: check-added-large-files # checks if large files were added
- id: check-merge-conflict # checks if all merge conflicts were resolved
- id: check-yaml # checks if yaml files are valid
- id: debug-statements # checks if debug statements are to be commited
- id: end-of-file-fixer # fixes missing line ending in end of file
- id: mixed-line-ending # fixes line files line ending
args: [--fix=lf]
- id: trailing-whitespace # removes trailing whitespaces from text files
exclude: .bumpversion.cfg # a tool edits this file and leaves trailing spaces, must be ignored
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck
args: ["--severity=warning"] # Optionally only show errors and warnings

- repo: https://github.com/ambv/black # formats Python code
rev: 25.1.0
hooks:
- id: black
args: ["--line-length=120", "-S"]

- repo: https://github.com/pycqa/flake8 # static tests Python code
rev: 7.1.2
hooks:
- id: flake8
args: ['--config', '.flake8']

# pylint does dynamic testing using data from imported modules
# thus the modules need to be found by it
# the easiest way to accomplish this is using it as a local hook
# see https://stackoverflow.com/questions/61238318/pylint-and-pre-commit-hook-unable-to-import
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: python
types: [python]
require_serial: true
args: [ "-E"]
62 changes: 41 additions & 21 deletions mobros/commands/ros_install_build_deps/catkin_package.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" Module with the ability to interpret a catkin package.xml into a runtime object
"""
"""Module with the ability to interpret a catkin package.xml into a runtime object"""

import xml.etree.ElementTree as ET
from os.path import isfile, join

Expand All @@ -9,7 +9,7 @@


def is_catkin_blacklisted(path):
""" Function that checks if a given path contains a catkin blacklist file
"""Function that checks if a given path contains a catkin blacklist file
Args:
path (os.path): OS path
Expand All @@ -24,7 +24,7 @@ def is_catkin_blacklisted(path):


class CatkinPackage:
""" Class that represents a catkin package and its dependencies"""
"""Class that represents a catkin package and its dependencies"""

def __init__(self, package_path, workspace_pkg_list=None):

Expand Down Expand Up @@ -84,35 +84,55 @@ def _find_dependencies(self, dependency_type, dependency_object, xml_root, black
if dependency_name in blacklist:
continue

deb_name = utilitary.translate_package_name(dependency_name)
deb_names = utilitary.translate_package_name(dependency_name)
self._process_deb_names(deb_names, dependency_object, child)

def _process_deb_names(self, deb_names, dependency_object, child):
"""Helper function to process debian package names
Args:
deb_names (list): List of debian package names
dependency_object (dict): Dictionary to store dependencies
child (xml_obj): XML element representing the dependency
"""
for deb_name in deb_names:
logging.debug(
"[Dependency_Manager - check_colisions] Dependency: "
+ dependency_name
+ child.text.strip()
+ " has been translated to "
+ deb_name
)

if deb_name not in dependency_object:
dependency_object[deb_name] = []

if child.attrib:
for key in child.attrib:
dependency_operator = key
dependency_version = child.attrib[key]

dependency_object[deb_name].append(
{
"operator": dependency_operator,
"version": dependency_version,
"from": self.package_name,
}
)
else:
self._add_dependency(deb_name, dependency_object, child)

def _add_dependency(self, deb_name, dependency_object, child):
"""Helper function to add a dependency to the dependency object
Args:
deb_name (str): Debian package name
dependency_object (dict): Dictionary to store dependencies
child (xml_obj): XML element representing the dependency
"""
if child.attrib:
for key in child.attrib:
dependency_operator = key
dependency_version = child.attrib[key]

dependency_object[deb_name].append(
{
"operator": "",
"version": None,
"operator": dependency_operator,
"version": dependency_version,
"from": self.package_name,
}
)
else:
dependency_object[deb_name].append(
{
"operator": "",
"version": None,
"from": self.package_name,
}
)
21 changes: 13 additions & 8 deletions mobros/utils/utilitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,26 @@ def translate_package_name(rosdep_key):
rosdep_key (str): catkin package name
Returns:
debian_pkg_name : debian package name
debian_pkg_name : list of debian package names
"""
output_lines = execute_shell_command(
["rosdep", "resolve", rosdep_key], stop_on_error=True, log_output=False
)

translation = []

for line in output_lines:
if ROSDEP_RESULT_HEADER not in line:
translation = line.strip()
logging.debug(
"[rosdep translate] Found translation for "
+ rosdep_key
+ ". It is "
+ translation
)
translation = line.strip().split(" ")

if translation:
logging.debug(
"[rosdep translate] Found translation for "
+ rosdep_key
+ ". It is "
+ str(translation)
)

return translation

def write_to_file(path_to_file, content):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_executers/test_catkin_package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from mobros.commands.ros_install_build_deps.catkin_package import CatkinPackage

mock_rosdep_translate_map = {
"ompl": "ros-noetic-ompl",
"movai_navigation": "ros-noetic-movai-navigation",
"ompl": ["ros-noetic-ompl"],
"movai_navigation": ["ros-noetic-movai-navigation"],
}


Expand Down
2 changes: 1 addition & 1 deletion tests/test_executers/test_install_build_deps_executer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def mock_inspect_package(deb_name, version):
return_value=None,
)
@mock.patch(
"mobros.utils.utilitary.translate_package_name", return_value="ros-noetic-mobros"
"mobros.utils.utilitary.translate_package_name", return_value=["ros-noetic-mobros"]
)
@mock.patch(
"mobros.utils.apt_utils.execute_shell_command",
Expand Down

0 comments on commit 3602e1e

Please sign in to comment.