-
-
Notifications
You must be signed in to change notification settings - Fork 6
🐛 extract relevant output from hatch env show --json
#95
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?
Conversation
If `result.stdout` contains something more than the JSON output of all the environments, such as logs from Hatch plugins/hooks, this will result in JSONDecodeError. We must extract the relevant output to prevent such cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where parsing the output of hatch env show --json could fail with a JSONDecodeError when the stdout contains additional content beyond the JSON output, such as logs from Hatch plugins or hooks. The fix extracts only the relevant JSON output by taking the last line of stdout.
- Adds robust JSON output extraction from
hatch env show --jsoncommand - Prevents
JSONDecodeErrorwhen stdout contains plugin/hook logs before the JSON output
Comments suppressed due to low confidence (1)
hatch_pip_compile/cli.py:146
- [nitpick] The variable name 'envs_raw' is somewhat ambiguous. Consider renaming it to 'json_output' or 'last_line_output' to better reflect that it contains the extracted JSON data from the last line.
envs_raw = result.stdout.strip().rsplit(b"\n", maxsplit=1)[-1]
|
lol, that was my first time requesting review from co-pilot. It wasn't actually that useful. Thanks for the contribution, @valentinoli - give me a day or to get a closer look at this but everything looks good on first glance. |
|
Perhaps consider parsing |
If
result.stdoutcontains something more than the JSON output of all the environments, such as logs from Hatch plugins/hooks, this will result inJSONDecodeError. We must extract the relevant output to prevent such cases.