Skip to content

Commit 621e2a2

Browse files
committed
test.
Signed-off-by: Tomoya Fujita <[email protected]>
1 parent b0a330a commit 621e2a2

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.github/workflows/rst_check.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Specific checks for rst files
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**/*.rst" # trigger only for .rst files
7+
8+
jobs:
9+
one_sentence_per_line:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.10"
20+
21+
- name: Get changed lines in .rst files
22+
run: |
23+
git fetch origin ${{ github.base_ref }} --depth=1
24+
git diff --unified=0 origin/${{ github.base_ref }} HEAD -- '*.rst' | grep '^[+-]' | grep -Ev '^(---|\+\+\+)' > /tmp/changed_lines.txt || true
25+
26+
- name: Run one-sentence-per-line checker on changed lines
27+
run: |
28+
python3 ./scripts/check_sentences.py /tmp/changed_lines.txt

scripts/sentence_line_checker.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import argparse
2+
import re
3+
import sys
4+
5+
def is_one_sentence_per_line(line) -> bool:
6+
"""
7+
Check if a line contains only one complete sentence.
8+
9+
:param line: The line of file to check.
10+
"""
11+
# this assumes a sentence ends with a period, question mark, or exclamation mark.
12+
sentence_endings = re.findall(r'[.!?]', line)
13+
# allow empty lines or lines with only one sentence
14+
return len(sentence_endings) <= 1
15+
16+
def check_changed_lines(filename) -> None:
17+
"""
18+
Check only changed lines for violations.
19+
20+
.. warning:: It checks only added / modified lines for the viaolation in the file,
21+
and ignores everything else including removed lines.
22+
23+
:param filename: The name of the file to check.
24+
"""
25+
with open(filename, 'r', encoding='utf-8') as file:
26+
lines = file.readlines()
27+
28+
violations = []
29+
for lineno, line in enumerate(lines, start=1):
30+
line = line.strip()
31+
# check only added lines, ignore everything else
32+
if line.startswith("+") and not is_one_sentence_per_line(line[1:]):
33+
violations.append((lineno, line[1:]))
34+
35+
if violations:
36+
print(f"\n⚠️ Found {len(violations)} violations:")
37+
for lineno, line in violations:
38+
print(f" ❌ Line {lineno}: {line}")
39+
# exit with non-zero status code to fail github actions
40+
sys.exit(1)
41+
else:
42+
print("✅ No violations found.")
43+
44+
if __name__ == "__main__":
45+
parser = argparse.ArgumentParser(
46+
description="Check if modified contents contain only one complete sentence per line.")
47+
parser.add_argument(
48+
'filename', type=str, help='The name of the file to check.')
49+
args = parser.parse_args()
50+
51+
check_changed_lines(args.filename)

source/Citations.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
Citations
44
=========
55

6+
This is a test.
7+
This is a test. This should fail.
8+
Is this a test?
9+
Is this a test? Shoud this fail?
10+
This is a test!
11+
This is a test! This should fail!
12+
613
If you use ROS 2 in your work please cite the 2022 Science Robotics paper `Robot Operating System 2: Design, architecture, and uses in the wild <https://www.science.org/doi/10.1126/scirobotics.abm6074>`_.
714

815
| S. Macenski, T. Foote, B. Gerkey, C. Lalancette, W. Woodall, "Robot Operating System 2: Design, architecture, and uses in the wild," Science Robotics vol. 7, May 2022.

0 commit comments

Comments
 (0)