-
Notifications
You must be signed in to change notification settings - Fork 2k
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
dist/tools: add Python style check in static tests #8078
Conversation
c60d709
to
35c6207
Compare
Maybe @cladmi you want to look at that one ? |
@@ -0,0 +1,35 @@ | |||
#!/usr/bin/env bash |
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.
why bash?
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.
because of the colored output when errors are found (using warning color). I couldn't make it work with sh
without having tput
result in the terminal... Maybe you have an idea ?
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.
Its the same as pr_check/pr_check.sh.
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.
ok
dist/tools/flake8/check.sh
Outdated
|
||
RIOTBASE=$(readlink -f "$(dirname $(realpath $0))/../../..") | ||
|
||
CHECK_PATHS="${RIOTBASE}/tests \ |
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.
please use "changed_files.sh" as all the other static checks do
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.
Thanks ! That's much better indeed. I pushed an update that adds this.
a515d89
to
ba3d717
Compare
Sorry, I wanted to look into this but did not have time, I will do next week. |
@cladmi, I can also raise an error (exit !0) when problems are found on modified files. What do you prefer ? |
I opened #8141 to keep track of the problems raised in the automatic test scripts. |
@@ -0,0 +1,35 @@ | |||
#!/usr/bin/env bash |
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.
Its the same as pr_check/pr_check.sh.
dist/tools/flake8/check.sh
Outdated
CRESET= | ||
fi | ||
|
||
. ${RIOTBASE:+${RIOTBASE}/}dist/tools/ci/changed_files.sh |
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.
This ${RIOTBASE:+${RIOTBASE}/}
does nothing, maybe more ${RIOTBASE:+.}/
.
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.
It does add a slash, shout riotbase be set, right? So we don't end up with neither "/home/foo/bardist/tools/..." nor "/dist/tools/.../".
dist/tools/flake8/check.sh
Outdated
fi | ||
|
||
# Allow 119 characters width per line to simplify test output parsing | ||
ERRORS=$(flake8 --max-line-length=119 ${FILES}) |
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.
I would prefer changing to using a config file here.
dist/tools/flake8/check.sh
Outdated
|
||
if [ -n "${ERRORS}" ] | ||
then | ||
echo -e "${CWARNING}There are style issues in the following Python scripts:${CRESET}" |
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.
AFAIR "echo -e" causes trouble on some platforms (OSX?).
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.
printf is better, more portable
f803ab5
to
5023717
Compare
@cladmi, I addressed your comments |
dist/tools/flake8/check.sh
Outdated
CRESET= | ||
fi | ||
|
||
. ${RIOTBASE:+./}dist/tools/ci/changed_files.sh |
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.
Every makefiles is using $(RIOTBASE)/ so I think the '/' can be put after, but maybe I'm wrong.
You could add a DIST_TOOLS variable so the${RIOTBASE} with default value is only done once in the file.
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.
After testing a bit, putting the /
outside was giving /dist/tools/...
with an empty RIOTBASE
. The problem was the +
that should be a -
:
${RIOTBASE:-.}/dist/tools/
works when RIOTBASE is empty and also when RIOTBASE is a valid path.
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.
And there is the same problem in the ccpcheck.sh script I think
dist/tools/flake8/check.sh
Outdated
exit 0 | ||
fi | ||
|
||
# Allow 119 characters width per line to simplify test output parsing |
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.
The comment can be moved to the config file I think.
6c8e55b
to
d185771
Compare
# directory for more details. | ||
# | ||
|
||
if tput colors &> /dev/null && [ $(tput colors) -ge 8 ]; then |
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.
To answer https://github.com/RIOT-OS/RIOT/pull/8078/files#r151843512: The &>
here is a bash-ism. The portable way would be > /dev/null 2> /dev/null
.
Is there still a dependency, that needs to be merged, before we can merge this one? |
Murdock workers should now be up-to-date and travis dependency is added by this PR. Now I'm just wondering if we should consider returning an error (and have the static-test failed) instead of just a warning. |
@cladmi do you still see things to change here ? |
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.
looks good to me, and having this check will (hopefully) enforce good python on our test scripts 😉
dist/tools/flake8/check.sh
Outdated
then | ||
printf "${CWARNING}There are style issues in the following Python scripts:${CRESET}\n\n" | ||
printf "${ERRORS}\n" | ||
exit 0 |
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.
just to make this more obvious: this check script never fails but just list problematic files with a warning yellow color. I can change to a more strict rule if desired: red error color + exit 1.
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.
mhm, did you run it all over RIOT checking all python in the current master? If that's the case and all current python stuff sticks with rules, I'd says lets be more strict and exit 1
because most people don't look into build logs if they succeed.
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.
did you run it all over RIOT checking all python in the current master?
Yes and the scripts in test should be fine but not the one in the dist/tools directory. But I agree we should be more strict now and open PRs if problems occur later.
d185771
to
035bdf7
Compare
@smlng this PR is now strict with python style issues. The CI will fail if there are problems in a python file touched by a PR. |
@cladmi can you have another look at this one ? |
As required in #8036 (see comment), I'm trying to split the PR in smaller pieces.
This PR is about adding a new checker in the static-test for common Python style issues. I think it's important to keep the automatic test scripts consistent and Python provide very well described rules for that (see PEP8 for instance).
The style checks are performed using Flake8. I also integrated this into Travis (
that will obviously fail).The static-test target doesn't fail for now but just displays the errors found.
We could also go further with linter (using pylint) but I'm still not convinced for the moment.