Skip to content

Commit bf01be1

Browse files
Fix source code linker errors (#128)
* Increase version * Fixing parsing errors Source code linker errored when it parsed the test & documentaiton files. This removes those tags in order to stop those errors
1 parent d14e358 commit bf01be1

File tree

4 files changed

+61
-43
lines changed

4 files changed

+61
-43
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
module(
1515
name = "score_docs_as_code",
16-
version = "0.4.0",
16+
version = "0.4.1",
1717
compatibility_level = 0,
1818
)
1919

docs/product/extensions/source_code_linker.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,22 @@ The extension uses two main components to integrate with Bazel:
4040
**Note:** The base_url is defined in `parse_source_files.py`. Currently set to: `https://github.com/eclipse-score/score/blob/`
4141

4242
Produces JSON mapping file:
43-
```json
43+
The strings are split here to not enable tracking by the source code linker.
44+
```python
4445
[
4546
{
4647
"file": "src/implementation1.py",
4748
"line": 3,
48-
"tag":"# req-Id:",
49+
"tag":"#" + " req-Id:",
4950
"need": "TREQ_ID_1",
50-
"full_line": "# req-Id: TREQ_ID_1"
51+
"full_line": "#"+" req-Id: TREQ_ID_1"
5152
},
5253
{
5354
"file": "src/implementation2.py",
5455
"line": 3,
55-
"tag":"# req-Id:",
56+
"tag":"#" + " req-Id:",
5657
"need": "TREQ_ID_1",
57-
"full_line": "# req-Id: TREQ_ID_1"
58+
"full_line": "#"+" req-Id: TREQ_ID_1"
5859
},
5960
]
6061
```

src/extensions/score_source_code_linker/tests/test_requirement_links.py

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -201,30 +201,30 @@ def sample_needlinks():
201201
NeedLink(
202202
file=Path("src/implementation1.py"),
203203
line=3,
204-
tag="# req-Id:",
204+
tag="#" + " req-Id:",
205205
need="TREQ_ID_1",
206-
full_line="# req-Id: TREQ_ID_1",
206+
full_line="#" + " req-Id: TREQ_ID_1",
207207
),
208208
NeedLink(
209209
file=Path("src/implementation2.py"),
210210
line=3,
211-
tag="# req-Id:",
211+
tag="#" + " req-Id:",
212212
need="TREQ_ID_1",
213-
full_line="# req-Id: TREQ_ID_1",
213+
full_line="#" + " req-Id: TREQ_ID_1",
214214
),
215215
NeedLink(
216216
file=Path("src/implementation1.py"),
217217
line=9,
218-
tag="# req-Id:",
218+
tag="#" + " req-Id:",
219219
need="TREQ_ID_2",
220-
full_line="# req-Id: TREQ_ID_2",
220+
full_line="#" + " req-Id: TREQ_ID_2",
221221
),
222222
NeedLink(
223223
file=Path("src/bad_implementation.py"),
224224
line=2,
225-
tag="# req-Id:",
225+
tag="#" + " req-Id:",
226226
need="TREQ_ID_200",
227-
full_line="# req-Id: TREQ_ID_200",
227+
full_line="#" + " req-Id: TREQ_ID_200",
228228
),
229229
]
230230

@@ -452,9 +452,9 @@ def test_get_github_link_with_real_repo(git_repo):
452452
needlink = NeedLink(
453453
file=Path("src/test.py"),
454454
line=42,
455-
tag="# req-Id:",
455+
tag="#" + " req-Id:",
456456
need="REQ_001",
457-
full_line="# req-Id: REQ_001",
457+
full_line="#" + " req-Id: REQ_001",
458458
)
459459

460460
result = get_github_link(git_repo, needlink)
@@ -502,9 +502,9 @@ def test_cache_file_with_encoded_comments(temp_dir):
502502
NeedLink(
503503
file=Path("src/test.py"),
504504
line=1,
505-
tag="# req-Id:",
505+
tag="#" + " req-Id:",
506506
need="TEST_001",
507-
full_line="# req-Id: TEST_001",
507+
full_line="#" + " req-Id: TEST_001",
508508
)
509509
]
510510

@@ -514,14 +514,14 @@ def test_cache_file_with_encoded_comments(temp_dir):
514514
# Check the raw JSON to verify encoding
515515
with open(cache_file, "r") as f:
516516
raw_content = f.read()
517-
assert "# req-Id:" in raw_content # Should be encoded
517+
assert "#" + " req-Id:" in raw_content # Should be encoded
518518
assert "#-----req-Id:" not in raw_content # Original should not be present
519519

520520
# Load and verify decoding
521521
loaded_links = load_source_code_links_json(cache_file)
522522
assert len(loaded_links) == 1
523-
assert loaded_links[0].tag == "# req-Id:" # Should be decoded back
524-
assert loaded_links[0].full_line == "# req-Id: TEST_001"
523+
assert loaded_links[0].tag == "#" + " req-Id:" # Should be decoded back
524+
assert loaded_links[0].full_line == "#" + " req-Id: TEST_001"
525525

526526

527527
# Integration tests
@@ -559,24 +559,31 @@ def test_end_to_end_with_real_files(temp_dir, git_repo):
559559
src_dir = git_repo / "src"
560560
src_dir.mkdir()
561561

562-
(src_dir / "implementation1.py").write_text("""
562+
(src_dir / "implementation1.py").write_text(
563+
"""
563564
# Some implementation
564-
# req-Id: TREQ_ID_1
565+
#"""
566+
+ """ req-Id: TREQ_ID_1
565567
def function1():
566568
pass
567569
568570
# Another function
569-
# req-Id: TREQ_ID_2
571+
#"""
572+
+ """ req-Id: TREQ_ID_2
570573
def function2():
571574
pass
572-
""")
575+
"""
576+
)
573577

574-
(src_dir / "implementation2.py").write_text("""
578+
(src_dir / "implementation2.py").write_text(
579+
"""
575580
# Another implementation
576-
# req-Id: TREQ_ID_1
581+
#"""
582+
+ """ req-Id: TREQ_ID_1
577583
def another_function():
578584
pass
579-
""")
585+
"""
586+
)
580587

581588
# Commit the changes
582589
subprocess.run(["git", "add", "."], cwd=git_repo, check=True)
@@ -589,23 +596,23 @@ def another_function():
589596
NeedLink(
590597
file=Path("src/implementation1.py"),
591598
line=3,
592-
tag="# req-Id:",
599+
tag="#" + " req-Id:",
593600
need="TREQ_ID_1",
594-
full_line="# req-Id: TREQ_ID_1",
601+
full_line="#" + " req-Id: TREQ_ID_1",
595602
),
596603
NeedLink(
597604
file=Path("src/implementation1.py"),
598605
line=8,
599-
tag="# req-Id:",
606+
tag="#" + " req-Id:",
600607
need="TREQ_ID_2",
601-
full_line="# req-Id: TREQ_ID_2",
608+
full_line="#" + " req-Id: TREQ_ID_2",
602609
),
603610
NeedLink(
604611
file=Path("src/implementation2.py"),
605612
line=3,
606-
tag="# req-Id:",
613+
tag="#" + " req-Id:",
607614
need="TREQ_ID_1",
608-
full_line="# req-Id: TREQ_ID_1",
615+
full_line="#" + " req-Id: TREQ_ID_1",
609616
),
610617
]
611618

@@ -652,9 +659,9 @@ def test_multiple_commits_hash_consistency(git_repo):
652659
needlink = NeedLink(
653660
file=Path("new_file.py"),
654661
line=1,
655-
tag="# req-Id:",
662+
tag="#" + " req-Id:",
656663
need="TEST_001",
657-
full_line="# req-Id: TEST_001",
664+
full_line="#" + " req-Id: TREQ_ID_1",
658665
)
659666

660667
os.chdir(Path(git_repo).absolute())

src/extensions/score_source_code_linker/tests/test_source_link.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,38 +97,48 @@ def create_demo_files(sphinx_base_dir, git_repo_setup):
9797

9898

9999
def make_source_1():
100-
return """
100+
return (
101+
"""
101102
# This is a test implementation file
102-
# req-Id: TREQ_ID_1
103+
#"""
104+
+ """ req-Id: TREQ_ID_1
103105
def some_function():
104106
pass
105107
106108
# Some other code here
107109
# More code...
108-
# req-Id: TREQ_ID_2
110+
#"""
111+
""" req-Id: TREQ_ID_2
109112
def another_function():
110113
pass
111114
"""
115+
)
112116

113117

114118
def make_source_2():
115-
return """
119+
return (
120+
"""
116121
# Another implementation file
117-
# req-Id: TREQ_ID_1
122+
#"""
123+
+ """ req-Id: TREQ_ID_1
118124
class SomeClass:
119125
def method(self):
120126
pass
121127
122128
"""
129+
)
123130

124131

125132
def make_bad_source():
126-
return """
127-
# req-Id: TREQ_ID_200
133+
return (
134+
"""
135+
#"""
136+
+ """ req-Id: TREQ_ID_200
128137
def This_Should_Error(self):
129138
pass
130139
131140
"""
141+
)
132142

133143

134144
def construct_gh_url() -> str:

0 commit comments

Comments
 (0)