@@ -71,7 +71,10 @@ def repr_query_job(query_job: Optional[bigquery.QueryJob]):
7171 if query_job is None :
7272 return "No job information available"
7373 if query_job .dry_run :
74- return f"Computation deferred. Computation will process { get_formatted_bytes (query_job .total_bytes_processed )} "
74+ return (
75+ f"Computation deferred. Computation will process "
76+ f"{ get_formatted_bytes (query_job .total_bytes_processed )} "
77+ )
7578 res = "Query Job Info"
7679 for key , value in query_job_prop_pairs .items ():
7780 job_val = getattr (query_job , value )
@@ -105,11 +108,15 @@ def repr_query_job_html(query_job: Optional[bigquery.QueryJob]):
105108 if query_job is None :
106109 return "No job information available"
107110 if query_job .dry_run :
108- return f"Computation deferred. Computation will process { get_formatted_bytes (query_job .total_bytes_processed )} "
111+ return (
112+ f"Computation deferred. Computation will process "
113+ f"{ get_formatted_bytes (query_job .total_bytes_processed )} "
114+ )
109115
110116 # We can reuse the plaintext repr for now or make a nicer table.
111- # For deferred mode consistency, let's just wrap the text in a pre block or similar,
112- # but the request implies we want a distinct HTML representation if possible.
117+ # For deferred mode consistency, let's just wrap the text in a pre
118+ # block or similar, but the request implies we want a distinct HTML
119+ # representation if possible.
113120 # However, existing repr_query_job returns a simple string.
114121 # Let's format it as a simple table or list.
115122
@@ -123,7 +130,10 @@ def repr_query_job_html(query_job: Optional[bigquery.QueryJob]):
123130 location = query_job .location ,
124131 job_id = query_job .job_id ,
125132 )
126- res += f'<li>Job: <a target="_blank" href="{ url } ">{ query_job .job_id } </a></li>'
133+ res += (
134+ f'<li>Job: <a target="_blank" href="{ url } ">'
135+ f"{ query_job .job_id } </a></li>"
136+ )
127137 elif key == "Slot Time" :
128138 res += f"<li>{ key } : { get_formatted_time (job_val )} </li>"
129139 elif key == "Bytes Processed" :
@@ -138,7 +148,7 @@ def repr_query_job_html(query_job: Optional[bigquery.QueryJob]):
138148
139149
140150def progress_callback (
141- envelope : bigframes . core . events . EventEnvelope ,
151+ envelope : Any ,
142152):
143153 """Displays a progress bar while the query is running"""
144154 global current_display_id
@@ -147,13 +157,19 @@ def progress_callback(
147157 import bigframes ._config
148158 import bigframes .core .events
149159 except ImportError :
150- # Since this gets called from __del__, skip if the import fails to avoid
160+ # Since this gets called from __del__, skip if the import fails
161+ # to avoid
151162 # ImportError: sys.meta_path is None, Python is likely shutting down.
152163 # This will allow cleanup to continue.
153164 return
154165
155- event = envelope .event
156- progress_bar = envelope .progress_bar
166+ if isinstance (envelope , bigframes .core .events .EventEnvelope ):
167+ event = envelope .event
168+ progress_bar = envelope .progress_bar
169+ else :
170+ event = envelope
171+ progress_bar = bigframes .core .events ._DEFAULT
172+
157173 if progress_bar == bigframes .core .events ._DEFAULT :
158174 progress_bar = bigframes ._config .options .display .progress_bar
159175
@@ -235,7 +251,8 @@ def wait_for_job(job: GenericJob, progress_bar: Optional[str] = None):
235251 job .result ()
236252 job .reload ()
237253 display .update_display (
238- display .HTML (get_base_job_loading_html (job )), display_id = display_id
254+ display .HTML (get_base_job_loading_html (job )),
255+ display_id = display_id ,
239256 )
240257 elif progress_bar == "terminal" :
241258 inital_loading_bar = get_base_job_loading_string (job )
@@ -289,7 +306,10 @@ def render_job_link_html(
289306 job_id = job_id ,
290307 )
291308 if job_url :
292- job_link = f' [<a target="_blank" href="{ job_url } ">Job { project_id } :{ location } .{ job_id } details</a>]'
309+ job_link = (
310+ f' [<a target="_blank" href="{ job_url } ">'
311+ f"Job { project_id } :{ location } .{ job_id } details</a>]"
312+ )
293313 else :
294314 job_link = ""
295315 return job_link
@@ -326,7 +346,10 @@ def get_job_url(
326346 """
327347 if project_id is None or location is None or job_id is None :
328348 return None
329- return f"""https://console.cloud.google.com/bigquery?project={ project_id } &j=bq:{ location } :{ job_id } &page=queryresults"""
349+ return (
350+ f"https://console.cloud.google.com/bigquery?project={ project_id } "
351+ f"&j=bq:{ location } :{ job_id } &page=queryresults"
352+ )
330353
331354
332355def render_bqquery_sent_event_html (
@@ -351,7 +374,10 @@ def render_bqquery_sent_event_html(
351374 job_id = event .job_id ,
352375 request_id = event .request_id ,
353376 )
354- query_text_details = f"<details><summary>SQL</summary><pre>{ html .escape (event .query )} </pre></details>"
377+ query_text_details = (
378+ f"<details><summary>SQL</summary><pre>"
379+ f"{ html .escape (event .query )} </pre></details>"
380+ )
355381
356382 return f"""
357383 Query started{ query_id } .{ job_link } { query_text_details }
@@ -400,7 +426,10 @@ def render_bqquery_retry_event_html(
400426 job_id = event .job_id ,
401427 request_id = event .request_id ,
402428 )
403- query_text_details = f"<details><summary>SQL</summary><pre>{ html .escape (event .query )} </pre></details>"
429+ query_text_details = (
430+ f"<details><summary>SQL</summary><pre>"
431+ f"{ html .escape (event .query )} </pre></details>"
432+ )
404433
405434 return f"""
406435 Retrying query{ query_id } .{ job_link } { query_text_details }
@@ -446,7 +475,10 @@ def render_bqquery_received_event_html(
446475 query_plan_details = ""
447476 if event .query_plan :
448477 plan_str = "\n " .join ([str (entry ) for entry in event .query_plan ])
449- query_plan_details = f"<details><summary>Query Plan</summary><pre>{ html .escape (plan_str )} </pre></details>"
478+ query_plan_details = (
479+ f"<details><summary>Query Plan</summary><pre>"
480+ f"{ html .escape (plan_str )} </pre></details>"
481+ )
450482
451483 return f"""
452484 Query{ query_id } is { event .state } .{ job_link } { query_plan_details }
@@ -509,7 +541,9 @@ def render_bqquery_finished_event_plaintext(
509541
510542 bytes_str = ""
511543 if event .total_bytes_processed is not None :
512- bytes_str = f" { humanize .naturalsize (event .total_bytes_processed )} processed."
544+ bytes_str = (
545+ f" { humanize .naturalsize (event .total_bytes_processed )} processed."
546+ )
513547
514548 slot_time_str = ""
515549 if event .slot_millis is not None :
@@ -575,7 +609,9 @@ def get_formatted_time(val):
575609 Duration string
576610 """
577611 try :
578- return humanize .naturaldelta (datetime .timedelta (milliseconds = float (val )))
612+ return humanize .naturaldelta (
613+ datetime .timedelta (milliseconds = float (val ))
614+ )
579615 except Exception :
580616 return val
581617
@@ -594,7 +630,10 @@ def get_formatted_bytes(val):
594630
595631
596632def get_bytes_processed_string (val : Any ):
597- """Try to get bytes processed string. Return empty if passed non int value"""
633+ """Try to get bytes processed string.
634+
635+ Return empty if passed non int value.
636+ """
598637 bytes_processed_string = ""
599638 if isinstance (val , int ):
600639 bytes_processed_string = f"""{ get_formatted_bytes (val )} processed. """
0 commit comments