Skip to content

Commit 5918352

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

File tree

5 files changed

+115
-112
lines changed

5 files changed

+115
-112
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

+38-36
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,16 +139,17 @@ 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-
"""
142+
# List params are currently not supported.
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+
# """
150150

151-
options: list[SelectOption[str]]
152-
"""A list of user selectable options."""
151+
# options: list[SelectOption[str]]
152+
# """A list of user selectable options."""
153153

154154

155155
@_dataclasses.dataclass(frozen=True)
@@ -228,8 +228,9 @@ class Param(Expression[_T]):
228228
deployments.
229229
"""
230230

231-
input: TextInput | ResourceInput | SelectInput[
232-
_T] | MultiSelectInput | None = None
231+
# List params are currently not supported.
232+
# - add | MultiSelectInput when supported.
233+
input: TextInput | ResourceInput | SelectInput[_T] | None = None
233234
"""
234235
The type of input that is required for this param, e.g. TextInput.
235236
"""
@@ -369,30 +370,31 @@ def value(self) -> bool:
369370
return False
370371

371372

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

397399

398400
@_dataclasses.dataclass(frozen=True)

src/firebase_functions/private/manifest.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ class ManifestStack:
182182

183183
def _param_input_to_spec(
184184
param_input: _params.TextInput | _params.ResourceInput |
185-
_params.SelectInput | _params.MultiSelectInput
185+
# List params are currently not supported.
186+
# _params.SelectInput | _params.MultiSelectInput
187+
_params.SelectInput
186188
) -> dict[str, _typing.Any]:
187189
if isinstance(param_input, _params.TextInput):
188190
return {
@@ -204,8 +206,9 @@ def _param_input_to_spec(
204206
"type": param_input.type,
205207
},
206208
}
207-
208-
if isinstance(param_input, (_params.MultiSelectInput, _params.SelectInput)):
209+
# List params are currently not supported.
210+
# if isinstance(param_input, (_params.MultiSelectInput, _params.SelectInput)):
211+
if isinstance(param_input, _params.SelectInput):
209212
key = "select" if isinstance(param_input,
210213
_params.SelectInput) else "multiSelect"
211214
return {
@@ -245,8 +248,9 @@ def _param_to_spec(
245248
spec_dict["type"] = "float"
246249
elif isinstance(param, _params.SecretParam):
247250
spec_dict["type"] = "secret"
248-
elif isinstance(param, _params.ListParam):
249-
spec_dict["type"] = "list"
251+
# List params are currently not supported.
252+
# elif isinstance(param, _params.ListParam):
253+
# spec_dict["type"] = "list"
250254
elif isinstance(param, _params.StringParam):
251255
spec_dict["type"] = "string"
252256
else:

tests/test_manifest.py

+33-24
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
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"]),
71+
# List params are currently not supported.
72+
# _params.ListParam("LIST_TEST", default=["1", "2", "3"]),
7273
],
7374
requiredAPIs=[{
7475
"api": "test_api",
@@ -80,29 +81,37 @@
8081
"endpoints": {
8182
"test": full_endpoint_dict
8283
},
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-
}],
84+
"params": [
85+
{
86+
"name": "BOOL_TEST",
87+
"type": "boolean",
88+
"default": False,
89+
},
90+
{
91+
"name": "INT_TEST",
92+
"type": "int",
93+
"description": "int_description"
94+
},
95+
{
96+
"name": "FLOAT_TEST",
97+
"type": "float",
98+
"immutable": True,
99+
},
100+
{
101+
"name": "SECRET_TEST",
102+
"type": "secret"
103+
},
104+
{
105+
"name": "STRING_TEST",
106+
"type": "string"
107+
},
108+
# List params are currently not supported.
109+
# {
110+
# "default": ["1", "2", "3"],
111+
# "name": "LIST_TEST",
112+
# "type": "list"
113+
# }
114+
],
106115
"requiredAPIs": [{
107116
"api": "test_api",
108117
"reason": "testing"

tests/test_params.py

+35-34
Original file line numberDiff line numberDiff line change
@@ -146,40 +146,41 @@ 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"
149+
# List params are currently not supported.
150+
# class TestListParams:
151+
# """ListParam unit tests."""
152+
153+
# def test_list_param_value(self):
154+
# """Testing if list param correctly returns list values."""
155+
# environ["LIST_VALUE_TEST1"] = "item1,item2"
156+
# assert params.ListParam("LIST_VALUE_TEST1").value == ["item1","item2"], \
157+
# 'Failure, params value != ["item1","item2"]'
158+
159+
# def test_list_param_filter_empty_strings(self):
160+
# """Testing if list param correctly returns list values wth empty strings excluded."""
161+
# environ["LIST_VALUE_TEST2"] = ",,item1,item2,,,item3,"
162+
# assert params.ListParam("LIST_VALUE_TEST2").value == ["item1","item2", "item3"], \
163+
# 'Failure, params value != ["item1","item2", "item3"]'
164+
165+
# def test_list_param_empty_default(self):
166+
# """Testing if list param defaults to an empty list if no value and no default."""
167+
# assert params.ListParam("LIST_DEFAULT_TEST1").value == [], \
168+
# "Failure, params value is not an empty list"
169+
170+
# def test_list_param_default(self):
171+
# """Testing if list param defaults to the provided default value."""
172+
# assert (params.ListParam("LIST_DEFAULT_TEST2", default=["1", "2"]).value
173+
# == ["1", "2"]), \
174+
# 'Failure, params default value != ["1", "2"]'
175+
176+
# def test_list_param_equality(self):
177+
# """Test list equality."""
178+
# assert (params.ListParam("LIST_TEST1",
179+
# default=["123"]).equals(["123"]).value
180+
# is True), "Failure, equality check returned False"
181+
# assert (params.ListParam("LIST_TEST2",
182+
# default=["456"]).equals(["123"]).value
183+
# is False), "Failure, equality check returned False"
183184

184185

185186
class TestParamsManifest:

0 commit comments

Comments
 (0)