Skip to content

CI: Format isort output to be detected as Azure pipelines errors #27179

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
datapythonista opened this issue Jul 2, 2019 · 1 comment · Fixed by #29654
Closed

CI: Format isort output to be detected as Azure pipelines errors #27179

datapythonista opened this issue Jul 2, 2019 · 1 comment · Fixed by #29654
Labels
CI Continuous Integration good first issue

Comments

@datapythonista
Copy link
Member

datapythonista commented Jul 2, 2019

isort is a tool to validate the order of the imports in Python code. We are using it in the CI to make sure all pandas imports follow a defined standard. It is implemented in ci/code_checks.sh.

When isort detects imports incorrectly sorted, it finishes with an exit code different than 0, and that makes the CI red. Besides that, it'd be useful that in Azure Pipelines (the CI system where isort runs) the output messages of isort were detected as errors.

Some tools provide an option to specify the output format, like flake8, but isort doesn't (see PyCQA/isort#961).

What we can do in this case is to modify the output with bash pipelines. We are already doing that in the invgrep function in ci/code_checks.sh.

What needs to be done is:

  • Change the format of isort output to be: `##vso[task.logissue type=error;sourcepath=%(path)s]%(text)s"
  • Make sure that the resulting command still has an exit code of 0 if no issues are found, and the exit code of isort is there are. e.g. the exit code of isort -c foo.py | awk -F" " '{ print $2 }' is 0, the exit code of awk even if errors are found (the exit code of isort is lost in the pipeline).

Note that the error message of isort is not delimited in a way that can be easily parsed. But since the error message does not change, it should be possible to extract the name of the file removing the number of characters of the text around it (see https://github.com/timothycrosley/isort/blob/develop/isort/isort.py#L122).

@leeyspaul
Copy link
Contributor

Happy to take this up! @datapythonista

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants