From a1d99b41be5bb303cd1ba65dfbd755e9d57f95ff Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 11 Nov 2021 15:29:17 -0500 Subject: [PATCH] Pylint and RTD update patch, and other fixes --- .github/workflows/build.yml | 4 ++-- .pre-commit-config.yaml | 30 +++++++++++++++--------------- .pylintrc | 2 +- adafruit_requests.py | 6 +++--- docs/requirements.txt | 5 +++++ tests/mocket.py | 3 +-- 6 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 docs/requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4c975d..ca35544 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 49d9415..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,25 +18,25 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 + rev: v2.11.1 hooks: - id: pylint name: pylint (library code) types: [python] + args: + - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) + - id: pylint + name: pylint (example code) description: Run pylint rules on "examples/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] - language: system -- repo: local - hooks: - - id: pylint_tests - name: pylint (tests code) + types: [python] + files: "^examples/" + args: + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint + name: pylint (test code) description: Run pylint rules on "tests/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "tests" ]] || for example in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] - language: system + types: [python] + files: "^tests/" + args: + - --disable=missing-docstring,consider-using-f-string,duplicate-code diff --git a/.pylintrc b/.pylintrc index f006a4a..cfd1c41 100755 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=12 +min-similarity-lines=4 [BASIC] diff --git a/adafruit_requests.py b/adafruit_requests.py index ed2f97c..aaa56cb 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -383,7 +383,7 @@ def _close_socket(self, sock): sock.close() del self._socket_free[sock] key = None - for k in self._open_sockets: + for k in self._open_sockets: # pylint: disable=consider-using-dict-items if self._open_sockets[k] == sock: key = k break @@ -392,8 +392,8 @@ def _close_socket(self, sock): def _free_sockets(self): free_sockets = [] - for sock in self._socket_free: - if self._socket_free[sock]: + for sock, val in self._socket_free.items(): + if val: free_sockets.append(sock) for sock in free_sockets: self._close_socket(sock) diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..88e6733 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +sphinx>=4.0.0 diff --git a/tests/mocket.py b/tests/mocket.py index 578a808..fe11cc9 100644 --- a/tests/mocket.py +++ b/tests/mocket.py @@ -54,8 +54,7 @@ def _recv_into(self, buf, nbytes=0): assert isinstance(nbytes, int) and nbytes >= 0 read = nbytes if nbytes > 0 else len(buf) remaining = len(self._response) - self._position - if read > remaining: - read = remaining + read = min(read, remaining) end = self._position + read buf[:read] = self._response[self._position : end] self._position = end