diff --git a/ament_ruff/CHANGELOG.rst b/ament_ruff/CHANGELOG.rst new file mode 100644 index 000000000..3c0dd6747 --- /dev/null +++ b/ament_ruff/CHANGELOG.rst @@ -0,0 +1,3 @@ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Changelog for package ament_ruff +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \ No newline at end of file diff --git a/ament_ruff/ament_ruff/__init__.py b/ament_ruff/ament_ruff/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ament_ruff/ament_ruff/ament_ruff.toml b/ament_ruff/ament_ruff/ament_ruff.toml new file mode 100644 index 000000000..b6ae4823a --- /dev/null +++ b/ament_ruff/ament_ruff/ament_ruff.toml @@ -0,0 +1,5 @@ +[lint] +select =["ALL"] +ignore = ["D100","D101","D102","D103","D104","D105","D106","D107","D203","D212","D404", "COM812"] +[format] +quote-style = "double" diff --git a/ament_ruff/ament_ruff/configuration/ament_ruff.toml b/ament_ruff/ament_ruff/configuration/ament_ruff.toml new file mode 100644 index 000000000..837343b2e --- /dev/null +++ b/ament_ruff/ament_ruff/configuration/ament_ruff.toml @@ -0,0 +1,4 @@ +[lint] +select =["ALL"] +[format] +quote_style = "Double" diff --git a/ament_ruff/ament_ruff/main.py b/ament_ruff/ament_ruff/main.py new file mode 100755 index 000000000..eaa7cc352 --- /dev/null +++ b/ament_ruff/ament_ruff/main.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +# Copyright 2016 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +import subprocess + +def main(argv=sys.argv[1:]): + result = subprocess.run( + [ + "ruff", + "format", + "--config", + "/opt/overlay_ws/src/navigation2/ament_lint/ament_ruff/ament_ruff/ament_ruff.toml", + ], + capture_output=True, + text=True, + ) + lint_result = subprocess.run( + [ + "ruff", + "check", + "--config", + "/opt/overlay_ws/src/navigation2/ament_lint/ament_ruff/ament_ruff/ament_ruff.toml", + ], + capture_output=True, + text=True, + ) + sys.stdout.write(result.stdout) + sys.stdout.write(lint_result.stdout) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/ament_ruff/ament_ruff/pytest_marker.py b/ament_ruff/ament_ruff/pytest_marker.py new file mode 100644 index 000000000..7120c923d --- /dev/null +++ b/ament_ruff/ament_ruff/pytest_marker.py @@ -0,0 +1,19 @@ +# Copyright 2019 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +def pytest_configure(config): + config.addinivalue_line( + "markers", "ruff: marks tests checking for ruff compliance" + ) diff --git a/ament_ruff/doc/index.rst b/ament_ruff/doc/index.rst new file mode 100644 index 000000000..caabc395f --- /dev/null +++ b/ament_ruff/doc/index.rst @@ -0,0 +1,17 @@ +ament_ruff +============ + +Checks the code syntax and style of Python source files using `ruff +TODO: link to ruff`_. +Files with the following extensions are being considered: ``.py``. + + +How to run the check from the command line? +------------------------------------------- + +.. code:: sh + + ament_ruff [ ...] + + + diff --git a/ament_ruff/package.xml b/ament_ruff/package.xml new file mode 100644 index 000000000..12850dfe7 --- /dev/null +++ b/ament_ruff/package.xml @@ -0,0 +1,26 @@ + + + + ament_ruff + 0.19.1 + + The ability to check code for style and syntax conventions and autoformat with ruff. + + + + + Apache License 2.0 + + + + + + + + ament_lint + python3-ruff + + + ament_python + + diff --git a/ament_ruff/pytest.ini b/ament_ruff/pytest.ini new file mode 100644 index 000000000..fe55d2ed6 --- /dev/null +++ b/ament_ruff/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +junit_family=xunit2 diff --git a/ament_ruff/resource/ament_ruff b/ament_ruff/resource/ament_ruff new file mode 100644 index 000000000..e69de29bb diff --git a/ament_ruff/setup.py b/ament_ruff/setup.py new file mode 100644 index 000000000..ca3632cd2 --- /dev/null +++ b/ament_ruff/setup.py @@ -0,0 +1,47 @@ +from setuptools import find_packages +from setuptools import setup + +package_name = "ament_ruff" + +setup( + name=package_name, + version="0.19.1", + packages=find_packages(exclude=["test"]), + data_files=[ + ("share/" + package_name, ["package.xml"]), + ("share/ament_index/resource_index/packages", ["resource/" + package_name]), + ], + install_requires=["setuptools"], + package_data={ + "": [ + "configuration/ament_ruff.toml", + ] + }, + zip_safe=False, + author="Nils-Christian Iseke", + author_email="nils.iseke@gmail.org", + maintainer="", + maintainer_email="", + url="https://github.com/ament/ament_lint", + download_url="https://github.com/ament/ament_lint/releases", + keywords=["ROS"], + classifiers=[ + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Topic :: Software Development", + ], + description="Check Python code style using ruff.", + long_description="""\ +The ability to check code for syntax and style conventions with ruff.""", + license="Apache License, Version 2.0", + tests_require=["pytest"], + entry_points={ + "console_scripts": [ + "ament_ruff = ament_ruff.main:main", + ], + "pytest11": [ + "ament_ruff = ament_ruff.pytest_marker", + ], + }, +) diff --git a/ament_ruff/test/test_ruff.py b/ament_ruff/test/test_ruff.py new file mode 100644 index 000000000..f6fba8455 --- /dev/null +++ b/ament_ruff/test/test_ruff.py @@ -0,0 +1,27 @@ +# Copyright 2016 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) + +from ament_ruff.main import main # noqa + +#TODO: Adapt this test to ruff +def test_ruff(): + rc, errors = main(argv=[]) + assert rc == 0, "Found %d code style errors / warnings:\n" % len( + errors + ) + "\n".join(errors)