Skip to content
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

cli added config support and validate command #729

Merged
merged 11 commits into from
Mar 7, 2024
Merged

Conversation

zilto
Copy link
Collaborator

@zilto zilto commented Mar 1, 2024

Now, all available commands accept --config which receives a Path. The path can be a .json, .py, or .ini file and the content is returned as a dictionary.

Changes

  • added logic to handle config path
  • modified logic that iterates over nodes to handle node.originating_functions is None for config nodes
  • updated commands.py to load config before building the driver
  • updated commands from __main__.py for the CLI to handle a new option

How I tested this

  • added config of each supported format to the examples/cli folder and manually tried them.

Notes

❗ I will add a hamilton validate command then update docs at once

  • we might want to add support for JSON config from the command line, but Typer doesn't support Union of types for arguments. Would need to add an additional --config-json -cjson to each command and prevent conflicts with --config. Maybe things could be renamed to --config-path and --config when received as JSON string
  • we could accept argument overload to CLI commands such as hamilton build key1="true" key2=0 MODULES, but it would be messier to parse and maintain

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

Ellipsis 🚀 This PR description was created by Ellipsis for commit 427f523.

Summary:

This PR enhances the CLI by adding support for configuration files, handling a new case for config nodes, updating the driver building process, handling a new CLI option, improving error handling, adding a validate command, and providing a demonstration of the new configuration options.

Key points:

  • Added support for configuration files in the CLI
  • Handled a new case where node.originating_functions is None for config nodes
  • Updated commands.py to load the config before building the driver
  • Updated commands from __main__.py for the CLI to handle a new option
  • Improved error handling
  • Added a validate command to the CLI
  • Demonstrated the new configuration options in module_v1.py in the examples/cli directory

Generated with ❤️ by ellipsis.dev

@zilto zilto added the enhancement New feature or request label Mar 1, 2024
@zilto zilto closed this Mar 2, 2024
@zilto zilto reopened this Mar 2, 2024
@zilto zilto marked this pull request as draft March 2, 2024 01:12
zilto added 2 commits March 2, 2024 12:11
Bit of scope creep.

Changes:
- drop support .ini config because they don't have
a basic construct for lists, which is required for
final_vars in driver.validate_execution()
- rename config methods to context. It allows to
reduce the number of arguments to pass to the CLI
and containts Driver config + execution final_vars,
inputs, and overrides
- refactored the CLI to extract methods to try a
command and to display a result in terminal.
- added a validate command. While build checks for
a valid definition, validate checks that certain
dataflow paths aren't broken for a given context.
hamilton/cli/logic.py Outdated Show resolved Hide resolved
hamilton/cli/logic.py Outdated Show resolved Hide resolved
hamilton/cli/logic.py Show resolved Hide resolved
hamilton/cli/logic.py Show resolved Hide resolved
@zilto zilto marked this pull request as ready for review March 3, 2024 14:45
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Reviewed the entire pull request up to b3fd011
  • Looked at 679 lines of code in 5 files
  • Took 2 minutes and 5 seconds to review
More info
  • Skipped 1 files when reviewing.
  • Skipped posting 4 additional comments because they didn't meet confidence threshold of 50%.
1. hamilton/cli/logic.py:268:
  • Assessed confidence : 80%
  • Grade: 0%
  • Comment:
    Consider adding validation to ensure that the loaded configuration contains all the required fields and that they are in the correct format. This could help prevent unexpected errors and make the code more robust.
  • Reasoning:
    The load_context function in logic.py is responsible for loading the configuration from a file. It currently supports .json and .py files. However, there is no validation to ensure that the loaded configuration is in the correct format. This could lead to unexpected errors if the configuration file is malformed or missing required fields.
2. hamilton/cli/commands.py:82:
  • Assessed confidence : 80%
  • Grade: 0%
  • Comment:
    Consider adding error handling for the validate_execution method call. This could help provide more informative error messages and make the code more robust.
  • Reasoning:
    The validate function in commands.py is responsible for validating the execution of a dataflow. It uses the validate_execution method of the Driver class, passing in the final variables, inputs, and overrides from the context. However, there is no error handling in case the validate_execution method raises an exception. This could lead to unhandled exceptions if there are issues with the validation.
3. hamilton/cli/commands.py:30:
  • Assessed confidence : 80%
  • Grade: 0%
  • Comment:
    Consider adding error handling for the load_modules_from_git function call. This could help provide more informative error messages and make the code more robust.
  • Reasoning:
    The diff function in commands.py is responsible for generating a diff between the current modules and a specified git reference. It uses the load_modules_from_git function to load the modules from the git reference. However, there is no error handling in case the load_modules_from_git function raises an exception. This could lead to unhandled exceptions if there are issues with loading the modules.
4. hamilton/cli/commands.py:8:
  • Assessed confidence : 80%
  • Grade: 0%
  • Comment:
    Consider adding validation to ensure that the loaded modules are in the correct format. This could help prevent unexpected errors and make the code more robust.
  • Reasoning:
    The build function in commands.py is responsible for building a Hamilton driver from the passed modules and loading the Driver config from the context file. However, there is no validation to ensure that the loaded modules are in the correct format. This could lead to unexpected errors if the modules are malformed or missing required fields.

Workflow ID: wflow_N88WFOK8NSTL9YvQ


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

@zilto zilto changed the title cli load config from .ini, .json, .py cli added config support and validate command Mar 3, 2024
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested.

  • Performed an incremental review on 0405587
  • Looked at 13 lines of code in 1 files
  • Took 2 minutes and 32 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 0 additional comments because they didn't meet confidence threshold of 50%.

Workflow ID: wflow_BhUEU8zUd1zAXidY


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

hamilton/cli/logic.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 409e996
  • Looked at 13 lines of code in 1 files
  • Took 2 minutes and 28 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 0 additional comments because they didn't meet confidence threshold of 50%.

Workflow ID: wflow_ZILROIimfIFDt4nZ


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 4a07446
  • Looked at 58 lines of code in 1 files
  • Took 2 minutes and 30 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 50%.
1. /hamilton/cli/__main__.py:77:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The PR description mentions that the CLI now accepts a --config option, but I don't see this option being handled in this file. Please ensure that this option is properly implemented and handled.
  • Reasoning:
    The PR description mentions that the CLI now accepts a --config option, but I don't see this option being handled in the __main__.py file. This could be an oversight or the changes might be in another file. I'll need to check the other files in the PR to confirm.

Workflow ID: wflow_BDxtopp5sMKtpog8


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

@elijahbenizzy elijahbenizzy self-requested a review March 7, 2024 15:03
Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline imports are generally bad practice -- let's remove them?

Also, can we add config stuff to the README?

examples/cli/module_v1.py Outdated Show resolved Hide resolved
hamilton/cli/logic.py Show resolved Hide resolved
examples/cli/config.json Show resolved Hide resolved
@zilto
Copy link
Collaborator Author

zilto commented Mar 7, 2024

Also, can we add config stuff to the README?

I think the CLI is still super experimental. As I work with pre-commit and GitHub actions, new API needs appear and things change frequently.

We should strongly emphasize that user rely on hamilton --help (after all that's why we picked Typer).

Generally speaking, we should probably start adding dates to examples/ to communicate potential deprecation until we automate CI for them. (hopefully the CLI will help)

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested.

  • Performed an incremental review on 42e236d
  • Looked at 23 lines of code in 1 files
  • Took 4 minutes and 2 seconds to review
More info
  • Skipped 1 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 50%.
1. examples/cli/module_v1.py:15:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    Consider passing the file path as a parameter to the function instead of hardcoding it. This would make the function more flexible and prevent potential issues if the file is not found at the specified location.
  • Reasoning:
    The function customers_df__default is reading a CSV file from a hardcoded path. This could lead to issues if the file is not found at the specified location. It would be better to pass the file path as a parameter to the function.

Workflow ID: wflow_Do1w7MRGxUTaS3TS


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

examples/cli/module_v1.py Show resolved Hide resolved
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 692fb0d
  • Looked at 35 lines of code in 1 files
  • Took 2 minutes and 58 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 50%.
1. /examples/cli/README.md:13:
  • Assessed confidence : 0%
  • Comment:
    The changes in the README file are clear and well-documented. Good job!
  • Reasoning:
    The README file has been updated to reflect the new changes in the CLI. The changes are well-documented and clear. There are no issues with the changes in the README file.

Workflow ID: wflow_MH1S1Mkp9mFxpxyF


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@zilto zilto merged commit 427f523 into main Mar 7, 2024
23 checks passed
@zilto zilto deleted the cli/config-support branch March 7, 2024 16:10
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 427f523
  • Looked at 745 lines of code in 6 files
  • Took 9 minutes and 13 seconds to review
More info
  • Skipped 1 files when reviewing.
  • Skipped posting 5 additional comments because they didn't meet confidence threshold of 50%.
1. /hamilton/cli/logic.py:268:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The load_context function should handle the case where the file does not exist. Consider adding error handling for FileNotFoundError.
  • Reasoning:
    The load_context function in logic.py is loading the context from a file. However, it does not handle the case where the file does not exist. This could lead to a FileNotFoundError which is not being caught and handled. This could be improved by adding error handling for this case.
2. /hamilton/cli/logic.py:269:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The load_context function should handle the case where the file does not exist. Consider adding error handling for FileNotFoundError.
  • Reasoning:
    The load_context function in logic.py is loading the context from a file. However, it does not handle the case where the file does not exist. This could lead to a FileNotFoundError which is not being caught and handled. This could be improved by adding error handling for this case.
3. /hamilton/cli/logic.py:278:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The load_context function should handle the case where the file extension is not supported. Consider adding error handling for ValueError.
  • Reasoning:
    The load_context function in logic.py is loading the context from a file. However, it does not handle the case where the file extension is not supported. This could lead to a ValueError which is not being caught and handled. This could be improved by adding error handling for this case.
4. /hamilton/cli/logic.py:270:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The load_context function should handle the case where the file does not exist. Consider adding error handling for FileNotFoundError.
  • Reasoning:
    The load_context function in logic.py is loading the context from a file. However, it does not handle the case where the file does not exist. This could lead to a FileNotFoundError which is not being caught and handled. This could be improved by adding error handling for this case.
5. /hamilton/cli/logic.py:279:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The load_context function should handle the case where the file extension is not supported. Consider adding error handling for ValueError.
  • Reasoning:
    The load_context function in logic.py is loading the context from a file. However, it does not handle the case where the file extension is not supported. This could lead to a ValueError which is not being caught and handled. This could be improved by adding error handling for this case.

Workflow ID: wflow_rJZzWw2DQqGXJ0bG


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants