Skip to content

Commit f505727

Browse files
FredLL-AvaigaFred Lefévère-Laoide
andauthored
support boolean value in env file config (#2669)
* support boolean value in env file config resolves #2453 * check integer value * adding env file * linter new version ? * lint --------- Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
1 parent 9a5ec3d commit f505727

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

taipy/core/data/_file_datanode_mixin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import shutil
1515
from datetime import datetime
1616
from os.path import isfile
17-
from typing import Any, Callable, Dict, Optional
17+
from typing import Any, Callable, Dict, Optional, cast
1818

1919
from taipy.common.config import Config
2020
from taipy.common.logger._taipy_logger import _TaipyLogger
@@ -47,7 +47,7 @@ class _FileDataNodeMixin:
4747
__logger = _TaipyLogger._get_logger()
4848

4949
def __init__(self, properties: Dict) -> None:
50-
self._path: str = properties.get(self._PATH_KEY, properties.get(self._DEFAULT_PATH_KEY))
50+
self._path: str = cast(str, properties.get(self._PATH_KEY, properties.get(self._DEFAULT_PATH_KEY)))
5151
self._is_generated: bool = properties.get(self._IS_GENERATED_KEY, self._path is None)
5252
self._last_edit_date: Optional[datetime] = None
5353

@@ -248,5 +248,5 @@ def _duplicate_file(self, dest: DataNode):
248248
else:
249249
shutil.copy(self._path, new_path)
250250
normalize_path = _normalize_path(new_path)
251-
dest._path = normalize_path
251+
dest._path = normalize_path # type: ignore[attr-defined]
252252
dest._properties[self._PATH_KEY] = normalize_path

taipy/core/data/excel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# specific language governing permissions and limitations under the License.
1111

1212
from datetime import datetime, timedelta
13-
from typing import Any, Dict, List, Optional, Set, Union
13+
from typing import Any, Dict, List, Optional, Set, Union, cast
1414

1515
import numpy as np
1616
import pandas as pd
@@ -225,7 +225,7 @@ def _read_as(self, path: str):
225225
excel_file.close()
226226

227227
if len(user_provided_sheet_names) == 1:
228-
return work_books[user_provided_sheet_names[0]]
228+
return work_books[cast(list, user_provided_sheet_names)[0]]
229229

230230
return work_books
231231

taipy/gui/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from ._page import _Page
2727
from ._warnings import _warn
2828
from .partial import Partial
29-
from .utils import _is_in_notebook
29+
from .utils import _is_in_notebook, _is_true
3030

3131
ConfigParameter = t.Literal[
3232
"allow_unsafe_werkzeug",
@@ -266,9 +266,12 @@ def _build_config(self, root_dir, env_filename, kwargs): # pragma: no cover
266266
if value is not None and key in config:
267267
try:
268268
if key == "port" and str(value).strip() == "auto":
269-
config["port"] = "auto"
269+
config[key] = "auto"
270270
else:
271-
config[key] = value if config[key] is None else type(config[key])(value) # type: ignore[reportCallIssue]
271+
if isinstance(config[key], bool):
272+
config[key] = _is_true(value)
273+
else:
274+
config[key] = value if config[key] is None else type(config[key])(value) # type: ignore[reportCallIssue]
272275
except Exception as e:
273276
_warn(
274277
f"Invalid env value in Gui.run(): {key} - {value}. Unable to parse value to the correct type", # noqa: E501

taipy/gui/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, **kwargs) -> None:
7676
# Special variables only use for page reloading in notebook context
7777
self._notebook_gui: t.Optional["Gui"] = None
7878
self._notebook_page: t.Optional["_Page"] = None
79-
self.set_style(kwargs.get("style", None))
79+
self.set_style(t.cast(dict, kwargs.get("style", None)))
8080
self._script_paths(kwargs.get("script_paths", None))
8181

8282
def create_page(self) -> t.Union[Page, str, None]:

tests/gui/config/test_filename.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2021-2025 Avaiga Private Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
# the License. You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
# specific language governing permissions and limitations under the License.
11+
12+
import pathlib
13+
14+
from taipy.gui import Gui
15+
16+
17+
def test_env_filename():
18+
19+
gui = Gui(env_filename=str(pathlib.Path(__file__).parent.parent / "resources" / "taipy_env"))
20+
gui.run(run_server=False)
21+
service_config = gui._config.config
22+
assert service_config["run_browser"] is False # type: ignore
23+
assert service_config["port"] == 5555 # type: ignore
24+
gui.stop()
25+

tests/gui/resources/taipy_env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run_browser = False
2+
port=5555

0 commit comments

Comments
 (0)