Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ament_ruff/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package ament_ruff
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Empty file.
5 changes: 5 additions & 0 deletions ament_ruff/ament_ruff/ament_ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[lint]
select =["ALL"]
ignore = ["D100","D101","D102","D103","D104","D105","D106","D107","D203","D212","D404", "COM812"]
[format]
quote-style = "double"
4 changes: 4 additions & 0 deletions ament_ruff/ament_ruff/configuration/ament_ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[lint]
select =["ALL"]
[format]
quote_style = "Double"
47 changes: 47 additions & 0 deletions ament_ruff/ament_ruff/main.py
Original file line number Diff line number Diff line change
@@ -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())
19 changes: 19 additions & 0 deletions ament_ruff/ament_ruff/pytest_marker.py
Original file line number Diff line number Diff line change
@@ -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"
)
17 changes: 17 additions & 0 deletions ament_ruff/doc/index.rst
Original file line number Diff line number Diff line change
@@ -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 [<path> ...]



26 changes: 26 additions & 0 deletions ament_ruff/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>ament_ruff</name>
<version>0.19.1</version>
<description>
The ability to check code for style and syntax conventions and autoformat with ruff.
</description>

<maintainer email=""></maintainer>

<license>Apache License 2.0</license>

<author email=""></author>
<author email=""></author>
<author></author>
<author></author>
<author email=""></author>

<exec_depend>ament_lint</exec_depend>
<exec_depend>python3-ruff</exec_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
2 changes: 2 additions & 0 deletions ament_ruff/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
junit_family=xunit2
Empty file added ament_ruff/resource/ament_ruff
Empty file.
47 changes: 47 additions & 0 deletions ament_ruff/setup.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
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",
],
},
)
27 changes: 27 additions & 0 deletions ament_ruff/test/test_ruff.py
Original file line number Diff line number Diff line change
@@ -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)