Skip to content

Commit c3b5b65

Browse files
authored
Merge pull request #31 from Copyleaks/AI-code-detection-sunset-v2
display warning message for relevant users
2 parents 2f2244c + 7dbc7d5 commit c3b5b65

File tree

6 files changed

+104
-21
lines changed

6 files changed

+104
-21
lines changed

copyleaks/__init__.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +0,0 @@
1-
import sys
2-
if sys.stderr.isatty():
3-
yellow = "\033[33m"
4-
red = "\033[31m"
5-
reset = "\033[0m"
6-
else:
7-
yellow = ""
8-
red = ""
9-
reset = ""
10-
notice = (
11-
f"{yellow}"
12-
"================================================================\n"
13-
f"{red} DEPRECATION NOTICE: copyleaks\n"
14-
f"{yellow}================================================================\n"
15-
"AI Code Detection will be discontinued on August 29, 2025.\n"
16-
"Please remove AI code detection integrations before the sunset date.\n"
17-
f"================================================================{reset}"
18-
)
19-
print(notice, file=sys.stderr)

copyleaks/clients/ai_detection_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from copyleaks.exceptions.command_error import CommandError
2929
from copyleaks.exceptions.under_maintenance_error import UnderMaintenanceError
3030
from copyleaks.helpers.copyleaks_client_helper import CopyleaksClientHelper
31-
31+
from copyleaks.deprecationService import deprecationService
3232
class _AIDetectionClient:
3333
@staticmethod
3434
def __submit(url, auth_token, scan_id, submission):
@@ -79,4 +79,5 @@ def submit_source_code(auth_token, scan_id, submission):
7979
`UnderMaintenanceError`: Copyleaks servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: https://api.copyleaks.com/documentation/v3/exponential-backoff
8080
'''
8181
url = f"{Consts.API_SERVER_URI}/v2/writer-detector/source-code/{scan_id}/check"
82+
deprecationService.show_deprecation_message()
8283
return _AIDetectionClient.__submit(url, auth_token, scan_id, submission)

copyleaks/copyleaks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
from copyleaks.clients.ai_detection_client import _AIDetectionClient
3737
from copyleaks.clients.writing_assistant_client import _WritingAssistantClient
3838
from copyleaks.clients.TextModerationClient import _TextModerationClient
39+
from copyleaks.models.constants.SupportedFilesTypes import SupportedFilesTypes
40+
from copyleaks.deprecationService import deprecationService
41+
import os
3942

4043
class Copyleaks(object):
4144

@@ -152,6 +155,14 @@ def submit_file(auth_token, scan_id, submission):
152155
`CommandError`: Server reject the request. See response status code, headers and content for more info.
153156
`UnderMaintenanceError`: Copyleaks servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: https://api.copyleaks.com/documentation/v3/exponential-backoff
154157
'''
158+
file_extension = os.path.splitext(submission.filename)[1].lstrip('.').lower()
159+
160+
if not file_extension:
161+
raise ValueError(f"File extension could not be determined for filename: {submission.filename}")
162+
163+
if file_extension in SupportedFilesTypes.SUPPORTED_CODE_EXTENSIONS:
164+
deprecationService.show_deprecation_message()
165+
155166
url = f"{Consts.API_SERVER_URI}/v3/scans/submit/file/{scan_id}"
156167
Copyleaks.__submit(url, auth_token, scan_id, submission)
157168

copyleaks/deprecationService.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'''
2+
The MIT License(MIT)
3+
4+
Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
'''
24+
import logging
25+
26+
class deprecationService:
27+
@staticmethod
28+
def show_deprecation_message():
29+
30+
logging.warning("DEPRECATION NOTICE: AI Code Detection will be discontinued on August 29, 2025. Please remove AI code detection integrations before the sunset date.")
31+
32+
33+
print("\033[31m", end="")
34+
print("════════════════════════════════════════════════════════════════════")
35+
print("DEPRECATION NOTICE !!!")
36+
print("AI Code Detection will be discontinued on August 29, 2025.")
37+
print("Please remove AI code detection integrations before the sunset date.")
38+
print("════════════════════════════════════════════════════════════════════")
39+
print("\033[0m", end="")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'''
2+
The MIT License(MIT)
3+
4+
Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
'''
24+
class SupportedFilesTypes:
25+
SUPPORTED_CODE_EXTENSIONS = [
26+
"ts",
27+
"py",
28+
"go",
29+
"cs",
30+
"c",
31+
"h",
32+
"idc",
33+
"cpp",
34+
"hpp",
35+
"c++",
36+
"h++",
37+
"cc",
38+
"hh",
39+
"java",
40+
"js",
41+
"swift",
42+
"rb",
43+
"pl",
44+
"php",
45+
"sh",
46+
"m",
47+
"scala",
48+
"rs",
49+
"vbs",
50+
"css"
51+
]

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def signal_handler(sig, frame):
176176
)
177177
source_code_submission = SourceCodeDocument(sample_text, "example.py")
178178
source_code_submission.set_sandbox(True)
179-
response = Copyleaks.AiDetectionClient.submit_natural_language(auth_token, scan_id, source_code_submission)
179+
response = Copyleaks.AiDetectionClient.submit_source_code(auth_token, scan_id, source_code_submission)
180180
print(response)
181181

182182
# This example is going to use the WritingAssistant client to get feedback on text

0 commit comments

Comments
 (0)