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

[BUG!] Python script with Status adding new line to stdout with echo #1662

Closed
victor-mariano-leite opened this issue Nov 9, 2021 · 4 comments · Fixed by #1667
Closed

[BUG!] Python script with Status adding new line to stdout with echo #1662

victor-mariano-leite opened this issue Nov 9, 2021 · 4 comments · Fixed by #1667

Comments

@victor-mariano-leite
Copy link

victor-mariano-leite commented Nov 9, 2021

Describe the bug
In my company CI pipeline with GitHub Actions, recently a weird behavior started to appear when I ran a script that outputed a new environment variable with print:

echo "IMAGE_NAME=$(python -m buggy_deployment_manager --silent build $ENV .)" >> $GITHUB_ENV

This week or so, we've discovered it started to break all of our workflow jobs (GHA) with:

Error: Unable to process file command 'env' successfully.
Error: Invalid environment variable format '***.dkr.ecr.***.amazonaws.com/some-image-name'

Which usually happens when some unsupported character goes into the GITHUB_ENV file.

Going deep into the problem I found out that there was a newline being outputed to $GITHUB_ENV, although there was no print statement other than only one in the buggy_deployment_manager module, and no logging or etc was being held in the stdout buffer explicitly.

With pdb and flushing all print outputs, I've discovered that the context manager Status from rich actually (somehow and to somewhere) inside this buggy_deployment_manager prints out a newline to echo once it ends. This \n only appeared with echo, which is a weird behavior, I don't think it was supposed to happen or why it happened.

To Reproduce

Create a script named bug.py with:

from rich.status import Status
print("1 ", end="")
with Status("Go"):
    print("2 ", end="")
print("3 ", end="")

And run with:

#!/bin/bash
echo "WHAT=$(python bug.py)"

Instead of:

WHAT=1 2 3 

It will write:

WHAT=1 2 
3 

Platform

I've used locally on MacOS 12.0.1, Ubuntu 20.04 and within our CI runner ( Debian 11 ) with:

  • Python 3.8.10, 3.9.7, 3.9.8;
@willmcgugan
Copy link
Collaborator

I think I know the cause. You might want to revert to 10.12.0 in the meantime.

@victor-mariano-leite
Copy link
Author

Nice @willmcgugan! thanks for the suggestion.

What would be the problem? We were very curious in my team yesterday 😛

@willmcgugan
Copy link
Collaborator

I think this PR #1648 had some unintended consequences.

@github-actions
Copy link

github-actions bot commented Nov 9, 2021

Did I solve your problem?

Consider sponsoring the ongoing work on Rich and Textual.

Or buy me a coffee to say thanks.

Will McGugan

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 23, 2021
10.14.0

Fixed

Fixed progress speed not updating when total doesn't change
Fixed superfluous new line in Status Textualize/rich#1662
Fixed Windows legacy width again
Fixed infinite loop in set_cell_size Textualize/rich#1682

Added

Added file protocol to URL highlighter Textualize/rich#1681
Added rich.protocol.rich_cast

Changed

Allowed __rich__ to work recursively
Allowed Text classes to work with sep in print Textualize/rich#1689
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants