17
17
logger = logging .getLogger (__name__ )
18
18
19
19
20
- def main ():
20
+ def main () -> None :
21
21
set_verbosity (enable_verbosity = False )
22
22
23
23
if "INPUT_SIZE-DELTAS-REPORTS-ARTIFACT-NAME" in os .environ :
@@ -32,7 +32,7 @@ def main():
32
32
report_size_deltas .report_size_deltas ()
33
33
34
34
35
- def set_verbosity (enable_verbosity ) :
35
+ def set_verbosity (enable_verbosity : bool ) -> None :
36
36
"""Turn debug output on or off.
37
37
38
38
Keyword arguments:
@@ -52,7 +52,7 @@ def set_verbosity(enable_verbosity):
52
52
53
53
54
54
class ReportSizeDeltas :
55
- """Methods for creating and submitting the memory usage change reports
55
+ """Methods for creating and submitting the memory usage change reports.
56
56
57
57
Keyword arguments:
58
58
repository_name -- repository owner and name e.g., octocat/Hello-World
@@ -63,7 +63,7 @@ class ReportSizeDeltas:
63
63
not_applicable_indicator = "N/A"
64
64
65
65
class ReportKeys :
66
- """Key names used in the sketches report dictionary"""
66
+ """Key names used in the sketches report dictionary. """
67
67
boards = "boards"
68
68
board = "board"
69
69
commit_hash = "commit_hash"
@@ -80,12 +80,12 @@ class ReportKeys:
80
80
sketches = "sketches"
81
81
compilation_success = "compilation_success"
82
82
83
- def __init__ (self , repository_name , sketches_reports_source , token ) :
83
+ def __init__ (self , repository_name : str , sketches_reports_source : str , token : str ) -> None :
84
84
self .repository_name = repository_name
85
85
self .sketches_reports_source = sketches_reports_source
86
86
self .token = token
87
87
88
- def report_size_deltas (self ):
88
+ def report_size_deltas (self ) -> None :
89
89
"""Comment a report of memory usage change to pull request(s)."""
90
90
if os .environ ["GITHUB_EVENT_NAME" ] == "pull_request" :
91
91
# The sketches reports will be in a local folder location specified by the user
@@ -95,7 +95,7 @@ def report_size_deltas(self):
95
95
# Scan the repository's pull requests and comment memory usage change reports where appropriate.
96
96
self .report_size_deltas_from_workflow_artifacts ()
97
97
98
- def report_size_deltas_from_local_reports (self ):
98
+ def report_size_deltas_from_local_reports (self ) -> None :
99
99
"""Comment a report of memory usage change to the pull request."""
100
100
sketches_reports_folder = pathlib .Path (os .environ ["GITHUB_WORKSPACE" ], self .sketches_reports_source )
101
101
sketches_reports = self .get_sketches_reports (artifact_folder_object = sketches_reports_folder )
@@ -108,7 +108,7 @@ def report_size_deltas_from_local_reports(self):
108
108
109
109
self .comment_report (pr_number = pr_number , report_markdown = report )
110
110
111
- def report_size_deltas_from_workflow_artifacts (self ):
111
+ def report_size_deltas_from_workflow_artifacts (self ) -> None :
112
112
"""Scan the repository's pull requests and comment memory usage change reports where appropriate."""
113
113
# Get the repository's pull requests
114
114
logger .debug ("Getting PRs for " + self .repository_name )
@@ -164,8 +164,8 @@ def report_size_deltas_from_workflow_artifacts(self):
164
164
page_number += 1
165
165
page_count = api_data ["page_count" ]
166
166
167
- def report_exists (self , pr_number , pr_head_sha ) :
168
- """Return whether a report has already been commented to the pull request thread for the latest workflow run
167
+ def report_exists (self , pr_number : int , pr_head_sha : str ) -> bool :
168
+ """Return whether a report has already been commented to the pull request thread for the latest workflow run.
169
169
170
170
Keyword arguments:
171
171
pr_number -- number of the pull request to check
@@ -191,8 +191,8 @@ def report_exists(self, pr_number, pr_head_sha):
191
191
# No reports found for the PR's head SHA
192
192
return False
193
193
194
- def get_artifact_download_url_for_sha (self , pr_user_login , pr_head_ref , pr_head_sha ) :
195
- """Return the report artifact download URL associated with the given head commit hash
194
+ def get_artifact_download_url_for_sha (self , pr_user_login : str , pr_head_ref : str , pr_head_sha : str ) -> str | None :
195
+ """Return the report artifact download URL associated with the given head commit hash.
196
196
197
197
Keyword arguments:
198
198
pr_user_login -- user name of the PR author (used to reduce number of GitHub API requests)
@@ -223,8 +223,8 @@ def get_artifact_download_url_for_sha(self, pr_user_login, pr_head_ref, pr_head_
223
223
# No matching artifact found
224
224
return None
225
225
226
- def get_artifact_download_url_for_run (self , run_id ) :
227
- """Return the report artifact download URL associated with the given GitHub Actions workflow run
226
+ def get_artifact_download_url_for_run (self , run_id : str ) -> str | None :
227
+ """Return the report artifact download URL associated with the given GitHub Actions workflow run.
228
228
229
229
Keyword arguments:
230
230
run_id -- GitHub Actions workflow run ID
@@ -249,8 +249,8 @@ def get_artifact_download_url_for_run(self, run_id):
249
249
# No matching artifact found
250
250
return None
251
251
252
- def get_artifact (self , artifact_download_url ):
253
- """Download and unzip the artifact and return an object for the temporary directory containing it
252
+ def get_artifact (self , artifact_download_url : str ):
253
+ """Download and unzip the artifact and return an object for the temporary directory containing it.
254
254
255
255
Keyword arguments:
256
256
artifact_download_url -- URL to download the artifact from GitHub
@@ -313,7 +313,7 @@ def get_sketches_reports(self, artifact_folder_object):
313
313
314
314
return sketches_reports
315
315
316
- def generate_report (self , sketches_reports ):
316
+ def generate_report (self , sketches_reports ) -> str :
317
317
"""Return the Markdown for the deltas report comment.
318
318
319
319
Keyword arguments:
@@ -370,7 +370,7 @@ def generate_report(self, sketches_reports):
370
370
logger .debug ("Report:\n " + report_markdown )
371
371
return report_markdown
372
372
373
- def add_summary_report_row (self , report_data , fqbn_data ):
373
+ def add_summary_report_row (self , report_data , fqbn_data ) -> None :
374
374
"""Add a row to the summary report.
375
375
376
376
Keyword arguments:
@@ -433,7 +433,7 @@ def add_summary_report_row(self, report_data, fqbn_data):
433
433
)
434
434
)
435
435
436
- def add_detailed_report_row (self , report_data , fqbn_data ):
436
+ def add_detailed_report_row (self , report_data , fqbn_data ) -> None :
437
437
"""Add a row to the detailed report.
438
438
439
439
Keyword arguments:
@@ -478,7 +478,7 @@ def add_detailed_report_row(self, report_data, fqbn_data):
478
478
# Relative
479
479
report_data [row_number ][column_number + 1 ] = self .not_applicable_indicator
480
480
481
- def get_summary_value (self , show_emoji , minimum , maximum ):
481
+ def get_summary_value (self , show_emoji : bool , minimum , maximum ) -> str :
482
482
"""Return the Markdown formatted text for a memory change data cell in the report table.
483
483
484
484
Keyword arguments:
@@ -517,8 +517,8 @@ def get_summary_value(self, show_emoji, minimum, maximum):
517
517
518
518
return value
519
519
520
- def comment_report (self , pr_number , report_markdown ) :
521
- """Submit the report as a comment on the PR thread
520
+ def comment_report (self , pr_number : int , report_markdown : str ) -> None :
521
+ """Submit the report as a comment on the PR thread.
522
522
523
523
Keyword arguments:
524
524
pr_number -- pull request number to submit the report to
@@ -536,7 +536,7 @@ def comment_report(self, pr_number, report_markdown):
536
536
537
537
self .http_request (url = url , data = report_data )
538
538
539
- def api_request (self , request , request_parameters = "" , page_number = 1 ):
539
+ def api_request (self , request : str , request_parameters : str = "" , page_number : int = 1 ):
540
540
"""Do a GitHub API request. Return a dictionary containing:
541
541
json_data -- JSON object containing the response
542
542
additional_pages -- indicates whether more pages of results remain (True, False)
@@ -552,7 +552,7 @@ def api_request(self, request, request_parameters="", page_number=1):
552
552
return self .get_json_response (url = "https://api.github.com/" + request + "?" + request_parameters + "&page="
553
553
+ str (page_number ) + "&per_page=100" )
554
554
555
- def get_json_response (self , url ):
555
+ def get_json_response (self , url : str ):
556
556
"""Load the specified URL and return a dictionary:
557
557
json_data -- JSON object containing the response
558
558
additional_pages -- indicates whether more pages of results remain (True, False)
@@ -587,7 +587,7 @@ def get_json_response(self, url):
587
587
except Exception as exception :
588
588
raise exception
589
589
590
- def http_request (self , url , data = None ):
590
+ def http_request (self , url : str , data : str | None = None ) -> dict [ str ] :
591
591
"""Make a request and return a dictionary:
592
592
read -- the response
593
593
info -- headers
@@ -603,7 +603,7 @@ def http_request(self, url, data=None):
603
603
"headers" : response_object .info (),
604
604
"url" : response_object .geturl ()}
605
605
606
- def raw_http_request (self , url , data = None ):
606
+ def raw_http_request (self , url : str , data : str | None = None ):
607
607
"""Make a request and return an object containing the response.
608
608
609
609
Keyword arguments:
@@ -635,7 +635,7 @@ def raw_http_request(self, url, data=None):
635
635
# Maximum retries reached without successfully opening URL
636
636
raise TimeoutError ("Maximum number of URL load retries exceeded" )
637
637
638
- def handle_rate_limiting (self ):
638
+ def handle_rate_limiting (self ) -> None :
639
639
"""Check whether the GitHub API request limit has been reached.
640
640
If so, exit with exit status 0.
641
641
"""
@@ -655,7 +655,7 @@ def handle_rate_limiting(self):
655
655
sys .exit (0 )
656
656
657
657
658
- def determine_urlopen_retry (exception ):
658
+ def determine_urlopen_retry (exception ) -> bool :
659
659
"""Determine whether the exception warrants another attempt at opening the URL.
660
660
If so, delay then return True. Otherwise, return False.
661
661
@@ -703,8 +703,8 @@ def determine_urlopen_retry(exception):
703
703
return False
704
704
705
705
706
- def get_page_count (link_header ) :
707
- """Return the number of pages of the API response
706
+ def get_page_count (link_header : str | None ) -> int :
707
+ """Return the number of pages of the API response.
708
708
709
709
Keyword arguments:
710
710
link_header -- Link header of the HTTP response
@@ -723,7 +723,7 @@ def get_page_count(link_header):
723
723
return page_count
724
724
725
725
726
- def get_report_column_number (report , column_heading ) :
726
+ def get_report_column_number (report , column_heading : str ) -> int :
727
727
"""Return the column number of the given heading.
728
728
729
729
Keyword arguments:
@@ -752,8 +752,8 @@ def get_report_column_number(report, column_heading):
752
752
return column_number
753
753
754
754
755
- def generate_markdown_table (row_list ):
756
- """Return the data formatted as a Markdown table
755
+ def generate_markdown_table (row_list ) -> str :
756
+ """Return the data formatted as a Markdown table.
757
757
758
758
Keyword arguments:
759
759
row_list -- list containing the data
@@ -769,7 +769,7 @@ def generate_markdown_table(row_list):
769
769
return markdown_table
770
770
771
771
772
- def generate_csv_table (row_list ):
772
+ def generate_csv_table (row_list ) -> str :
773
773
"""Return a string containing the supplied data formatted as CSV.
774
774
775
775
Keyword arguments:
0 commit comments