Skip to content

Commit 4b21151

Browse files
committed
refactor: remove ListParam & MultiSelectInput
1 parent d176e8c commit 4b21151

File tree

5 files changed

+31
-123
lines changed

5 files changed

+31
-123
lines changed

samples/basic_params/functions/main.py

-13
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@
2828
default="/images/processed",
2929
)
3030

31-
image_type = params.ListParam(
32-
"IMAGE_TYPE",
33-
label="convert image to preferred types",
34-
description="The image types you'd like your source image to convert to.",
35-
input=params.MultiSelectInput([
36-
params.SelectOption(value="jpeg", label="jpeg"),
37-
params.SelectOption(value="png", label="png"),
38-
params.SelectOption(value="webp", label="webp"),
39-
]),
40-
default=["jpeg", "png"],
41-
)
42-
4331
delete_original = params.BoolParam(
4432
"DELETE_ORIGINAL_FILE",
4533
label="delete the original file",
@@ -68,7 +56,6 @@ def resize_images(event: storage_fn.CloudEvent[storage_fn.StorageObjectData]):
6856
This function will be triggered when a new object is created in the bucket.
6957
"""
7058
print("Got a new image:", event)
71-
print("Selected image types:", image_type.value)
7259
print("Selected bucket resource:", bucket.value)
7360
print("Selected output location:", output_path.value)
7461
print("Testing a not so secret api key:", image_resize_api_secret.value)

src/firebase_functions/params.py

+1-41
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""Module for params that can make Cloud Functions codebases generic."""
1515

1616
import abc as _abc
17-
import json as _json
1817
import dataclasses as _dataclasses
1918
import os as _os
2019
import re as _re
@@ -140,18 +139,6 @@ class SelectInput(_typing.Generic[_T]):
140139
"""A list of user selectable options."""
141140

142141

143-
@_dataclasses.dataclass(frozen=True)
144-
class MultiSelectInput():
145-
"""
146-
Specifies that a Param's value should be determined by having the user select
147-
a subset from a list of pre-canned options interactively at deploy-time.
148-
Will result in errors if used on Params of type other than string[].
149-
"""
150-
151-
options: list[SelectOption[str]]
152-
"""A list of user selectable options."""
153-
154-
155142
@_dataclasses.dataclass(frozen=True)
156143
class TextInput:
157144
"""
@@ -228,8 +215,7 @@ class Param(Expression[_T]):
228215
deployments.
229216
"""
230217

231-
input: TextInput | ResourceInput | SelectInput[
232-
_T] | MultiSelectInput | None = None
218+
input: TextInput | ResourceInput | SelectInput[_T] | None = None
233219
"""
234220
The type of input that is required for this param, e.g. TextInput.
235221
"""
@@ -369,32 +355,6 @@ def value(self) -> bool:
369355
return False
370356

371357

372-
@_dataclasses.dataclass(frozen=True)
373-
class ListParam(Param[list]):
374-
"""A parameter as a list of strings."""
375-
376-
@property
377-
def value(self) -> list[str]:
378-
if _os.environ.get(self.name) is not None:
379-
# If the environment variable starts with "[" and ends with "]",
380-
# then assume it is a JSON array and try to parse it.
381-
# (This is for Cloud Run (v2 Functions), the environment variable is a JSON array.)
382-
if _os.environ[self.name].startswith("[") and _os.environ[
383-
self.name].endswith("]"):
384-
try:
385-
return _json.loads(_os.environ[self.name])
386-
except _json.JSONDecodeError:
387-
return []
388-
# Otherwise, split the string by commas.
389-
# (This is for emulator & the Firebase CLI generated .env file, the environment
390-
# variable is a comma-separated list.)
391-
return list(filter(len, _os.environ[self.name].split(",")))
392-
if self.default is not None:
393-
return self.default.value if isinstance(
394-
self.default, Expression) else self.default
395-
return []
396-
397-
398358
@_dataclasses.dataclass(frozen=True)
399359
class _DefaultStringParam(StringParam):
400360
"""

src/firebase_functions/private/manifest.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ class ManifestStack:
181181

182182

183183
def _param_input_to_spec(
184-
param_input: _params.TextInput | _params.ResourceInput |
185-
_params.SelectInput | _params.MultiSelectInput
184+
param_input: _params.TextInput | _params.ResourceInput | _params.SelectInput
186185
) -> dict[str, _typing.Any]:
187186
if isinstance(param_input, _params.TextInput):
188187
return {
@@ -205,11 +204,9 @@ def _param_input_to_spec(
205204
},
206205
}
207206

208-
if isinstance(param_input, (_params.MultiSelectInput, _params.SelectInput)):
209-
key = "select" if isinstance(param_input,
210-
_params.SelectInput) else "multiSelect"
207+
if isinstance(param_input, _params.SelectInput):
211208
return {
212-
key: {
209+
"select": {
213210
"options": [{
214211
key: value for key, value in {
215212
"value": option.value,
@@ -245,8 +242,6 @@ def _param_to_spec(
245242
spec_dict["type"] = "float"
246243
elif isinstance(param, _params.SecretParam):
247244
spec_dict["type"] = "secret"
248-
elif isinstance(param, _params.ListParam):
249-
spec_dict["type"] = "list"
250245
elif isinstance(param, _params.StringParam):
251246
spec_dict["type"] = "string"
252247
else:

tests/test_manifest.py

+27-25
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,43 @@
6868
_params.FloatParam("FLOAT_TEST", immutable=True),
6969
_params.SecretParam("SECRET_TEST"),
7070
_params.StringParam("STRING_TEST"),
71-
_params.ListParam("LIST_TEST", default=["1", "2", "3"]),
7271
],
7372
requiredAPIs=[{
7473
"api": "test_api",
7574
"reason": "testing"
76-
}])
75+
}],
76+
)
7777

7878
full_stack_dict = {
7979
"specVersion": "v1alpha1",
8080
"endpoints": {
8181
"test": full_endpoint_dict
8282
},
83-
"params": [{
84-
"name": "BOOL_TEST",
85-
"type": "boolean",
86-
"default": False,
87-
}, {
88-
"name": "INT_TEST",
89-
"type": "int",
90-
"description": "int_description"
91-
}, {
92-
"name": "FLOAT_TEST",
93-
"type": "float",
94-
"immutable": True,
95-
}, {
96-
"name": "SECRET_TEST",
97-
"type": "secret"
98-
}, {
99-
"name": "STRING_TEST",
100-
"type": "string"
101-
}, {
102-
"default": ["1", "2", "3"],
103-
"name": "LIST_TEST",
104-
"type": "list"
105-
}],
83+
"params": [
84+
{
85+
"name": "BOOL_TEST",
86+
"type": "boolean",
87+
"default": False,
88+
},
89+
{
90+
"name": "INT_TEST",
91+
"type": "int",
92+
"description": "int_description"
93+
},
94+
{
95+
"name": "FLOAT_TEST",
96+
"type": "float",
97+
"immutable": True,
98+
},
99+
{
100+
"name": "SECRET_TEST",
101+
"type": "secret"
102+
},
103+
{
104+
"name": "STRING_TEST",
105+
"type": "string"
106+
},
107+
],
106108
"requiredAPIs": [{
107109
"api": "test_api",
108110
"reason": "testing"

tests/test_params.py

-36
Original file line numberDiff line numberDiff line change
@@ -146,42 +146,6 @@ def test_string_param_equality(self):
146146
is False), "Failure, equality check returned False"
147147

148148

149-
class TestListParams:
150-
"""ListParam unit tests."""
151-
152-
def test_list_param_value(self):
153-
"""Testing if list param correctly returns list values."""
154-
environ["LIST_VALUE_TEST1"] = "item1,item2"
155-
assert params.ListParam("LIST_VALUE_TEST1").value == ["item1","item2"], \
156-
'Failure, params value != ["item1","item2"]'
157-
158-
def test_list_param_filter_empty_strings(self):
159-
"""Testing if list param correctly returns list values wth empty strings excluded."""
160-
environ["LIST_VALUE_TEST2"] = ",,item1,item2,,,item3,"
161-
assert params.ListParam("LIST_VALUE_TEST2").value == ["item1","item2", "item3"], \
162-
'Failure, params value != ["item1","item2", "item3"]'
163-
164-
def test_list_param_empty_default(self):
165-
"""Testing if list param defaults to an empty list if no value and no default."""
166-
assert params.ListParam("LIST_DEFAULT_TEST1").value == [], \
167-
"Failure, params value is not an empty list"
168-
169-
def test_list_param_default(self):
170-
"""Testing if list param defaults to the provided default value."""
171-
assert (params.ListParam("LIST_DEFAULT_TEST2", default=["1", "2"]).value
172-
== ["1", "2"]), \
173-
'Failure, params default value != ["1", "2"]'
174-
175-
def test_list_param_equality(self):
176-
"""Test list equality."""
177-
assert (params.ListParam("LIST_TEST1",
178-
default=["123"]).equals(["123"]).value
179-
is True), "Failure, equality check returned False"
180-
assert (params.ListParam("LIST_TEST2",
181-
default=["456"]).equals(["123"]).value
182-
is False), "Failure, equality check returned False"
183-
184-
185149
class TestParamsManifest:
186150
"""
187151
Tests any created params are tracked for the purposes

0 commit comments

Comments
 (0)