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

Small fixes #31

Merged
merged 4 commits into from
Aug 24, 2022
Merged

Small fixes #31

merged 4 commits into from
Aug 24, 2022

Conversation

ale-rt
Copy link
Member

@ale-rt ale-rt commented Aug 24, 2022

Better reviewd commit by commit

@mister-roboto
Copy link

@ale-rt thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@ale-rt
Copy link
Member Author

ale-rt commented Aug 24, 2022

@jenkins-plone-org please run jobs

Copy link
Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.
I added two inline comments, but they can be ignored. I will merge.

@@ -300,8 +300,9 @@ def validateTicket(secret, ticket, ip='0.0.0.0', timeout=0, now=None,

# doctest runner
def _test():
import doctest
from plone.session.tests.testDocTests import Py23DocChecker
Copy link
Member

Choose a reason for hiding this comment

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

Py23DocChecker could also be removed. But can be done later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Py23DocChecker is removed in #32

@@ -1,2 +1,11 @@
[bdist_wheel]
universal = 0

[flake8]
max-line-length = 88
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we are running flake8 anymore. Just black. But it does not hurt.
I myself have a small custom script to call flake8 and ignore a few common problems:

$ cat ~/bin/pychecker3
#! /bin/sh
#infile = $1
if test "x$1" = "x--stdlib"; then
    # --stdlib gets passed by some python-mode.el versions.  pep8 and
    # pyflakes and flake8 cannot handle this, so we ignore this argument, by
    # shifting the rest of the arguments.
    #shift
    # Actually, we suddenly get passed 'pychecker --stdlib /Volumes/Macintosh /Volumes/Macintosh /Volumes/Macintosh /Volumes/Macintosh /Volumes/Macintosh /Users/mauritsvanrees/myfile.py'
    # So we shift to the last argument and pass only that
    shift $(($# - 1))
fi
# Check with Python 3.
# E203 Whitespace before ':' (false positives when using black)
# E231 missing whitespace after ',' (conflicts with black)
# E501 line too long
# W503 Line break occurred before a binary operator [outdated]
flake8 --ignore=E203,E231,E501,W503 $1 | sort-flake8

And then sort-flake8:

#!/usr/bin/env python
# Example: flake8 zest/releaser/utils.py | ./pychecker-sort
# Sorts with Failures first.
import sys
lines = sys.stdin.read().splitlines()


def get_code(line):
    """Extract error code from line.

    Example line:
    'zest/releaser/utils.py:797:1: E302 expected 2 blank lines, found 1'
    """
    if line.count(':') != 3:
        return ''
    filename, lineno, pos, error = line.split(':')
    # Example error:
    # ' E302 expected 2 blank lines, found 1'
    code = error.strip().split(' ', 1)[0]
    if not code:
        return ''
    return code


def sortable_code(code):
    """Make code sortable.

    First failures, then errors, then warnings, then any others.
    """
    if not code:
        # sort last
        return '9'
    first = code[0]
    if first == 'F':
        value = 0
    elif first == 'E':
        value = 1
    elif first == 'W':
        value = 2
    else:
        value = 3
    return '{}{}'.format(value, code)


def error_value(line):
    return sortable_code(get_code(line))


for line in sorted(lines, key=error_value):
    print(line)

@mauritsvanrees mauritsvanrees merged commit ea96eaa into master Aug 24, 2022
@mauritsvanrees mauritsvanrees deleted the small-fixes branch August 24, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants