-
Notifications
You must be signed in to change notification settings - Fork 185
feat: Add support for loading context from TOML files including pyproject.toml #1402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
21fae43
3427092
fa132f5
25d0964
3c49db4
7c2c196
b1ab411
12b8ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import tomli | ||
| from pathlib import Path | ||
|
|
||
| toml_path = Path('tests/cli/resources/test_context.toml') | ||
| with open(toml_path, 'rb') as f: | ||
| data = tomli.load(f) | ||
| print('TOML data:', data) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Test TOML file for Hamilton CLI context loading | ||
|
|
||
| # Define Hamilton headers as top-level values | ||
| HAMILTON_CONFIG = {test_param = "test_value"} | ||
| HAMILTON_FINAL_VARS = ["final_var1", "final_var2"] | ||
| HAMILTON_INPUTS = {input_value = 42} | ||
| HAMILTON_OVERRIDES = {override_value = "override"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Test TOML file for Hamilton CLI context loading using [tool.hamilton] section | ||
|
|
||
| [tool.hamilton] | ||
| # Hamilton-specific configuration | ||
| config = {test_param = "test_value"} | ||
| final_vars = ["final_var1", "final_var2"] | ||
| inputs = {input_value = 42, string_input = "test_string"} | ||
| overrides = {override_value = "override"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,3 +93,44 @@ def test_diff_node_versions(): | |
| assert diff["reference_only"] == ["orders_per_customer"] | ||
| assert diff["current_only"] == ["orders_per_distributor"] | ||
| assert diff["edit"] == ["average_order_by_customer", "customer_summary_table"] | ||
|
|
||
|
|
||
| def test_load_context_from_toml(): | ||
| """Test loading context from a TOML file with top-level Hamilton headers.""" | ||
| import os | ||
| os.environ["HAMILTON_CONFIG"] = "HAMILTON_CONFIG" | ||
| os.environ["HAMILTON_FINAL_VARS"] = "HAMILTON_FINAL_VARS" | ||
| os.environ["HAMILTON_INPUTS"] = "HAMILTON_INPUTS" | ||
| os.environ["HAMILTON_OVERRIDES"] = "HAMILTON_OVERRIDES" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I see, to prove it was changed by the .toml file. I think this should be patched/mocked for the test, since this will impact the env for the life of the test process.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something like this: def test_load_context_from_toml(monkeypatch):
monkeypatch.setenv("HAMILTON_CONFIG", "HAMILTON_CONFIG")monkeypatch is part of pytest.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for pointing out the test isolation issue! You're absolutely right that directly |
||
|
|
||
| toml_path = Path(__file__).parent / "resources" / "test_context.toml" | ||
|
|
||
| # Load context from TOML file | ||
| context = logic.load_context(toml_path) | ||
|
|
||
| # Check that the expected values are loaded | ||
| assert context["HAMILTON_CONFIG"] == {"test_param": "test_value"} | ||
| assert context["HAMILTON_INPUTS"] == {"input_value": 42} | ||
| assert context["HAMILTON_OVERRIDES"] == {"override_value": "override"} | ||
| # The TOML file has an array of final variables | ||
| assert context["HAMILTON_FINAL_VARS"] == ["final_var1", "final_var2"] | ||
|
|
||
|
|
||
| def test_load_context_from_toml_tool_hamilton(): | ||
| """Test loading context from a TOML file with [tool.hamilton] section.""" | ||
| import os | ||
| os.environ["HAMILTON_CONFIG"] = "HAMILTON_CONFIG" | ||
| os.environ["HAMILTON_FINAL_VARS"] = "HAMILTON_FINAL_VARS" | ||
| os.environ["HAMILTON_INPUTS"] = "HAMILTON_INPUTS" | ||
| os.environ["HAMILTON_OVERRIDES"] = "HAMILTON_OVERRIDES" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
|
||
| toml_path = Path(__file__).parent / "resources" / "test_tool_hamilton.toml" | ||
|
|
||
| # Load context from TOML file with tool.hamilton section | ||
| context = logic.load_context(toml_path) | ||
|
|
||
| # Check that the expected values from [tool.hamilton] section are loaded | ||
| assert context["HAMILTON_CONFIG"] == {"test_param": "test_value"} | ||
| assert context["HAMILTON_INPUTS"] == {"input_value": 42, "string_input": "test_string"} | ||
| assert context["HAMILTON_OVERRIDES"] == {"override_value": "override"} | ||
| assert context["HAMILTON_FINAL_VARS"] == ["final_var1", "final_var2"] | ||
Uh oh!
There was an error while loading. Please reload this page.