Skip to content

CI: format isort output for detection by azure pipelines #27334

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

Closed
wants to merge 7 commits into from
Closed

CI: format isort output for detection by azure pipelines #27334

wants to merge 7 commits into from

Conversation

leeyspaul
Copy link
Contributor

@leeyspaul leeyspaul commented Jul 11, 2019

@leeyspaul leeyspaul changed the title format isort output CI: Format isort output to be detected as Azure pipelines errors Jul 11, 2019
@leeyspaul leeyspaul changed the title CI: Format isort output to be detected as Azure pipelines errors CI: format isort output for detection by azure pipeliens Jul 11, 2019
@leeyspaul leeyspaul changed the title CI: format isort output for detection by azure pipeliens CI: format isort output for detection by azure pipelines Jul 11, 2019
@@ -109,7 +109,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then

# Imports - Check formatting using isort see setup.cfg for settings
MSG='Check import format using isort ' ; echo $MSG
isort --recursive --check-only pandas asv_bench
isort --recursive --check-only pandas asv_bench | awk -F ":" '##vso[task.logissue type=error;sourcepath=%(path)s]%(text)s'
Copy link
Member

Choose a reason for hiding this comment

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

Looks good, but we just want to change the format when the environment variable AZURE is set. You can see how this is done for flake8. Sorry it wasn't clear in the issue.

Can you also change the order of an import to see this failing in the CI please? So we can see it working before we merge. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, thank you for being so helpful!

Copy link
Member

Choose a reason for hiding this comment

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

Does this still grab the return code from isort?

@datapythonista datapythonista added CI Continuous Integration Error Reporting Incorrect or improved errors from pandas labels Jul 11, 2019
@leeyspaul
Copy link
Contributor Author

@datapythonista sorry I'm a bit new to bash scripting. It's definitely catching the import error but it is ignoring the exception as shown here:

BrokenPipeError: [Errno 32] Broken pipe
Check import format using isort DONE
##[error]Bash exited with code '120'.```

fix isort formatting for awk

fix isort format output

test awk change

fix isort output for azure

remove comment

fix deliberate import errors

fix whitespace

whitespace fix
@leeyspaul
Copy link
Contributor Author

pinging for review! Spent some time on it to understand awk. @datapythonista thank you!

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Thanks @leeyspaul, getting closer, still some comments.

@@ -109,9 +109,12 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then

# Imports - Check formatting using isort see setup.cfg for settings
MSG='Check import format using isort ' ; echo $MSG
isort --recursive --check-only pandas asv_bench
if [[ "$AZURE" == "true" ]]; then
isort --recursive --check-only pandas asv_bench | awk -F ':' '{print $0"\n" "##vso[task.logissue type=error;sourcepath=%(path)s]%(text)s"}'
Copy link
Member

Choose a reason for hiding this comment

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

I think the return code $? we are checking later to see if isort was successful or not, will actually be the one of awk with this, which will always be 0.

This means that if the imports are not correctly sorted, we won't detect them in the CI.

Can you start by swapping the order of two imports in pandas in this PR, so we know if this is working or not? We'll remove them once the PR is approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will push up the badly sorted imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is the output! Check import format using isort ERROR: /home/vsts/work/1/s/pandas/plotting/_matplotlib/core.py Imports are incorrectly sorted. ##[error]%(path)s(,): error : %(text)s Check import format using isort DONE ##[error]Bash exited with code '1'. ##[section]Finishing: Linting

@datapythonista
Copy link
Member

Seems like awk is keeping the exit status of isort, I guess it's because of the set -o pipefail in the function at the top of the function, we'll have to fix that.

But the first things would probably be fixing the output, from:

ERROR: /home/vsts/work/1/s/pandas/plotting/_matplotlib/core.py 
##[error]%(path)s(,): error : %(text)s

to

##vso[task.logissue type=error;sourcepath=/home/vsts/work/1/s/pandas/plotting/_matplotlib/core.py] Imports are incorrectly sorted.

Thanks!

leeyspaul added 3 commits August 2, 2019 22:03
fix output

test azuredev output

fix awk output to show path

reformat output to incorporate error msg

format output to catch path and error name
@leeyspaul
Copy link
Contributor Author

ok! I think I'm getting closer now. @datapythonista could you check out the failure? I've pasted below what it's returning for ease.

Check import format using isort
##[error]pandas/plotting/_matplotlib/core.py(,): error :   Imports are incorrectly sorted.Check import format using isort DONE
##[error]Bash exited with code '1'.
##[section]Finishing: Linting

I added the ORS as the error message was moving to a new line with print. If there is a better way to do this do let me know, thank you!

@datapythonista
Copy link
Member

is there a reason to not use the ##vso code I suggested? I think is what we use in the other cases, if there is no reason better to keep consistent.

@leeyspaul
Copy link
Contributor Author

is there a reason to not use the ##vso code I suggested? I think is what we use in the other cases, if there is no reason better to keep consistent.

er, I didn't mean to remove anything. I'm not too familiar on vso codes but I read up on logging here: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md

Could you clarify what you mean by the vso code and I will change it back, or point me to the docs. Thank you!

@datapythonista
Copy link
Member

I refer to what is suggested in #27334 (comment) instead of using ##[error]

@leeyspaul
Copy link
Contributor Author

ah right. So oddly it seems to be getting converted from ##vso to ##[error] though the awk line I've used is isort --recursive --check-only pandas asv_bench | awk '{ORS=""} {print "##vso[task.logissue type=error;sourcepath="$2";]"} {$1=$2=""; print $0}'.

I might be missing something obvious here

@datapythonista
Copy link
Member

ah, sorry, didn't see in the code you were already using the ##vso. I guess that's some azure magic then, but will be applied to all the other commands too, so it's ok.

I'd prefer to remove the awk and leave the original call when not using azure. Will be misleading if the errors are different when people call isort directly than with our script I think.

And the thing that concerns me is the set -o pipefail inside the if at the beginning. If eventually we change that code, your code will fail. And that doesn't seem right, since both things are unrelated, and shouldn't be using side-effects of each other. I'd start by adding set +o pipefail after the grep in line 39. That should already be there, will avoid the side effects, and will make your code fail. After that, you can wrap your code with the same set -o pipefail and set +o pipefail, and that should fix it again.

Does this make sense?

@leeyspaul
Copy link
Contributor Author

leeyspaul commented Aug 6, 2019

ah, sorry, didn't see in the code you were already using the ##vso. I guess that's some azure magic then, but will be applied to all the other commands too, so it's ok.

I'd prefer to remove the awk and leave the original call when not using azure. Will be misleading if the errors are different when people call isort directly than with our script I think.

And the thing that concerns me is the set -o pipefail inside the if at the beginning. If eventually we change that code, your code will fail. And that doesn't seem right, since both things are unrelated, and shouldn't be using side-effects of each other. I'd start by adding set +o pipefail after the grep in line 39. That should already be there, will avoid the side effects, and will make your code fail. After that, you can wrap your code with the same set -o pipefail and set +o pipefail, and that should fix it again.

Does this make sense?

I think so, I'll take a look at this tonight! Thanks for the info. : ) (will ping if I can't get it!)

@WillAyd
Copy link
Member

WillAyd commented Sep 5, 2019

@leeyspaul can you merge master again? Old builds are no longer available

@WillAyd
Copy link
Member

WillAyd commented Sep 13, 2019

@leeyspaul is this still active?

@leeyspaul
Copy link
Contributor Author

@WillAyd hey yeah, sorry. Had gotten caught up with work. I will work on this this weekend.

@WillAyd
Copy link
Member

WillAyd commented Sep 13, 2019

Great! No worries on timing - not in any rush. Just wanted to make sure this was something that you were still looking at, so thanks for confirming

@jreback
Copy link
Contributor

jreback commented Oct 6, 2019

@leeyspaul can you merge master and update

@jbrockmendel
Copy link
Member

@leeyspaul can you rebase

@alimcmaster1
Copy link
Member

alimcmaster1 commented Nov 2, 2019

If we dont hear from @leeyspaul I can take this on

@leeyspaul
Copy link
Contributor Author

leeyspaul commented Nov 4, 2019

@alimcmaster1 feel free to take over. I don't think I'll be able to complete this any time soon. Thanks!

@alimcmaster1
Copy link
Member

Restarted this over here: #29654

Closing this for now

@datapythonista
Copy link
Member

I'm moving the Checks build to actions, and I think it only supports the ##[error] formatting, not the one with file, line number...

@alimcmaster1
Copy link
Member

Ahh so there probably isn’t much value in this at all? I can close my PR if so

@datapythonista
Copy link
Member

There is surely value on letting the CI know what's an error. Just the format will probably be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI: Format isort output to be detected as Azure pipelines errors
6 participants