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

nixos/testing-python.nix: Add skipFormatter #122197

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nixos/lib/testing-python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ rec {
{ testScript
, enableOCR ? false
, name ? "unnamed"
# Skip linting (mainly intended for faster dev cycles)
# Skip linting (not advisable)
, skipLint ? false
# Skip formatting check
, skipFormatter ? false
Copy link
Member

Choose a reason for hiding this comment

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

Having this false by default wouldn't prevent those annoyances (you get annoyed, then enable skipFormatter until all tests have it enabled?) unless we use skipFormatter = true; for every test, which then in turn poses the question why we need black at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're 100% right about this, but the apparent lack of agreement on this topic still makes me hesitant to decide for everyone. I'd be happy to change it to true though.

, passthru ? {}
, # For meta.position
pos ? # position used in error messages and for meta.position
Expand Down Expand Up @@ -158,7 +160,7 @@ rec {
mkdir -p $out/bin

echo -n "$testScript" > $out/test-script
Copy link
Member

Choose a reason for hiding this comment

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

Hm, what about doing something like this instead:

Suggested change
echo -n "$testScript" > $out/test-script
echo "# fmt: off" > $out/test-script
echo -n "$testScript" >> $out/test-script

I do this by default on all my tests and if I'm not missing something, this causes black to not apply formatting but still does things such as syntax checks and other rather useful things.

Copy link
Member Author

Choose a reason for hiding this comment

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

What else does it do? I've re-read the README, but it only seems to talk about formatting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Giving this a shot here #122199

Copy link
Member

@aszlig aszlig May 8, 2021

Choose a reason for hiding this comment

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

Okay, just checked: It basically just does a syntax check. Maybe using something like pyflakes is a better idea because it does have useful checks, eg. usage of undefined variables, invalid format arguments, duplicate arguments, shadowed loop vars and more.

Copy link
Member

Choose a reason for hiding this comment

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

@roberth: Gave this a shot as well here: #122201

${lib.optionalString (!skipLint) ''
${lib.optionalString (!skipLint && !skipFormatter) ''
${python3Packages.black}/bin/black --check --diff $out/test-script
''}

Expand Down