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

dist/tools: add Python style check in static tests #8078

Merged
merged 2 commits into from
Dec 19, 2017

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Nov 17, 2017

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.

@aabadie aabadie added Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools labels Nov 17, 2017
@aabadie aabadie force-pushed the pr/python_style_check branch 4 times, most recently from c60d709 to 35c6207 Compare November 17, 2017 16:49
@aabadie
Copy link
Contributor Author

aabadie commented Nov 17, 2017

Maybe @cladmi you want to look at that one ?

@@ -0,0 +1,35 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

why bash?

Copy link
Contributor Author

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 ?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok


RIOTBASE=$(readlink -f "$(dirname $(realpath $0))/../../..")

CHECK_PATHS="${RIOTBASE}/tests \
Copy link
Contributor

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

Copy link
Contributor Author

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.

@aabadie aabadie force-pushed the pr/python_style_check branch 4 times, most recently from a515d89 to ba3d717 Compare November 18, 2017 18:35
@aabadie
Copy link
Contributor Author

aabadie commented Nov 18, 2017

I pushed ba3d717 just to make sure errors are raised on modified files and the build remains successful (just a warning). 5a06800 shows that everything is fine after fixing the detected issues.

@cladmi
Copy link
Contributor

cladmi commented Nov 24, 2017

Sorry, I wanted to look into this but did not have time, I will do next week.

@aabadie
Copy link
Contributor Author

aabadie commented Nov 27, 2017

@cladmi, I can also raise an error (exit !0) when problems are found on modified files. What do you prefer ?

@aabadie
Copy link
Contributor Author

aabadie commented Nov 27, 2017

I opened #8141 to keep track of the problems raised in the automatic test scripts.

@@ -0,0 +1,35 @@
#!/usr/bin/env bash
Copy link
Contributor

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.

CRESET=
fi

. ${RIOTBASE:+${RIOTBASE}/}dist/tools/ci/changed_files.sh
Copy link
Contributor

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:+.}/.

Copy link
Contributor

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/.../".

fi

# Allow 119 characters width per line to simplify test output parsing
ERRORS=$(flake8 --max-line-length=119 ${FILES})
Copy link
Contributor

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.


if [ -n "${ERRORS}" ]
then
echo -e "${CWARNING}There are style issues in the following Python scripts:${CRESET}"
Copy link
Contributor

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?).

Copy link
Member

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

@aabadie aabadie force-pushed the pr/python_style_check branch 2 times, most recently from f803ab5 to 5023717 Compare November 29, 2017 17:02
@aabadie
Copy link
Contributor Author

aabadie commented Nov 29, 2017

@cladmi, I addressed your comments

CRESET=
fi

. ${RIOTBASE:+./}dist/tools/ci/changed_files.sh
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

exit 0
fi

# Allow 119 characters width per line to simplify test output parsing
Copy link
Contributor

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.

@aabadie aabadie force-pushed the pr/python_style_check branch 2 times, most recently from 6c8e55b to d185771 Compare November 30, 2017 19:31
# directory for more details.
#

if tput colors &> /dev/null && [ $(tput colors) -ge 8 ]; then
Copy link
Member

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.

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 11, 2017
@miri64
Copy link
Member

miri64 commented Dec 11, 2017

Is there still a dependency, that needs to be merged, before we can merge this one?

@aabadie
Copy link
Contributor Author

aabadie commented Dec 11, 2017

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.

@kaspar030 kaspar030 dismissed their stale review December 11, 2017 21:28

comments addressed

@aabadie
Copy link
Contributor Author

aabadie commented Dec 14, 2017

@cladmi do you still see things to change here ?

Copy link
Member

@smlng smlng left a 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 😉

then
printf "${CWARNING}There are style issues in the following Python scripts:${CRESET}\n\n"
printf "${ERRORS}\n"
exit 0
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@aabadie
Copy link
Contributor Author

aabadie commented Dec 15, 2017

@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.

@aabadie
Copy link
Contributor Author

aabadie commented Dec 18, 2017

@cladmi can you have another look at this one ?

@cladmi cladmi merged commit a40e9ba into RIOT-OS:master Dec 19, 2017
@aabadie aabadie added this to the Release 2018.01 milestone Jan 18, 2018
@aabadie aabadie deleted the pr/python_style_check branch June 8, 2018 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants