Skip to content

Commit 0aabeae

Browse files
committed
lint
1 parent a1b6e70 commit 0aabeae

5 files changed

Lines changed: 89 additions & 65 deletions

File tree

  • Python
    • app-distribution-feedback-to-jira/functions
    • call-vertex-remote-config-server/functions
    • instrument-with-opentelemetry/functions
    • remote-config-server-with-vertex/functions

Python/app-distribution-feedback-to-jira/functions/main.py

Lines changed: 79 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
}
3838
},
3939
)
40-
PROJECT_KEY = StringParam(
41-
"PROJECT_KEY", description="Project key of your Jira instance (e.g. 'XY')"
42-
)
40+
PROJECT_KEY = StringParam("PROJECT_KEY",
41+
description="Project key of your Jira instance (e.g. 'XY')")
4342
ISSUE_TYPE_ID = IntParam(
4443
"ISSUE_TYPE_ID",
4544
description="Issue type ID for the Jira issues being created",
@@ -55,8 +54,10 @@
5554
description="Owner of the Jira API token",
5655
input={
5756
"text": {
58-
"validation_regex": r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$",
59-
"validation_error_message": "Please enter a valid email address",
57+
"validation_regex":
58+
r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$",
59+
"validation_error_message":
60+
"Please enter a valid email address",
6061
}
6162
},
6263
)
@@ -94,8 +95,7 @@ def create_issue(event: InAppFeedbackEvent):
9495
)
9596
if not response.ok:
9697
raise Exception(
97-
f"Issue creation failed: {response.status_code} {response.reason} for {request_json}"
98-
)
98+
f"Issue creation failed: {response.status_code} {response.reason} for {request_json}")
9999
return response.json()["self"] # issueUri
100100

101101

@@ -104,8 +104,7 @@ def upload_screenshot(issue_uri: str, screenshot_uri: str):
104104
dl_response = requests.get(screenshot_uri)
105105
if not dl_response.ok:
106106
raise Exception(
107-
f"Screenshot download failed: {dl_response.status_code} {dl_response.reason}"
108-
)
107+
f"Screenshot download failed: {dl_response.status_code} {dl_response.reason}")
109108
blob = dl_response.content
110109
files = {"file": ("screenshot.png", blob, "image/png")}
111110
ul_response = requests.post(
@@ -118,16 +117,17 @@ def upload_screenshot(issue_uri: str, screenshot_uri: str):
118117
files=files,
119118
)
120119
if not ul_response.ok:
121-
raise Exception(
122-
f"Screenshot upload failed: {ul_response.status_code} {ul_response.reason}"
123-
)
120+
raise Exception(f"Screenshot upload failed: {ul_response.status_code} {ul_response.reason}")
124121

125122

126123
def lookup_reporter(tester_email: str):
127124
"""Looks up Jira user ID."""
128125
response = requests.get(
129126
f"{JIRA_URI.value()}/rest/api/3/user/search?query={tester_email}",
130-
headers={"Authorization": auth_header(), "Accept": "application/json"},
127+
headers={
128+
"Authorization": auth_header(),
129+
"Accept": "application/json"
130+
},
131131
)
132132
if not response.ok:
133133
print(
@@ -148,52 +148,79 @@ def build_create_issue_request(event: InAppFeedbackEvent):
148148
"update": {},
149149
"fields": {
150150
"summary": summary,
151-
"issuetype": {"id": str(ISSUE_TYPE_ID.value())},
152-
"project": {"key": PROJECT_KEY.value()},
151+
"issuetype": {
152+
"id": str(ISSUE_TYPE_ID.value())
153+
},
154+
"project": {
155+
"key": PROJECT_KEY.value()
156+
},
153157
"description": {
154-
"type": "doc",
155-
"version": 1,
158+
"type":
159+
"doc",
160+
"version":
161+
1,
156162
"content": [
157163
{
158-
"type": "paragraph",
164+
"type":
165+
"paragraph",
159166
"content": [
160167
{
161168
"text": "Firebase App ID: ",
162169
"type": "text",
163-
"marks": [{"type": "strong"}],
170+
"marks": [{
171+
"type": "strong"
172+
}],
173+
},
174+
{
175+
"text": event.app_id,
176+
"type": "text"
164177
},
165-
{"text": event.app_id, "type": "text"},
166178
],
167179
},
168180
{
169-
"type": "paragraph",
181+
"type":
182+
"paragraph",
170183
"content": [
171184
{
172185
"text": "App Version: ",
173186
"type": "text",
174-
"marks": [{"type": "strong"}],
187+
"marks": [{
188+
"type": "strong"
189+
}],
190+
},
191+
{
192+
"text": event.data.payload.app_version,
193+
"type": "text"
175194
},
176-
{"text": event.data.payload.app_version, "type": "text"},
177195
],
178196
},
179197
{
180-
"type": "paragraph",
198+
"type":
199+
"paragraph",
181200
"content": [
182201
{
183202
"text": "Tester Email: ",
184203
"type": "text",
185-
"marks": [{"type": "strong"}],
204+
"marks": [{
205+
"type": "strong"
206+
}],
207+
},
208+
{
209+
"text": event.data.payload.tester_email,
210+
"type": "text"
186211
},
187-
{"text": event.data.payload.tester_email, "type": "text"},
188212
],
189213
},
190214
{
191-
"type": "paragraph",
215+
"type":
216+
"paragraph",
192217
"content": [
193218
{
194219
"text": "Tester Name: ",
195220
"type": "text",
196-
"marks": [{"type": "strong"}],
221+
"marks": [{
222+
"type": "strong"
223+
}],
197224
},
198225
{
199226
"text": event.data.payload.tester_name or "None",
@@ -202,33 +229,38 @@ def build_create_issue_request(event: InAppFeedbackEvent):
202229
],
203230
},
204231
{
205-
"type": "paragraph",
232+
"type":
233+
"paragraph",
206234
"content": [
207235
{
208236
"text": "Feedback text: ",
209237
"type": "text",
210-
"marks": [{"type": "strong"}],
238+
"marks": [{
239+
"type": "strong"
240+
}],
241+
},
242+
{
243+
"text": event.data.payload.text,
244+
"type": "text"
211245
},
212-
{"text": event.data.payload.text, "type": "text"},
213246
],
214247
},
215248
{
216-
"type": "paragraph",
217-
"content": [
218-
{
219-
"text": "Console link",
220-
"type": "text",
221-
"marks": [
222-
{
223-
"type": "link",
224-
"attrs": {
225-
"href": event.data.payload.feedback_console_uri,
226-
"title": "Firebase console",
227-
},
228-
}
229-
],
230-
}
231-
],
249+
"type":
250+
"paragraph",
251+
"content": [{
252+
"text":
253+
"Console link",
254+
"type":
255+
"text",
256+
"marks": [{
257+
"type": "link",
258+
"attrs": {
259+
"href": event.data.payload.feedback_console_uri,
260+
"title": "Firebase console",
261+
},
262+
}],
263+
}],
232264
},
233265
],
234266
},

Python/call-vertex-remote-config-server/functions/main.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"top_k": 20,
4949
},
5050
"prompt": "I'm a developer who wants to learn about Firebase and you are a "
51-
"helpful assistant who knows everything there is to know about Firebase!",
51+
"helpful assistant who knows everything there is to know about Firebase!",
5252
"safety_settings": {
5353
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
5454
},
@@ -95,9 +95,8 @@ def call_vertex_with_rc(req: https_fn.CallableRequest):
9595
chat_input = text_prompt + " " + user_input
9696

9797
if not chat_input:
98-
raise https_fn.HttpsError(
99-
https_fn.FunctionsErrorCode.INVALID_ARGUMENT, "Missing text prompt"
100-
)
98+
raise https_fn.HttpsError(https_fn.FunctionsErrorCode.INVALID_ARGUMENT,
99+
"Missing text prompt")
101100

102101
# Check if Vertex AI is enabled
103102
if not vertex_enabled:
@@ -120,6 +119,4 @@ def call_vertex_with_rc(req: https_fn.CallableRequest):
120119
return "".join(chunks) # Return the concatenated chunks
121120
except Exception as error:
122121
print(error)
123-
raise https_fn.HttpsError(
124-
https_fn.FunctionsErrorCode.INTERNAL, "Internal server error"
125-
)
122+
raise https_fn.HttpsError(https_fn.FunctionsErrorCode.INTERNAL, "Internal server error")

Python/instrument-with-opentelemetry/functions/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828

2929
class Timer:
30+
3031
def __init__(self):
3132
self.start_time = time.time()
3233

@@ -37,17 +38,15 @@ def measure_ms(self):
3738
def slice_into_chunks(arr, chunk_size):
3839
res = []
3940
for i in range(0, len(arr), chunk_size):
40-
chunk = arr[i: i + chunk_size]
41+
chunk = arr[i:i + chunk_size]
4142
res.append(chunk)
4243
return res
4344

4445

4546
async def calculate_price(product_ids):
4647
timer = Timer()
4748
total_usd = 0
48-
products = await asyncio.gather(
49-
*[db.document(f"products/{id}").get() for id in product_ids]
50-
)
49+
products = await asyncio.gather(*[db.document(f"products/{id}").get() for id in product_ids])
5150
for product in products:
5251
total_usd += product.to_dict().get("usd", 0)
5352
print(f"calculatePrice: {timer.measure_ms()}ms")

Python/instrument-with-opentelemetry/functions/tracing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
if "FUNCTIONS_EMULATOR" not in os.environ:
2929
# Set up OpenTelemetry
3030
trace.set_tracer_provider(TracerProvider(resource=GcpResourceDetector().detect()))
31-
trace.get_tracer_provider().add_span_processor(
32-
BatchSpanProcessor(CloudTraceSpanExporter())
33-
)
31+
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(CloudTraceSpanExporter()))
3432
trace.set_text_map_propagator(GcpCloudPropagator())
3533

3634
# Instrument libraries

Python/remote-config-server-with-vertex/functions/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"top_k": 20,
4343
},
4444
"prompt": "I'm a developer who wants to learn about Firebase and you are a "
45-
"helpful assistant who knows everything there is to know about Firebase!",
45+
"helpful assistant who knows everything there is to know about Firebase!",
4646
"safety_settings": {
4747
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
4848
},
@@ -89,9 +89,7 @@ def generate_with_vertex(req: https_fn.Request) -> https_fn.Response:
8989

9090
# If vertexEnabled isn't true, do not send queries to Vertex AI.
9191
if not vertex_enabled:
92-
return https_fn.Response(
93-
"Vertex AI call skipped. Vertex is not enabled.", status=200
94-
)
92+
return https_fn.Response("Vertex AI call skipped. Vertex is not enabled.", status=200)
9593

9694
print(
9795
f"\nRunning with model {text_model}, prompt: {text_prompt}, "

0 commit comments

Comments
 (0)