This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new cc44926 Fix environment variable parsing (#423)
cc44926 is described below
commit cc449266e7fe0e97f23e61b3c732b75a0d0a8dec
Author: Fokko Driesprong <[email protected]>
AuthorDate: Wed Feb 14 09:11:13 2024 +0100
Fix environment variable parsing (#423)
* Fix environment variable parsing
```bash
export PYICEBERG_CATALOG__SOMETHING__S3__REGION=eu-north-1
```
Before:
```python
>>> from pyiceberg.catalog import load_catalog
>>> load_catalog('something').properties
{'s3': {'region': 'eu-north-1'}, ...}
```
After:
```python
>>> from pyiceberg.catalog import load_catalog
>>> load_catalog('something').properties
{'s3.region': 'eu-north-1', ...}
```
Which correspondents with the key `s3.region` that we use.
* Add second test
Co-authored-by: Hussein Awala <[email protected]>
* lint
---------
Co-authored-by: Hussein Awala <[email protected]>
---
pyiceberg/utils/config.py | 4 ++--
tests/utils/test_config.py | 14 ++++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/pyiceberg/utils/config.py b/pyiceberg/utils/config.py
index 31ba0b3..e038005 100644
--- a/pyiceberg/utils/config.py
+++ b/pyiceberg/utils/config.py
@@ -125,8 +125,8 @@ class Config:
env_var_lower = env_var.lower()
if env_var_lower.startswith(PYICEBERG.lower()):
key = env_var_lower[len(PYICEBERG) :]
- parts = key.split("__")
- parts_normalized = [part.replace("_", "-") for part in parts]
+ parts = key.split("__", maxsplit=2)
+ parts_normalized = [part.replace('__', '.').replace("_", "-")
for part in parts]
set_property(config, parts_normalized, config_value)
return config
diff --git a/tests/utils/test_config.py b/tests/utils/test_config.py
index d694e15..5e3f72c 100644
--- a/tests/utils/test_config.py
+++ b/tests/utils/test_config.py
@@ -41,6 +41,20 @@ def test_from_environment_variables_uppercase() -> None:
assert Config().get_catalog_config("PRODUCTION") == {"uri":
"https://service.io/api"}
[email protected](
+ os.environ,
+ {
+ "PYICEBERG_CATALOG__PRODUCTION__S3__REGION": "eu-north-1",
+ "PYICEBERG_CATALOG__PRODUCTION__S3__ACCESS_KEY_ID": "username",
+ },
+)
+def test_fix_nested_objects_from_environment_variables() -> None:
+ assert Config().get_catalog_config("PRODUCTION") == {
+ 's3.region': 'eu-north-1',
+ 's3.access-key-id': 'username',
+ }
+
+
def test_from_configuration_files(tmp_path_factory: pytest.TempPathFactory) ->
None:
config_path = str(tmp_path_factory.mktemp("config"))
with open(f"{config_path}/.pyiceberg.yaml", "w", encoding=UTF8) as file: