Skip to content

Commit

Permalink
Merge pull request #66 from ori-drs/improvement/black-formatting
Browse files Browse the repository at this point in the history
Apply black formatter and add github action to check conformity
  • Loading branch information
heuristicus authored Oct 28, 2022
2 parents 328d5a3 + 80eaa4b commit bb82c29
Show file tree
Hide file tree
Showing 8 changed files with 1,430 additions and 641 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Black formatting

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
with:
src: "spot_driver/src spot_driver/scripts"
36 changes: 18 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,29 @@
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.viewcode",
]

source_suffix = '.rst'
master_doc = 'index'
source_suffix = ".rst"
master_doc = "index"

project = u'Spot ROS User Documentation'
copyright = u'2020, Clearpath Robotics'
project = "Spot ROS User Documentation"
copyright = "2020, Clearpath Robotics"

# Get version number from package.xml.
tree = etree.parse('../spot_driver/package.xml')
tree = etree.parse("../spot_driver/package.xml")
version = tree.find("version").text
release = version

#.. html_theme = 'nature'
#.. html_theme_path = ["."]
# .. html_theme = 'nature'
# .. html_theme_path = ["."]
html_theme = "sphinx_rtd_theme"
html_theme_path = ["."]


html_sidebars = {
'**': ['sidebartoc.html', 'sourcelink.html', 'searchbox.html']
}
html_sidebars = {"**": ["sidebartoc.html", "sourcelink.html", "searchbox.html"]}

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
html_show_sphinx = False
Expand All @@ -48,15 +46,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -66,6 +61,11 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'SpotROSUserDocumentation.tex', 'Spot ROS User Documentation',
'Dave Niewinski', 'manual'),
(
master_doc,
"SpotROSUserDocumentation.tex",
"Spot ROS User Documentation",
"Dave Niewinski",
"manual",
),
]
27 changes: 11 additions & 16 deletions spot_driver/doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import os
import sys
sys.path.insert(0, os.path.abspath('../scripts'))

project = 'spot_driver'
copyright = '2020, Dave Niewinski'
author = 'Dave Niewinski'
sys.path.insert(0, os.path.abspath("../scripts"))

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.napoleon'
]
project = "spot_driver"
copyright = "2020, Dave Niewinski"
author = "Dave Niewinski"

html_theme = 'clearpath-sphinx-theme'
extensions = ["sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.napoleon"]

html_theme = "clearpath-sphinx-theme"
html_theme_path = ["."]

html_static_path = ['./clearpath-sphinx-theme/static']
html_static_path = ["./clearpath-sphinx-theme/static"]

html_sidebars = {
'**': ['sidebartoc.html', 'sourcelink.html', 'searchbox.html']
}
html_sidebars = {"**": ["sidebartoc.html", "sourcelink.html", "searchbox.html"]}

html_show_sphinx = False

html_logo = 'clearpath-sphinx-theme/static/clearpathlogo.png'
html_logo = "clearpath-sphinx-theme/static/clearpathlogo.png"

html_favicon = 'clearpath-sphinx-theme/static/favicon.ico'
html_favicon = "clearpath-sphinx-theme/static/favicon.ico"
6 changes: 2 additions & 4 deletions spot_driver/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from catkin_pkg.python_setup import generate_distutils_setup

d = generate_distutils_setup(
packages=['spot_driver'],
scripts=['scripts/spot_ros'],
package_dir={'': 'src'}
packages=["spot_driver"], scripts=["scripts/spot_ros"], package_dir={"": "src"}
)

setup(**d)
setup(**d)
55 changes: 37 additions & 18 deletions spot_driver/src/spot_driver/graph_nav_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@

def id_to_short_code(id):
"""Convert a unique id to a 2 letter short code."""
tokens = id.split('-')
tokens = id.split("-")
if len(tokens) > 2:
return '%c%c' % (tokens[0][0], tokens[1][0])
return "%c%c" % (tokens[0][0], tokens[1][0])
return None


def pretty_print_waypoints(waypoint_id, waypoint_name, short_code_to_count, localization_id, logger):
def pretty_print_waypoints(
waypoint_id, waypoint_name, short_code_to_count, localization_id, logger
):
short_code = id_to_short_code(waypoint_id)
if short_code is None or short_code_to_count[short_code] != 1:
short_code = ' ' # If the short code is not valid/unique, don't show it.
short_code = " " # If the short code is not valid/unique, don't show it.

logger.info("%s Waypoint name: %s id: %s short code: %s" %
('->' if localization_id == waypoint_id else ' ',
waypoint_name, waypoint_id, short_code))
logger.info(
"%s Waypoint name: %s id: %s short code: %s"
% (
"->" if localization_id == waypoint_id else " ",
waypoint_name,
waypoint_id,
short_code,
)
)


def find_unique_waypoint_id(short_code, graph, name_to_id, logger):
Expand All @@ -35,8 +43,10 @@ def find_unique_waypoint_id(short_code, graph, name_to_id, logger):
# Has an associated waypoint id!
return name_to_id[short_code]
else:
logger.error("The waypoint name %s is used for multiple different unique waypoints. Please use" + \
"the waypoint id." % (short_code))
logger.error(
"The waypoint name %s is used for multiple different unique waypoints. Please use"
+ "the waypoint id." % (short_code)
)
return None
# Also not an waypoint annotation name, so we will operate under the assumption that it is a
# unique waypoint id.
Expand All @@ -62,14 +72,17 @@ def update_waypoints_and_edges(graph, localization_id, logger):
# Determine the timestamp that this waypoint was created at.
timestamp = -1.0
try:
timestamp = waypoint.annotations.creation_time.seconds + waypoint.annotations.creation_time.nanos / 1e9
timestamp = (
waypoint.annotations.creation_time.seconds
+ waypoint.annotations.creation_time.nanos / 1e9
)
except:
# Must be operating on an older graph nav map, since the creation_time is not
# available within the waypoint annotations message.
pass
waypoint_to_timestamp.append((waypoint.id,
timestamp,
waypoint.annotations.name))
waypoint_to_timestamp.append(
(waypoint.id, timestamp, waypoint.annotations.name)
)

# Determine how many waypoints have the same short code.
short_code = id_to_short_code(waypoint.id)
Expand All @@ -91,21 +104,27 @@ def update_waypoints_and_edges(graph, localization_id, logger):

# Sort the set of waypoints by their creation timestamp. If the creation timestamp is unavailable,
# fallback to sorting by annotation name.
waypoint_to_timestamp = sorted(waypoint_to_timestamp, key= lambda x:(x[1], x[2]))
waypoint_to_timestamp = sorted(waypoint_to_timestamp, key=lambda x: (x[1], x[2]))

# Print out the waypoints name, id, and short code in a ordered sorted by the timestamp from
# when the waypoint was created.
logger.info('%d waypoints:' % len(graph.waypoints))
logger.info("%d waypoints:" % len(graph.waypoints))
for waypoint in waypoint_to_timestamp:
pretty_print_waypoints(waypoint[0], waypoint[2], short_code_to_count, localization_id, logger)
pretty_print_waypoints(
waypoint[0], waypoint[2], short_code_to_count, localization_id, logger
)

for edge in graph.edges:
if edge.id.to_waypoint in edges:
if edge.id.from_waypoint not in edges[edge.id.to_waypoint]:
edges[edge.id.to_waypoint].append(edge.id.from_waypoint)
else:
edges[edge.id.to_waypoint] = [edge.id.from_waypoint]
logger.info("(Edge) from waypoint id: ", edge.id.from_waypoint, " and to waypoint id: ",
edge.id.to_waypoint)
logger.info(
"(Edge) from waypoint id: ",
edge.id.from_waypoint,
" and to waypoint id: ",
edge.id.to_waypoint,
)

return name_to_id, edges
Loading

0 comments on commit bb82c29

Please sign in to comment.