Skip to content

Commit

Permalink
Pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
DLu committed Feb 26, 2024
1 parent cdbe316 commit 4ea6c7b
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 0 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ repos:
- '2'
- --offset
- '0'
exclude: ^.pre-commit-hooks.yaml
rev: 0.2.3
- repo: https://github.com/hhatto/autopep8
hooks:
Expand Down
174 changes: 174 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
- id: check_manifest_dependencies
name: Check Manifest Dependencies
entry: glint_hook check_manifest_dependencies -f
language: python
- id: enforce_manifest_ordering
name: Enforce Manifest Ordering
entry: glint_hook enforce_manifest_ordering -f
language: python
- id: remove_empty_export_tag
name: Remove Empty Export Tag
entry: glint_hook remove_empty_export_tag -f
language: python
- id: enforce_manifest_tabbing
name: Enforce Manifest Tabbing
entry: glint_hook enforce_manifest_tabbing -f
language: python
- id: remove_empty_manifest_lines
name: Remove Empty Manifest Lines
entry: glint_hook remove_empty_manifest_lines -f
language: python
- id: remove_boilerplate_manifest_comments
name: Remove Boilerplate Manifest Comments
entry: glint_hook remove_boilerplate_manifest_comments -f
language: python
- id: greedy_depend_tag
name: Greedy Depend Tag
entry: glint_hook greedy_depend_tag -f
language: python
- id: update_people
name: Update People
entry: glint_hook update_people -f
language: python
- id: update_license
name: Update License
entry: glint_hook update_license -f
language: python
- id: remove_empty_cmake_lines
name: Remove Empty CMake Lines
entry: glint_hook remove_empty_cmake_lines -f
language: python
- id: remove_boilerplate_cmake_comments
name: Remove Boilerplate CMake Comments
entry: glint_hook remove_boilerplate_cmake_comments -f
language: python
- id: check_cmake_dependencies
name: Check CMake Dependencies
entry: glint_hook check_cmake_dependencies -f
language: python
- id: check_generators
name: Check Generators
entry: glint_hook check_generators -f
language: python
- id: check_includes
name: Check Includes
entry: glint_hook check_includes -f
language: python
- id: target_catkin_libraries
name: Target Catkin Libraries
entry: glint_hook target_catkin_libraries -f
language: python
- id: check_library_setup
name: Check Library Setup
entry: glint_hook check_library_setup -f
language: python
- id: check_exported_dependencies
name: Check Exported Dependencies
entry: glint_hook check_exported_dependencies -f
language: python
- id: remove_old_style_cpp_dependencies
name: Remove Old Style C++ Dependencies
entry: glint_hook remove_old_style_cpp_dependencies -f
language: python
- id: update_cplusplus_installs
name: Update C++ Installs
entry: glint_hook update_cplusplus_installs -f
language: python
- id: export_cplusplus_libraries
name: Export C++ Libraries
entry: glint_hook export_cplusplus_libraries -f
language: python
- id: update_misc_installs
name: Update Miscellaneous Installs
entry: glint_hook update_misc_installs -f
language: python
- id: fix_double_directory_installs
name: Fix Double Directory Installs
entry: glint_hook fix_double_directory_installs -f
language: python
- id: check_python_marker
name: Check Python Marker
entry: glint_hook check_python_marker -f
language: python
- id: generate_ament_cmake_python_entry_points
name: Generate Ament CMake Python Entry Points
entry: glint_hook generate_ament_cmake_python_entry_points -f
language: python
- id: sync_package_xml_and_setup_py
name: Sync Package XML And Setup Py
entry: glint_hook sync_package_xml_and_setup_py -f
language: python
- id: check_setup_py
name: Check Setup Py
entry: glint_hook check_setup_py -f
language: python
- id: update_python_installs
name: Update Python Installs
entry: glint_hook update_python_installs -f
language: python
- id: clean_whitespace_from_interface_definition
name: Clean Whitespace From Interface Definition
entry: glint_hook clean_whitespace_from_interface_definition -f
language: python
- id: fill_in_msg_package_names
name: Fill In Msg Package Names
entry: glint_hook fill_in_msg_package_names -f
language: python
- id: check_plugins
name: Check Plugins
entry: glint_hook check_plugins -f
language: python
- id: enforce_cmake_ordering
name: Enforce CMake Ordering
entry: glint_hook enforce_cmake_ordering -f
language: python
- id: alphabetize_cmake_sections
name: Alphabetize CMake Sections
entry: glint_hook alphabetize_cmake_sections -f
language: python
- id: prettify_catkin_package_cmd
name: Prettify Catkin Package Cmd
entry: glint_hook prettify_catkin_package_cmd -f
language: python
- id: prettify_package_lists
name: Prettify Package Lists
entry: glint_hook prettify_package_lists -f
language: python
- id: prettify_msgs_srvs
name: Prettify Msgs Srvs
entry: glint_hook prettify_msgs_srvs -f
language: python
- id: prettify_installs
name: Prettify Installs
entry: glint_hook prettify_installs -f
language: python
- id: prettify_command_groups
name: Prettify Command Groups
entry: glint_hook prettify_command_groups -f
language: python
- id: clean_up_rviz_configs
name: Clean Up RViz Configs
entry: glint_hook clean_up_rviz_configs -f
language: python
- id: check_dynamic_reconfigure
name: Check Dynamic Reconfigure
entry: glint_hook check_dynamic_reconfigure -f
language: python
- id: remove_useless_files
name: Remove Useless Files
entry: glint_hook remove_useless_files -f
language: python
- id: misc_xml_formatting
name: Miscellaneous XML Formatting
entry: glint_hook misc_xml_formatting -f
language: python
- id: prettify_cmake
name: Prettify CMake
entry: glint_hook prettify_catkin_package_cmd prettify_package_lists prettify_msgs_srvs prettify_installs
prettify_command_groups -f
language: python
- id: remove_boilerplate
name: Remove Boilerplate
entry: glint_hook remove_empty_export_tag remove_boilerplate_manifest_comments remove_boilerplate_cmake_comments
-f
language: python
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ classifiers = [

[project.scripts]
glint_ros = "ros_glint.main:main"
glint_hook = "ros_glint.glint_hook:main"

[project.urls]
Homepage = "https://github.com/MetroRobots/ros_glint"
Expand Down
31 changes: 31 additions & 0 deletions src/ros_glint/glint_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import argparse
import pathlib
from . import get_linters
from ros_introspect import find_packages


def main():
parser = argparse.ArgumentParser()
parser.add_argument('linters', nargs='*', metavar='linter', default=[])
parser.add_argument('-f', '--related_files', type=pathlib.Path, nargs='*')

args = parser.parse_args()
pkgs = {}

for related_file in args.related_files:
for pkg in find_packages(related_file.parent):
if pkg.root not in pkgs:
pkgs[pkg.root] = pkg

ret = 0

for _, package in sorted(pkgs.items()):
for name, fne in get_linters().items():
if args.linters and name not in args.linters:
continue
fne(package)
if package.has_changes():
package.save()
ret = -1

return ret

0 comments on commit 4ea6c7b

Please sign in to comment.