Skip to content

Commit

Permalink
Merge pull request #2996 from Excalartur/pylint-pass2
Browse files Browse the repository at this point in the history
update pylint version, and fix linter issues
  • Loading branch information
benoitc committed May 25, 2023
2 parents 6998d12 + dd0aebf commit add8a4c
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ignore=

disable=
attribute-defined-outside-init,
bad-continuation,
bad-mcs-classmethod-argument,
bare-except,
broad-except,
Expand All @@ -25,12 +24,10 @@ disable=
import-self,
inconsistent-return-statements,
invalid-name,
misplaced-comparison-constant,
missing-docstring,
no-else-return,
no-member,
no-self-argument,
no-self-use,
no-staticmethod-decorator,
not-callable,
protected-access,
Expand All @@ -53,3 +50,6 @@ disable=
useless-import-alias,
comparison-with-callable,
try-except-raise,
consider-using-with,
consider-using-f-string,
unspecified-encoding
1 change: 1 addition & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Andrew Svetlov <andrew.svetlov@gmail.com>
Anil V <avaitla16@gmail.com>
Antoine Girard <antoine.girard.dev@gmail.com>
Anton Vlasenko <antares.spica@gmail.com>
Artur Kruchinin <arturkruchinin@gmail.com>
Bartosz Oler <bartosz@bzimage.us>
Ben Cochran <bcochran@gmail.com>
Ben Oswald <ben.oswald@root-space.de>
Expand Down
5 changes: 4 additions & 1 deletion gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,8 @@ class LogConfigDict(Setting):
Format: https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig
For more context you can look at the default configuration dictionary for logging, which can be found at ``gunicorn.glogging.CONFIG_DEFAULTS``.
For more context you can look at the default configuration dictionary for logging,
which can be found at ``gunicorn.glogging.CONFIG_DEFAULTS``.
.. versionadded:: 19.8
"""
Expand Down Expand Up @@ -1993,6 +1994,7 @@ def on_exit(server):
The callable needs to accept a single instance variable for the Arbiter.
"""


class NewSSLContext(Setting):
name = "ssl_context"
section = "Server Hooks"
Expand Down Expand Up @@ -2027,6 +2029,7 @@ def ssl_context(conf, default_ssl_context_factory):
.. versionadded:: 20.2
"""


class ProxyProtocol(Setting):
name = "proxy_protocol"
section = "Server Mechanics"
Expand Down
19 changes: 9 additions & 10 deletions gunicorn/glogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@
"local7": 23
}

CONFIG_DEFAULTS = dict(
version=1,
disable_existing_loggers=False,

root={"level": "INFO", "handlers": ["console"]},
loggers={
CONFIG_DEFAULTS = {
"version": 1,
"disable_existing_loggers": False,
"root": {"level": "INFO", "handlers": ["console"]},
"loggers": {
"gunicorn.error": {
"level": "INFO",
"handlers": ["error_console"],
Expand All @@ -65,7 +64,7 @@
"qualname": "gunicorn.access"
}
},
handlers={
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "generic",
Expand All @@ -77,14 +76,14 @@
"stream": "ext://sys.stderr"
},
},
formatters={
"formatters": {
"generic": {
"format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter"
}
}
)
}


def loggers():
Expand Down Expand Up @@ -418,7 +417,7 @@ def _set_handler(self, log, output, fmt, stream=None):
if output == "-":
h = logging.StreamHandler(stream)
else:
util.check_is_writeable(output)
util.check_is_writable(output)
h = logging.FileHandler(output)
# make sure the user can reopen the file
try:
Expand Down
2 changes: 1 addition & 1 deletion gunicorn/http/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from gunicorn.http.message import HEADER_RE
from gunicorn.http.errors import InvalidHeader, InvalidHeaderName
from gunicorn import SERVER_SOFTWARE, SERVER
import gunicorn.util as util
from gunicorn import util

# Send files in at most 1GB blocks as some operating systems can have problems
# with sending files in blocks over 2GB.
Expand Down
10 changes: 7 additions & 3 deletions gunicorn/sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,15 @@ def create_sockets(conf, log, fds=None):

return listeners


def close_sockets(listeners, unlink=True):
for sock in listeners:
sock_name = sock.getsockname()
sock.close()
if unlink and _sock_type(sock_name) is UnixSocket:
os.unlink(sock_name)


def ssl_context(conf):
def default_ssl_context_factory():
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH, cafile=conf.ca_certs)
Expand All @@ -222,7 +224,9 @@ def default_ssl_context_factory():

return conf.ssl_context(conf, default_ssl_context_factory)


def ssl_wrap_socket(sock, conf):
return ssl_context(conf).wrap_socket(sock, server_side=True,
suppress_ragged_eofs=conf.suppress_ragged_eofs,
do_handshake_on_connect=conf.do_handshake_on_connect)
return ssl_context(conf).wrap_socket(sock,
server_side=True,
suppress_ragged_eofs=conf.suppress_ragged_eofs,
do_handshake_on_connect=conf.do_handshake_on_connect)
6 changes: 3 additions & 3 deletions gunicorn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,12 @@ def seed():
random.seed('%s.%s' % (time.time(), os.getpid()))


def check_is_writeable(path):
def check_is_writable(path):
try:
f = open(path, 'a')
with open(path, 'a') as f:
f.close()
except IOError as e:
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))
f.close()


def to_bytestring(value, encoding="utf8"):
Expand Down
8 changes: 4 additions & 4 deletions gunicorn/workers/base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import ssl
import sys

import gunicorn.http as http
import gunicorn.http.wsgi as wsgi
import gunicorn.util as util
import gunicorn.workers.base as base
from gunicorn import http
from gunicorn.http import wsgi
from gunicorn import util
from gunicorn.workers import base

ALREADY_HANDLED = object()

Expand Down
1 change: 1 addition & 0 deletions gunicorn/workers/geventlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def run(self):
eventlet.sleep(1.0)

self.notify()
t = None
try:
with eventlet.Timeout(self.cfg.graceful_timeout) as t:
for a in acceptors:
Expand Down
2 changes: 1 addition & 1 deletion gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run(self):
ssl_args = {}

if self.cfg.is_ssl:
ssl_args = dict(ssl_context=ssl_context(self.cfg))
ssl_args = {"ssl_context": ssl_context(self.cfg)}

for s in self.sockets:
s.setblocking(1)
Expand Down
4 changes: 2 additions & 2 deletions gunicorn/workers/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# closed.
# pylint: disable=no-else-break

import concurrent.futures as futures
from concurrent import futures
import errno
import os
import selectors
Expand Down Expand Up @@ -124,7 +124,7 @@ def accept(self, server, listener):
conn = TConn(self.cfg, sock, client, server)
# set timeout to ensure it will not be in the loop too long
conn.set_timeout()

self.nr_conns += 1
# wait until socket is readable
with self._lock:
Expand Down
3 changes: 1 addition & 2 deletions gunicorn/workers/gtornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

import copy
import os
import sys

Expand Down Expand Up @@ -112,7 +111,7 @@ def run(self):
isinstance(app, tornado.wsgi.WSGIApplication):
app = WSGIContainer(app)
elif not isinstance(app, WSGIContainer) and \
not isinstance(app, tornado.web.Application):
not isinstance(app, tornado.web.Application):
app = WSGIContainer(app)

# Monkey-patching HTTPConnection.finish to count the
Expand Down
10 changes: 5 additions & 5 deletions gunicorn/workers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import ssl
import sys

import gunicorn.http as http
import gunicorn.http.wsgi as wsgi
import gunicorn.sock as sock
import gunicorn.util as util
import gunicorn.workers.base as base
from gunicorn import http
from gunicorn.http import wsgi
from gunicorn import sock
from gunicorn import util
from gunicorn.workers import base


class StopWaiting(Exception):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See the NOTICE for more information.

import os
import unittest.mock as mock
from unittest import mock

import gunicorn.app.base
import gunicorn.arbiter
Expand Down
2 changes: 1 addition & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io
import t
import pytest
import unittest.mock as mock
from unittest import mock

from gunicorn import util
from gunicorn.http.body import Body, LengthReader, EOFReader
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pidfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See the NOTICE for more information.

import errno
import unittest.mock as mock
from unittest import mock

import gunicorn.pidfile

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

import unittest.mock as mock
from unittest import mock

from gunicorn import sock

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest

from gunicorn.config import (
KeyFile, CertFile, SSLVersion, CACerts, SuppressRaggedEOFs,
KeyFile, CertFile, CACerts, SuppressRaggedEOFs,
DoHandshakeOnConnect, Setting, Ciphers,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from contextlib import contextmanager
import os
import unittest.mock as mock
from unittest import mock

import pytest

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ deps =
[testenv:lint]
commands =
pylint -j0 \
--max-line-length=120 \
gunicorn \
tests/test_arbiter.py \
tests/test_config.py \
Expand All @@ -26,7 +27,7 @@ commands =
tests/test_util.py \
tests/test_valid_requests.py
deps =
pylint<2.7
pylint==2.17.4

[testenv:docs-lint]
allowlist_externals =
Expand Down

0 comments on commit add8a4c

Please sign in to comment.