Skip to content

Commit

Permalink
[Config] Use orderdict to preserve key order in env parsing (mlrun#7221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yacouby authored Feb 3, 2025
1 parent 8997620 commit 20cd19e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion mlrun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"VolumeMount",
]

import collections
from os import environ, path
from typing import Optional

Expand Down Expand Up @@ -238,7 +239,7 @@ def order_env_vars(env_vars: dict[str, str]) -> dict[str, str]:
"""
ordered_keys = mlconf.get_ordered_keys()

ordered_env_vars: dict[str, str] = {}
ordered_env_vars = collections.OrderedDict()

# First, add the ordered keys to the dictionary
for key in ordered_keys:
Expand Down
16 changes: 10 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import collections
import os
import pathlib
import subprocess
Expand Down Expand Up @@ -587,12 +588,15 @@ def test_set_environment_cred():
def test_env_from_file():
env_path = str(assets_path / "envfile")
env_dict = mlrun.set_env_from_file(env_path, return_dict=True)
assert env_dict == {
"ENV_ARG1": "123",
"ENV_ARG2": "abc",
"MLRUN_HTTPDB__HTTP__VERIFY": "false",
"MLRUN_KFP_TTL": "12345",
}

assert env_dict == collections.OrderedDict(
{
"MLRUN_HTTPDB__HTTP__VERIFY": "false",
"MLRUN_KFP_TTL": "12345",
"ENV_ARG1": "123",
"ENV_ARG2": "abc",
}
)
assert mlrun.mlconf.kfp_ttl == 12345
for key, value in env_dict.items():
assert os.environ[key] == value
Expand Down

0 comments on commit 20cd19e

Please sign in to comment.