Skip to content

Commit 46f6d9c

Browse files
authored
Code style (#96)
2 parents 0cf4dda + 8880acc commit 46f6d9c

25 files changed

+554
-423
lines changed

.clang-format

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
ColumnLimit: 120

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Add git commit hashes to ignore for blame
2+
e87343d297ec4c7059f8aa240bfafd59b8fe686e

.github/workflows/pre-commit.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Code style checks
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v4
14+
- name: Install cppcheck
15+
run: sudo apt install cppcheck -y
16+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.1.6
4+
hooks:
5+
- id: ruff
6+
args:
7+
- "--fix"
8+
- "--exit-non-zero-on-fix"
9+
- repo: https://github.com/psf/black
10+
rev: 23.11.0
11+
hooks:
12+
- id: black
13+
- repo: https://github.com/pocc/pre-commit-hooks
14+
rev: v1.3.5
15+
hooks:
16+
- id: clang-format
17+
args:
18+
- "-i"
19+
- id: cppcheck
20+
args:
21+
- "--suppress=missingInclude"
22+
- "--suppress=unmatchedSuppression"
23+
- "--suppress=unusedFunction"

dynamic_stack_decider/docs/conf.py

+34-40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Full list of options at http://www.sphinx-doc.org/en/master/config
43

@@ -10,28 +9,30 @@
109
#
1110
import os
1211
import sys
13-
import catkin_pkg.package
1412

13+
import catkin_pkg.package
1514
from exhale import utils
1615

1716
package_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1817
catkin_package = catkin_pkg.package.parse_package(
19-
os.path.join(package_dir, catkin_pkg.package.PACKAGE_MANIFEST_FILENAME))
18+
os.path.join(package_dir, catkin_pkg.package.PACKAGE_MANIFEST_FILENAME)
19+
)
2020
sys.path.insert(0, os.path.abspath(os.path.join(package_dir, "src")))
2121

2222

2323
# -- Helper functions --------------------------------------------------------
2424

25+
2526
def count_files():
2627
""":returns tuple of (num_py, num_cpp)"""
2728
num_py = 0
2829
num_cpp = 0
2930

30-
for root, dirs, files in os.walk(os.path.join(package_dir, "src")):
31+
for _root, _dirs, files in os.walk(os.path.join(package_dir, "src")):
3132
for f in files:
3233
if f.endswith(".py"):
3334
num_py += 1
34-
for root, dirs, files in os.walk(os.path.join(package_dir, "include")):
35+
for _root, _dirs, files in os.walk(os.path.join(package_dir, "include")):
3536
for f in files:
3637
if f.endswith(".h") or f.endswith(".hpp"):
3738
num_cpp += 1
@@ -42,7 +43,7 @@ def count_files():
4243
# -- Project information -----------------------------------------------------
4344

4445
project = catkin_package.name
45-
copyright = '2019, Bit-Bots'
46+
copyright = "2019, Bit-Bots"
4647
author = ", ".join([a.name for a in catkin_package.authors])
4748

4849
# The short X.Y version
@@ -60,27 +61,27 @@ def count_files():
6061
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
6162
# ones.
6263
extensions = [
63-
'sphinx.ext.autodoc',
64-
'sphinx.ext.doctest',
65-
'sphinx.ext.intersphinx',
66-
'sphinx.ext.todo',
67-
'sphinx.ext.coverage',
68-
'sphinx.ext.imgmath',
69-
'sphinx.ext.viewcode',
70-
'sphinx_rtd_theme',
64+
"sphinx.ext.autodoc",
65+
"sphinx.ext.doctest",
66+
"sphinx.ext.intersphinx",
67+
"sphinx.ext.todo",
68+
"sphinx.ext.coverage",
69+
"sphinx.ext.imgmath",
70+
"sphinx.ext.viewcode",
71+
"sphinx_rtd_theme",
7172
]
7273

7374
# Add any paths that contain templates here, relative to this directory.
74-
templates_path = ['_templates']
75+
templates_path = ["_templates"]
7576

7677
# The suffix(es) of source filenames.
7778
# You can specify multiple suffix as a list of string:
7879
#
7980
# source_suffix = ['.rst', '.md']
80-
source_suffix = '.rst'
81+
source_suffix = ".rst"
8182

8283
# The master toctree document.
83-
master_doc = 'index'
84+
master_doc = "index"
8485

8586
# The language for content autogenerated by Sphinx. Refer to documentation
8687
# for a list of supported languages.
@@ -92,7 +93,7 @@ def count_files():
9293
# List of patterns, relative to source directory, that match files and
9394
# directories to ignore when looking for source files.
9495
# This pattern also affects html_static_path and html_extra_path.
95-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
96+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
9697

9798
# The name of the Pygments (syntax highlighting) style to use.
9899
pygments_style = None
@@ -108,24 +109,17 @@ def count_files():
108109

109110
if num_files_cpp > 0:
110111
extensions += [
111-
'breathe',
112-
'exhale',
112+
"breathe",
113+
"exhale",
113114
]
114115

115-
breathe_projects = {
116-
project: os.path.join("_build", "doxyoutput", "xml")
117-
}
116+
breathe_projects = {project: os.path.join("_build", "doxyoutput", "xml")}
118117
breathe_default_project = project
119118

120119
def specifications_for_kind(kind):
121120
# Show all members for classes and structs
122121
if kind == "class" or kind == "struct":
123-
return [
124-
":members:",
125-
":protected-members:",
126-
":private-members:",
127-
":undoc-members:"
128-
]
122+
return [":members:", ":protected-members:", ":private-members:", ":undoc-members:"]
129123
# An empty list signals to Exhale to use the defaults
130124
else:
131125
return []
@@ -136,21 +130,19 @@ def specifications_for_kind(kind):
136130
"rootFileName": "library_root.rst",
137131
"rootFileTitle": "C++ Library API",
138132
"doxygenStripFromPath": "..",
139-
"customSpecificationsMapping": utils.makeCustomSpecificationsMapping(
140-
specifications_for_kind
141-
),
133+
"customSpecificationsMapping": utils.makeCustomSpecificationsMapping(specifications_for_kind),
142134
# Suggested optional arguments
143135
"createTreeView": True,
144136
"exhaleExecutesDoxygen": True,
145-
"exhaleDoxygenStdin": "INPUT = {}".format(os.path.join(package_dir, "include"))
137+
"exhaleDoxygenStdin": "INPUT = {}".format(os.path.join(package_dir, "include")),
146138
}
147139

148140
# -- Options for HTML output -------------------------------------------------
149141

150142
# The theme to use for HTML and HTML Help pages. See the documentation for
151143
# a list of builtin themes.
152144
#
153-
html_theme = 'sphinx_rtd_theme'
145+
html_theme = "sphinx_rtd_theme"
154146

155147
# Theme options are theme-specific and customize the look and feel of a theme
156148
# further. For a list of options available for each theme, see the
@@ -161,7 +153,7 @@ def specifications_for_kind(kind):
161153
# Add any paths that contain custom static files (such as style sheets) here,
162154
# relative to this directory. They are copied after the builtin static files,
163155
# so a file named "default.css" will overwrite the builtin "default.css".
164-
html_static_path = ['_static']
156+
html_static_path = ["_static"]
165157

166158
# Custom sidebar templates, must be a dictionary that maps document names
167159
# to template names.
@@ -173,21 +165,23 @@ def specifications_for_kind(kind):
173165
#
174166
# html_sidebars = {}
175167

176-
html_logo = os.path.join('_static', 'logo.png')
177-
html_favicon = os.path.join('_static', 'logo.png')
168+
html_logo = os.path.join("_static", "logo.png")
169+
html_favicon = os.path.join("_static", "logo.png")
178170

179171

180172
# -- Options for intersphinx extension ---------------------------------------
181173

182174
# Example configuration for intersphinx: refer to the Python standard library.
183-
intersphinx_mapping = {'https://docs.python.org/': None}
175+
intersphinx_mapping = {"https://docs.python.org/": None}
184176

185177
# -- Options for todo extension ----------------------------------------------
186178

187179
# If true, `todo` and `todoList` produce output, else they produce nothing.
188180
todo_include_todos = True
189181

190182
# -- RST Standard variables ---------------------------------------------------
191-
rst_prolog = ".. |project| replace:: {}\n".format(project)
183+
rst_prolog = f".. |project| replace:: {project}\n"
192184
rst_prolog += ".. |description| replace:: {}\n".format(catkin_package.description.replace("\n\n", "\n"))
193-
rst_prolog += ".. |modindex| replace:: {}\n".format(":ref:`modindex`" if num_files_py > 0 else "Python module index is not available")
185+
rst_prolog += ".. |modindex| replace:: {}\n".format(
186+
":ref:`modindex`" if num_files_py > 0 else "Python module index is not available"
187+
)
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from .dsd import DSD
2-
from .abstract_decision_element import AbstractDecisionElement
3-
from .abstract_action_element import AbstractActionElement

dynamic_stack_decider/dynamic_stack_decider/abstract_action_element.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABCMeta
2+
23
from dynamic_stack_decider.abstract_stack_element import AbstractStackElement
34

45

@@ -12,6 +13,7 @@ class AbstractActionElement(AbstractStackElement, metaclass=ABCMeta):
1213
Actions do not push further elements on the stack but command actions on lower-level modules like new movement goals.
1314
If the action is complete, it can remove itself from the stack by performing a pop command.
1415
"""
16+
1517
def __init__(self, blackboard, dsd, parameters=None):
1618
"""
1719
Constructor of the action element
@@ -22,7 +24,7 @@ def __init__(self, blackboard, dsd, parameters=None):
2224
super().__init__(blackboard, dsd, parameters)
2325
# Reevaluation can be disabled by setting 'r' or 'reevaluate' to False
2426
if parameters is not None:
25-
self.never_reevaluate = not parameters.get('r', True) or not parameters.get('reevaluate', True)
27+
self.never_reevaluate = not parameters.get("r", True) or not parameters.get("reevaluate", True)
2628
else:
2729
self.never_reevaluate = False
2830

@@ -39,8 +41,4 @@ def repr_dict(self):
3941
4042
:rtype: dict
4143
"""
42-
return {
43-
'type': 'action',
44-
'classname': self.__class__.__name__,
45-
'debug_data': self._debug_data
46-
}
44+
return {"type": "action", "classname": self.__class__.__name__, "debug_data": self._debug_data}

dynamic_stack_decider/dynamic_stack_decider/abstract_decision_element.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABCMeta
2+
23
from dynamic_stack_decider.abstract_stack_element import AbstractStackElement
34

45

@@ -25,11 +26,7 @@ def repr_dict(self):
2526
2627
:rtype: dict
2728
"""
28-
return {
29-
'type': 'decision',
30-
'classname': self.__class__.__name__,
31-
'debug_data': self._debug_data
32-
}
29+
return {"type": "decision", "classname": self.__class__.__name__, "debug_data": self._debug_data}
3330

3431
def get_reevaluate(self):
3532
"""

dynamic_stack_decider/dynamic_stack_decider/abstract_stack_element.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
from abc import ABCMeta, abstractmethod
2-
from typing import Union
32

43
from dynamic_stack_decider.logger import get_logger
54

5+
66
class AbstractStackElement(metaclass=ABCMeta):
77
"""
88
The AbstractStackElement is the basis of all elements on the stack.
99
It provides some help functions which should not be overloaded.
1010
The work of an element is done in the :func:`perform`.
1111
Each element which inherits from the AbstractStackElement can be used as a root element on the stack.
1212
"""
13+
1314
_dsd = None
1415
_init_data = None
1516

@@ -68,10 +69,13 @@ def publish_debug_data(self, label, data):
6869
:param data: data that should be displayed for debugging purposes
6970
"""
7071
if type(data) not in (dict, list, int, float, str, bool):
71-
get_logger().debug("The supplied debug data of type {} is not JSON serializable and will be wrapped in str()".format(type(data)), throttle_duration_sec=1)
72+
get_logger().debug(
73+
f"The supplied debug data of type {type(data)} is not JSON serializable and will be wrapped in str()",
74+
throttle_duration_sec=1,
75+
)
7276
data = str(data)
7377

74-
get_logger().debug('{}: {}'.format(label, data))
78+
get_logger().debug(f"{label}: {data}")
7579
self._debug_data[label] = data
7680

7781
def clear_debug_data(self):
@@ -84,9 +88,5 @@ def clear_debug_data(self):
8488

8589
def repr_dict(self):
8690
# type: () -> dict
87-
""" Represent this stack element as dictionary which is JSON encodable """
88-
return {
89-
'type': 'abstract',
90-
'classname': self.__class__.__name__,
91-
'debug_data': self._debug_data
92-
}
91+
"""Represent this stack element as dictionary which is JSON encodable"""
92+
return {"type": "abstract", "classname": self.__class__.__name__, "debug_data": self._debug_data}

0 commit comments

Comments
 (0)