Skip to content

Commit b4e9991

Browse files
authored
field testing revealed various bugs (#30)
* upload new demo image * Revert "upload new demo image" This reverts commit 1aff6c7. * update readme & upload new demo pic * avoids duplicated checks on commits to open PR * fix workflow from last commit * Revert "fix workflow from last commit" This reverts commit 778e10d. * rename py pkg; allow no clang-tidy & no event.json * pleasing pylint * various bug fixes * pleasing pylint * update README about `tidy-checks=-*` * increase indent in last change * increase indent again (I don't like mkdocs) * update docs * avoid nesting log groups * switch pylint to my check-python-sources action * trigger pylint action * Revert "switch pylint to my check-python-sources action" This reverts commit 1733c4f.
1 parent 02781e8 commit b4e9991

24 files changed

+114
-135
lines changed

.ci-ignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
python_action
1+
cpp_linter
22
mkdocs.yml

.github/workflows/build-docs.bak

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/run-pylint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ jobs:
2525
python3 -m pip install -r requirements.txt
2626
- name: run pylint
2727
run: |
28-
pylint python_action/**
28+
pylint cpp_linter/**
2929
pylint setup.py

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ RUN apt-get update
1616
RUN apt-get -y install python3-pip
1717
# RUN python3 -m pip install --upgrade pip
1818

19-
COPY python_action/ pkg/python_action/
19+
COPY cpp_linter/ pkg/cpp_linter/
2020
COPY setup.py pkg/setup.py
2121
RUN python3 -m pip install pkg/
2222

2323
# github action args use the CMD option
2424
# See https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsargs
2525
# also https://docs.docker.com/engine/reference/builder/#cmd
26-
ENTRYPOINT [ "python3", "-m", "python_action.run" ]
26+
ENTRYPOINT [ "python3", "-m", "cpp_linter.run" ]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
#### `tidy-checks`
6666

6767
- **Description**: Comma-separated list of globs with optional '-' prefix. Globs are processed in order of appearance in the list. Globs without '-' prefix add checks with matching names to the set, globs with the '-' prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in a .clang-tidy file (if any).
68+
- It is possible to disable clang-tidy entirely by setting this option to '-\*'. This allows using only clang-format to lint your source files.
6869
- Default: 'boost-\*,bugprone-\*,performance-\*,readability-\*,portability-\*,modernize-\*,clang-analyzer-\*,cppcoreguidelines-\*'
6970

7071
#### `repo-root`
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""The Base module of the `python_action` package. This holds the objects shared by
1+
"""The Base module of the `cpp_linter` package. This holds the objects shared by
22
multiple modules."""
33
import io
44
import os
@@ -24,7 +24,7 @@
2424
logger.debug("rich module not found")
2525

2626
# global constant variables
27-
GITHUB_SHA = os.getenv("GITHUB_SHA", "95915a282b3efcad67b9ad3f95fba1501e43ab22")
27+
GITHUB_SHA = os.getenv("GITHUB_SHA", "")
2828
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", os.getenv("GIT_REST_API", ""))
2929
API_HEADERS = {
3030
"Authorization": f"token {GITHUB_TOKEN}",
@@ -54,13 +54,13 @@ class GlobalParser:
5454

5555
tidy_notes = []
5656
"""This can only be a `list` of type
57-
[`TidyNotification`][python_action.clang_tidy.TidyNotification]"""
57+
[`TidyNotification`][cpp_linter.clang_tidy.TidyNotification]"""
5858
tidy_advice = []
5959
"""This can only be a `list` of type
60-
[`YMLFixit`][python_action.clang_tidy_yml.YMLFixit]"""
60+
[`YMLFixit`][cpp_linter.clang_tidy_yml.YMLFixit]"""
6161
format_advice = []
6262
"""This can only be a `list` of type
63-
[`XMLFixit`][python_action.clang_format_xml.XMLFixit]"""
63+
[`XMLFixit`][cpp_linter.clang_format_xml.XMLFixit]"""
6464

6565

6666
def get_line_cnt_from_cols(file_path: str, offset: int) -> tuple:
@@ -80,24 +80,20 @@ def get_line_cnt_from_cols(file_path: str, offset: int) -> tuple:
8080
last_lf_pos = 0
8181
cols = 1
8282
file_path = file_path.replace("/", os.sep)
83-
with io.open(file_path, "r", encoding="utf-8", newline="\n") as src_file:
84-
src_file.seek(0, io.SEEK_END)
85-
max_len = src_file.tell()
83+
# logger.debug("Getting line count from %s at offset %d", file_path, offset)
84+
with io.open(file_path, "rb") as src_file:
85+
max_len = src_file.seek(0, io.SEEK_END)
8686
src_file.seek(0, io.SEEK_SET)
8787
while src_file.tell() != offset and src_file.tell() < max_len:
8888
char = src_file.read(1)
89-
if char == "\n":
89+
if char == b"\n":
9090
line_cnt += 1
9191
last_lf_pos = src_file.tell() - 1 # -1 because LF is part of offset
92-
if last_lf_pos + 1 > max_len:
93-
src_file.newlines = "\r\n"
94-
src_file.seek(0, io.SEEK_SET)
95-
line_cnt = 1
9692
cols = src_file.tell() - last_lf_pos
9793
return (line_cnt, cols)
9894

9995

10096
def log_response_msg():
101-
"""Output the response buffer's message on failed request"""
97+
"""Output the response buffer's message on a failed request."""
10298
if Globals.response_buffer.status_code >= 400:
10399
logger.error("response returned message: %s", Globals.response_buffer.text)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FormatReplacementLine:
3737
Attributes:
3838
line (int): The line number of where the suggestion starts
3939
replacements (list): A list of
40-
[`FormatReplacement`][python_action.clang_format_xml.FormatReplacement]
40+
[`FormatReplacement`][cpp_linter.clang_format_xml.FormatReplacement]
4141
object(s) representing suggestions.
4242
"""
4343

@@ -63,7 +63,7 @@ class XMLFixit:
6363
filename (str): The source file that the suggestion concerns.
6464
replaced_lines (list): A list of
6565
[`FormatReplacementLine`][
66-
python_action.clang_format_xml.FormatReplacementLine]
66+
cpp_linter.clang_format_xml.FormatReplacementLine]
6767
representing replacement(s) on a single line.
6868
"""
6969

@@ -118,7 +118,7 @@ def log_command(self, style: str) -> str:
118118

119119
def parse_format_replacements_xml(src_filename: str):
120120
"""Parse XML output of replacements from clang-format. Output is saved to
121-
[`format_advice`][python_action.__init__.GlobalParser.format_advice].
121+
[`format_advice`][cpp_linter.__init__.GlobalParser.format_advice].
122122
123123
Args:
124124
src_filename: The source file's name for which the contents of the xml
@@ -145,8 +145,8 @@ def parse_format_replacements_xml(src_filename: str):
145145

146146

147147
def print_fixits():
148-
"""Print all [`XMLFixit`][python_action.clang_format_xml.XMLFixit] objects in
149-
[`format_advice`][python_action.__init__.GlobalParser.format_advice]."""
148+
"""Print all [`XMLFixit`][cpp_linter.clang_format_xml.XMLFixit] objects in
149+
[`format_advice`][cpp_linter.__init__.GlobalParser.format_advice]."""
150150
for fixit in GlobalParser.format_advice:
151151
print(repr(fixit))
152152
for line_fix in fixit.replaced_lines:
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Parse output from clang-tidy's stdout"""
22
import os
3-
import sys
43
import re
5-
from . import GlobalParser
4+
from . import GlobalParser # , logger
65

6+
NOTE_HEADER = re.compile("^(.*):(\d+):(\d+):\s(\w+):(.*)\[(.*)\]$")
77

88
class TidyNotification:
99
"""Create a object that decodes info from the clang-tidy output's initial line that
@@ -20,27 +20,24 @@ class TidyNotification:
2020
notification.
2121
"""
2222

23-
def __init__(self, notification_line: str):
23+
def __init__(self, notification_line: tuple):
2424
"""
2525
Args:
26-
notification_line: The first line in the notification.
26+
notification_line: The first line in the notification parsed into a tuple of
27+
string that represent the different components of the notification's
28+
details.
2729
"""
28-
sliced_line = notification_line.split(":")
29-
if sys.platform.startswith("win32") and len(sliced_line) > 5:
30-
# sliced_list items 0 & 1 are the path seperated at the ":".
31-
# we need to re-assemble the path for correct list expansion (see below)
32-
sliced_line = [sliced_line[0] + ":" + sliced_line[1]] + sliced_line[2:]
30+
# logger.debug("Creating tidy note from line %s", notification_line)
3331
(
3432
self.filename,
3533
self.line,
3634
self.cols,
3735
self.note_type,
3836
self.note_info,
39-
) = sliced_line
37+
self.diagnostic,
38+
) = notification_line
4039

41-
self.diagnostic = re.search("\[.*\]", self.note_info).group(0)
42-
self.note_info = self.note_info.replace(self.diagnostic, "").strip()
43-
self.diagnostic = self.diagnostic[1:-1]
40+
self.note_info = self.note_info.strip()
4441
self.note_type = self.note_type.strip()
4542
self.line = int(self.line)
4643
self.cols = int(self.cols)
@@ -90,8 +87,9 @@ def parse_tidy_output() -> None:
9087
notification = None
9188
with open("clang_tidy_report.txt", "r", encoding="utf-8") as tidy_out:
9289
for line in tidy_out.readlines():
93-
if re.search("^.*:\d+:\d+:\s\w+:.*\[.*\]$", line) is not None:
94-
notification = TidyNotification(line)
90+
match = re.match(NOTE_HEADER, line)
91+
if match is not None:
92+
notification = TidyNotification(match.groups())
9593
GlobalParser.tidy_notes.append(notification)
9694
elif notification is not None:
9795
notification.fixit_lines.append(line)
@@ -100,7 +98,7 @@ def parse_tidy_output() -> None:
10098
def print_fixits():
10199
"""Print out all clang-tidy notifications from stdout (which are saved to
102100
clang_tidy_report.txt and allocated to
103-
[`tidy_notes`][python_action.__init__.GlobalParser.tidy_notes]."""
101+
[`tidy_notes`][cpp_linter.__init__.GlobalParser.tidy_notes]."""
104102
for notification in GlobalParser.tidy_notes:
105103
print("found", len(GlobalParser.tidy_notes), "tidy_notes")
106104
print(repr(notification))
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TidyDiagnostic:
2020
cols (int): The columns of the `line` that triggered the diagnostic
2121
null_len (int): The number of bytes replaced by suggestions
2222
replacements (list): The `list` of
23-
[`TidyReplacement`][python_action.clang_tidy_yml.TidyReplacement] objects.
23+
[`TidyReplacement`][cpp_linter.clang_tidy_yml.TidyReplacement] objects.
2424
2525
"""
2626

@@ -79,7 +79,7 @@ class YMLFixit:
7979
Attributes:
8080
filename (str): The source file's name concerning the suggestion.
8181
diagnostics (list): The `list` of
82-
[`TidyDiagnostic`][python_action.clang_tidy_yml.TidyDiagnostic] objects.
82+
[`TidyDiagnostic`][cpp_linter.clang_tidy_yml.TidyDiagnostic] objects.
8383
"""
8484

8585
def __init__(self, filename: str) -> None:
@@ -99,7 +99,7 @@ def __repr__(self) -> str:
9999

100100
def parse_tidy_suggestions_yml():
101101
"""Read a YAML file from clang-tidy and create a list of suggestions from it.
102-
Output is saved to [`tidy_advice`][python_action.__init__.GlobalParser.tidy_advice].
102+
Output is saved to [`tidy_advice`][cpp_linter.__init__.GlobalParser.tidy_advice].
103103
"""
104104
yml = {}
105105
with open("clang_tidy_output.yml", "r", encoding="utf-8") as yml_file:
@@ -129,8 +129,8 @@ def parse_tidy_suggestions_yml():
129129

130130

131131
def print_fixits():
132-
"""Print all [`YMLFixit`][python_action.clang_tidy_yml.YMLFixit] objects in
133-
[`tidy_advice`][python_action.__init__.GlobalParser.tidy_advice]."""
132+
"""Print all [`YMLFixit`][cpp_linter.clang_tidy_yml.YMLFixit] objects in
133+
[`tidy_advice`][cpp_linter.__init__.GlobalParser.tidy_advice]."""
134134
for fix in GlobalParser.tidy_advice:
135135
for diag in fix.diagnostics:
136136
print(repr(diag))

0 commit comments

Comments
 (0)