Skip to content

Support loading context from TOML files (including pyproject.toml) #1401

@harshith1118

Description

@harshith1118
 ## Description
 Currently, the Hamilton CLI only supports loading context files from `.json` and `.py` files. It
  would be beneficial to add support for TOML files, especially since many Python projects use
  `pyproject.toml` for project configuration.

 ## Motivation
 - Many Python projects already have `pyproject.toml` files
 - It would follow Python packaging conventions to keep Hamilton configuration in `
  [tool.hamilton]` section
 - Users could consolidate their project configuration in one place
 - TOML is a more readable format than JSON for configuration files

## Implementation Plan
I've already implemented this feature in a fork which:
- Adds support for `.toml` file extension in the CLI context loading
- Supports both formats:
  1. Top-level Hamilton headers: `HAMILTON_CONFIG`, `HAMILTON_FINAL_VARS`, etc.
  2. Tool-specific section: `[tool.hamilton]` with `config`, `final_vars`, etc. sub-sections
    Added comprehensive tests for both formats
    Updated CLI help text to reflect the new supported file type

## Files Modified
- `hamilton/cli/logic.py` - Enhanced `load_context` function
- `hamilton/cli/__main__.py` - Updated help text
- Added test files and test functions

## Testing
All existing tests continue to pass, and new tests cover the TOML functionality.

I'd like to submit a pull request for this feature if the maintainers approve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions