Skip to content

Commit a6e1a63

Browse files
OVI3D0IanHoang
authored andcommitted
Lint checker for 1.x/2.x terms (#933)
Signed-off-by: Michael Oviedo <[email protected]>
1 parent 6d14f7d commit a6e1a63

File tree

6 files changed

+113
-54
lines changed

6 files changed

+113
-54
lines changed

.ci/scripts/check_deprecated_terms.py

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,113 @@
11
#!/usr/bin/env python3
2-
3-
import os
4-
import re
5-
import sys
6-
7-
DEPRECATED_TERMS = [
2+
# .ci/scripts/check_deprecated_terms.py
3+
4+
import os, re, sys, argparse
5+
6+
# ---- Term sets ----
7+
# Block these when you're on the *2.x* branch (i.e., forbid legacy 1.x names):
8+
TERMS_1X = [
89
"provision-configs",
10+
"provision-config-instances",
11+
"results-publishing",
912
"results-publisher",
1013
"load-worker-coordinator-hosts",
1114
"execute-test",
1215
]
13-
14-
SKIP_DIRS = [".git", "venv", "__pycache__", ".pytest_cache"]
16+
17+
# Block these when you're on the *1.x* branch (i.e., forbid 2.x names):
18+
TERMS_2X = [
19+
"cluster-configs",
20+
"reporting",
21+
"worker-hosts",
22+
"run-test",
23+
"test-run",
24+
]
25+
26+
SKIP_DIRS = {".git", "venv", "__pycache__", ".pytest_cache", ".ci", "tests"}
1527
VALID_EXTENSIONS = (".py", ".yml", ".yaml", ".md", ".sh", ".json", ".txt")
16-
17-
VARIANT_PATTERNS = []
18-
19-
def generate_variants(term):
28+
29+
SUPRESS_MARKERS = {
30+
"block-1x": "check-deprecated-terms-disable-1x",
31+
"block-2x": "check-deprecated-terms-disable-2x"
32+
}
33+
34+
def generate_variants(term: str) -> set[str]:
2035
base = term.replace("-", " ").replace("_", " ")
2136
words = base.split()
2237
variants = set()
23-
24-
# kebab-case, snake_case, PascalCase, camelCase
38+
# kebab, snake, Pascal, camel
2539
variants.add("-".join(words))
2640
variants.add("_".join(words))
27-
variants.add("".join([w.capitalize() for w in words])) # PascalCase
41+
variants.add("".join([w.capitalize() for w in words])) # PascalCase
2842
variants.add(words[0] + "".join([w.capitalize() for w in words[1:]])) # camelCase
29-
30-
# Word order flip for 2-word terms
31-
if len(words) == 2:
43+
44+
# Optional: flip order for 2-word terms, but avoid silly "-ip" flips creating noise
45+
if len(words) == 2 and not words[1].lower() == "ip":
3246
variants.add("-".join(words[::-1]))
3347
variants.add("_".join(words[::-1]))
3448
variants.add(words[1] + words[0].capitalize()) # camelCase reverse
35-
3649
return variants
37-
38-
for term in DEPRECATED_TERMS:
39-
for variant in generate_variants(term):
40-
VARIANT_PATTERNS.append(re.compile(re.escape(variant), re.IGNORECASE))
41-
42-
def should_check_file(filename):
43-
return filename.endswith(VALID_EXTENSIONS)
44-
45-
def main():
46-
error_found = False
47-
50+
51+
def build_patterns(terms: list[str]) -> list[re.Pattern]:
52+
pats = []
53+
for t in terms:
54+
for v in generate_variants(t):
55+
pats.append(re.compile(re.escape(v), re.IGNORECASE))
56+
return pats
57+
58+
def should_check_file(path: str) -> bool:
59+
return path.endswith(VALID_EXTENSIONS)
60+
61+
def walk_and_check(patterns: list[re.Pattern], mode: str) -> int:
62+
error_found = 0
63+
suppress_marker = SUPRESS_MARKERS.get(mode)
4864
for root, _, files in os.walk("."):
49-
if any(skip in root for skip in SKIP_DIRS):
65+
if any(skip in root.split(os.sep) for skip in SKIP_DIRS):
5066
continue
51-
5267
for f in files:
5368
full_path = os.path.join(root, f)
5469
if not should_check_file(full_path):
5570
continue
56-
5771
try:
58-
with open(full_path, "r", encoding="utf-8") as file:
59-
for i, line in enumerate(file, 1):
60-
for pattern in VARIANT_PATTERNS:
61-
if pattern.search(line):
62-
print(f"[Deprecated Term] {full_path}:{i}: {line.strip()}")
63-
error_found = True
72+
with open(full_path, "r", encoding="utf-8") as fh:
73+
previous_line = ""
74+
for i, line in enumerate(fh, 1):
75+
if suppress_marker in previous_line or suppress_marker in line:
76+
previous_line = line
77+
continue
78+
for patt in patterns:
79+
if patt.search(line):
80+
print(f"[Forbidden Term] {full_path}:{i}: {line.strip()}")
81+
error_found = 1
82+
break
6483
except Exception as e:
6584
print(f"[Warning] Skipped file {full_path}: {e}")
66-
67-
if error_found:
68-
print("\n❌ Deprecated terms found. Please remove or rename them.")
85+
return error_found
86+
87+
def main():
88+
p = argparse.ArgumentParser(description="Check forbidden term set by mode or env.")
89+
p.add_argument("--mode", choices=["block-1x", "block-2x"], default=os.getenv("OSB_TERM_MODE"))
90+
args = p.parse_args()
91+
92+
mode = args.mode
93+
if not mode:
94+
print("No mode provided (use --mode block-1x | block-2x or set OSB_TERM_MODE). Exiting 0.")
95+
sys.exit(0)
96+
97+
if mode == "block-1x":
98+
terms = TERMS_1X
99+
banner = "❌ 1.x terms found in 2.x branch. Replace with 2.x names."
100+
else:
101+
terms = TERMS_2X
102+
banner = "❌ 2.x terms found in 1.x branch. Replace with 1.x names."
103+
104+
patterns = build_patterns(terms)
105+
failed = walk_and_check(patterns, mode)
106+
if failed:
107+
print("\n" + banner)
69108
sys.exit(1)
70-
71-
print("✅ No deprecated terms found.")
109+
print("✅ No forbidden terms found for", mode)
72110
sys.exit(0)
73-
111+
74112
if __name__ == "__main__":
75113
main()

.github/workflows/unit-test.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ jobs:
2525
- name: Run the CI build script
2626
run: bash .ci/build.sh build_and_unit_test
2727

28-
- name: Run deprecated term lint checker
29-
run: .ci/scripts/check_deprecated_terms.py
30-
if: contains(github.event.pull_request.labels.*.name, '2.x-terms-only')
28+
- name: Detect term-check mode from labels
29+
id: detect_mode
30+
shell: bash
31+
run: |
32+
labels='${{ toJson(github.event.pull_request.labels.*.name) }}'
33+
echo "PR labels: $labels"
34+
mode=""
35+
36+
if echo "$labels" | grep -qi '"check-1.x-terms"'; then
37+
mode="block-1x"
38+
elif echo "$labels" | grep -qi '"check-2.x-terms"'; then
39+
mode="block-2x"
40+
fi
41+
42+
echo "mode=$mode" >> "$GITHUB_OUTPUT"
43+
44+
# 2) Run the checker only if a mode was selected
45+
- name: Run term lint checker
46+
if: steps.detect_mode.outputs.mode != ''
47+
env:
48+
OSB_TERM_MODE: ${{ steps.detect_mode.outputs.mode }}
49+
run: |
50+
python3 .ci/scripts/check_deprecated_terms.py --mode "$OSB_TERM_MODE"

RELEASE_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Add backport labels to PRs and commits so that changes can be added to `main` br
7373
3. Run `opensearch-benchmark --version` to ensure that it is the correct version
7474
4. Run `opensearch-benchmark --help`
7575
5. Run `opensearch-benchmark list workloads`
76-
6. Run a basic workload on Linux and MacOS: `opensearch-benchmark execute-test --workload pmc --test-mode`
76+
6. Run a basic workload on Linux and MacOS: `opensearch-benchmark run --workload pmc --test-mode`
7777
7. If you are fastidious, you can check the installed source files at `` `python3 -m site --user-site`/osbenchmark `` to verify that a recent change is indeed present.
7878

7979
8. Verify Docker Hub Staging OSB Image Works:

osbenchmark/benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ def handle_command_suggestions():
12921292
Check for common command mistakes and provide helpful suggestions
12931293
Returns True if suggestion was provided, False otherwise
12941294
"""
1295+
# check-deprecated-terms-disable-1x
12951296
DEPRECATED_SUBCOMMANDS = ["execute-test", "execute"]
12961297
if len(sys.argv) > 1 and sys.argv[1] in DEPRECATED_SUBCOMMANDS:
12971298
console.info("Did you mean 'run'?")

osbenchmark/publisher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Throughput(Enum):
5252
MEDIAN = "median"
5353

5454
def summarize(results, cfg):
55-
SummaryResultsPublisher(results, cfg).publish()
55+
SummaryResultsPublisher(results, cfg).publish() # check-deprecated-terms-disable-1x
5656

5757

5858
def compare(cfg, baseline_id, contender_id):
@@ -115,7 +115,7 @@ def comma_separated_string_to_number_list(string_list):
115115
return results
116116

117117

118-
118+
# check-deprecated-terms-disable-1x
119119
class SummaryResultsPublisher:
120120
def __init__(self, results, config):
121121
self.results = results

osbenchmark/utils/console.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ def println(msg, console_prefix=None, end="\n", flush=False, force=False, logger
168168

169169

170170
def progress(width=90):
171-
return CmdLineProgressResultsPublisher(width, plain_output=PLAIN)
172-
171+
return CmdLineProgressResultsPublisher(width, plain_output=PLAIN) # check-deprecated-terms-disable-1x
173172

173+
# check-deprecated-terms-disable-1x
174174
class CmdLineProgressResultsPublisher:
175175
"""
176-
CmdLineProgressResultsPublisher supports displaying an updating progress indication together with an information message.
176+
This class supports displaying an updating progress indication together with an information message.
177177
178178
:param printer: allow use of a different print method to assist with patching in unittests
179179
"""

0 commit comments

Comments
 (0)