GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Check for whitespace in CI · Issue #429 · python/core-workflow

Check for whitespace in CI #429

New issue
Copy link
New issue
Copy link
Closed
python/cpython
#104275
python/cpython#104275
Closed
Check for whitespace in CI#429
python/cpython
#104275
Copy link
Labels
CI

Description

@erlend-aasland
erlend-aasland
opened on Mar 5, 2022
Issue body actions

Consider adding a CI check for whitespace errors, a la git diff --check.

I've seen this idea surface a couple of times, most recently by @JelleZijlstra in python/cpython#31695 (comment)

Reacted by Jelle Zijlstra, Alex Waygood and Hugo van Kemenade

Activity

  1. erlend-aasland
    added
    CI
    on Mar 5, 2022
  2. erlend-aasland commented on Mar 5, 2022

    @erlend-aasland
    erlend-aasland
    on Mar 5, 2022
    Author
    More actions

    I remembered I got a PoC branch lying around: https://github.com/erlend-aasland/cpython/tree/add-whitespace-linter

  3. hugovk commented on Mar 5, 2022

    @hugovk
    hugovk
    on Mar 5, 2022
    Member
    More actions

    Sounds good.

    Looking at the erlend-aasland/cpython#14 PoC, some ideas:

    • Rather than only running on PRs, can it also run for pushes? That way contributors may see and fix a failure on their fork's CI even before opening a PR ("fast feedback loop")

    • How about using https://pre-commit.com ? There's a trailing-whitespace hook to trim trailing whitespace.

      • For developers who like pre-commit, it can autofix things for you before you even commit/push

      • For those who don't, there's absolutely no obligation to run locally and the CI will pick things up

      • Can run on pushes and PRs

      • Easily extensible, there are lots of other checks which may be useful (for example, check-yaml to validate CI config)

    Reacted by Alex Waygood, Erlend E. Aasland and Jonas Kittner
  4. erlend-aasland commented on Mar 5, 2022

    @erlend-aasland
    erlend-aasland
    on Mar 5, 2022
    Author
    More actions

    Rather than only running on PRs, can it also run for pushes? That way contributors may see and fix a failure on their fork's CI even before opening a PR ("fast feedback loop")

    +1

    How about using https://pre-commit.com/ ?

    Oooh, that sure looks nice!

  5. hugovk commented on Mar 5, 2022

    @hugovk
    hugovk
    on Mar 5, 2022
    Member
    More actions

    Here's an example: hugovk/cpython#22

    There's currently a lot of files with trimmable trailing whitespace, see:

    • Add pre-commit config and test on CI hugovk/cpython#22 (comment) for a list
    • https://github.com/hugovk/cpython/runs/5434180892?check_suite_focus=true for diffs

    So we could limit it to certain file types. For example types_or: [c, python]. And/or to certain directories.

    Reacted by Erlend E. Aasland
  6. erlend-aasland commented on Mar 5, 2022

    @erlend-aasland
    erlend-aasland
    on Mar 5, 2022
    Author
    More actions

    Here's an example: hugovk/cpython#22

    Neat! Much more elegant than my PoC 😅

    So we could limit it to certain file types. For example types: [c, python]. And/or to certain directories.

    +1

  7. hugovk commented on Mar 5, 2022

    @hugovk
    hugovk
    on Mar 5, 2022
    Member
    More actions

    I've updated hugovk/cpython#22 to remove the trailing whitespace, and add:

            types_or: [c, python]
            exclude: ^Lib/test/test_argparse.py$

    I excluded that file because a couple of its asserts depend on trailing whitespace:

    https://github.com/python/cpython/blob/6927632492cbad86a250aa006c1847e03b03e70b/Lib/test/test_argparse.py#L2179
    https://github.com/python/cpython/blob/6927632492cbad86a250aa006c1847e03b03e70b/Lib/test/test_argparse.py#L2196

  8. arhadthedev commented on Mar 5, 2022

    @arhadthedev
    arhadthedev
    on Mar 5, 2022
    Member
    More actions

    I excluded that file because a couple of its asserts depend on trailing whitespace

    These whitespaces are invisible to a programmer who reads the assertions. Can the following be used instead?

             self.assertEqual(parser.format_help(), textwrap.dedent('''\
                 usage: PROG [-h] {}
                 main description
                 positional arguments:
    -              {}          
    +              {}          ''' + '''
                 options:
                   -h, --help  show this help message and exit
             '''))
  9. ericvsmith commented on Mar 6, 2022

    @ericvsmith
    ericvsmith
    on Mar 6, 2022
    Member
    More actions

    I excluded that file because a couple of its asserts depend on trailing whitespace

    These whitespaces are invisible to a programmer who reads the assertions. Can the following be used instead?

    I agree that's better. Also a comment explaining why there are trailing spaces and why the string is constructed that way would help.

    Reacted by Erlend E. Aasland, Oleg Iarygin, Hugo van Kemenade and Ezio Melotti
  10. hugovk commented on Mar 14, 2022

    @hugovk
    hugovk
    on Mar 14, 2022
    Member
    More actions

    Well turns out there was already a whitespace check run on the CI as part of make patchcheck.

    It was broken but has now been fixed: python/cpython#31708

    Do we still need the pre-commit suggestion in hugovk/cpython#22 or this issue?

  11. sweeneyde commented on Apr 17, 2022

    @sweeneyde
    sweeneyde
    on Apr 17, 2022
    Member
    More actions

    I think it would be nice to have the patchcheck as its own GitHub Action with its own green checkmark, so that sort of common issue gets noticed within seconds, rather than having to wait on the build and the whole test suite to run.

    Theoretically, I think we should be able to use actions/setup-python@v3 and not even have to build python at all. Currently, patchcheck uses sys.version to determine what the base branch is, but it could be determined by some sort of patchcheck.py --base_branch ${{ github.base_ref }} feature instead. But I am no wizard at GitHub Actions.

    Reacted by Alex Waygood, Erlend E. Aasland, Hugo van Kemenade and Ezio Melotti
  12. hugovk commented on May 7, 2023

    @hugovk
    hugovk
    on May 7, 2023
    Member
    More actions

    Please see PR python/cpython#104275.

    Reacted by Itamar Oren and Erlend E. Aasland
  13. hugovk
    closed this as completedin cpython#104275on May 8, 2023
  14. erlend-aasland commented on Jun 27, 2023

    @erlend-aasland
    erlend-aasland
    on Jun 27, 2023
    Author
    More actions

    See also:

    • make patchcheck should check the whitespace of .c/.h files cpython#53158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CI

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.