Skip to content

Commit 5f167e1

Browse files
#3659 Fix copyright detection normalization
1 parent 0d2ce3f commit 5f167e1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/cluecode/copyrights.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@
2626

2727
from cluecode import copyrights_hint
2828

29+
from cluecode.normalizer import normalize_copyright_symbols
30+
31+
def detect_copyrights(file_path):
32+
# Read the content of the file
33+
with open(file_path, 'r', encoding='utf-8') as file:
34+
text = file.read()
35+
36+
# Normalize the text before processing it
37+
normalized_text = normalize_copyright_symbols(text)
38+
39+
# Save the normalized content back to the file (optional)
40+
with open(file_path, 'w', encoding='utf-8') as file:
41+
file.write(normalized_text)
42+
43+
return normalized_text
44+
45+
# Specify the path to your document directly here
46+
file_path = "./copyright.py"
47+
48+
# Call the function and print the result
49+
normalized_content = detect_copyrights(file_path)
50+
print(normalized_content)
51+
2952
# Tracing flags
3053
TRACE = False or os.environ.get('SCANCODE_DEBUG_COPYRIGHT', False)
3154

src/cluecode/copyrights_hint.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@
1414
# A regex to match a string that may contain a copyright year.
1515
# This is a year between 1960 and today prefixed and suffixed with
1616
# either a white-space or some punctuation.
17+
from cluecode.normalizer import normalize_copyright_symbols
18+
19+
def detect_copyrights(file_path):
20+
# Read the content of the file
21+
with open(file_path, 'r', encoding='utf-8') as file:
22+
text = file.read()
23+
24+
# Normalize the text before processing it
25+
normalized_text = normalize_copyright_symbols(text)
26+
27+
# Save the normalized content back to the file (optional)
28+
with open(file_path, 'w', encoding='utf-8') as file:
29+
file.write(normalized_text)
30+
31+
return normalized_text
32+
33+
# Specify the path to your document directly here
34+
file_path = "./copyright.py"
35+
36+
# Call the function and print the result
37+
normalized_content = detect_copyrights(file_path)
38+
print(normalized_content)
39+
1740

1841
all_years = tuple(str(year) for year in range(1960, datetime.today().year))
1942
years = r'[\(\.,\-\)\s]+(' + '|'.join(all_years) + r')([\(\.,\-\)\s]+|$)'

0 commit comments

Comments
 (0)