From a10114e1b9203816b767bb0cfa14924f57745f4e Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 23 Sep 2021 17:52:55 -0400 Subject: [PATCH 1/8] Globally disabled consider-using-f-string pylint check Signed-off-by: dherrada --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples 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 $example; done)'] + 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 From 3263d95a78c8b4af4b4012ef85a1d41e77c45461 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Oct 2021 10:56:00 -0500 Subject: [PATCH 2/8] add docs link to readme --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index c951275..b22034b 100644 --- a/README.rst +++ b/README.rst @@ -166,6 +166,11 @@ This example demonstrates a simple web server that allows setting the Neopixel c eth.maintain_dhcp_lease() # Could do any other background tasks here, like reading sensors +Documentation +============= + +API documentation for this library can be found on `Read the Docs `_. + Contributing ============ From 3481b9ade5099b04882081f94a92eb6f13127bbc Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Nov 2021 14:40:16 -0400 Subject: [PATCH 3/8] PATCH Pylint and readthedocs patch test Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- .pre-commit-config.yaml | 26 +++++++++++++++++--------- .pylintrc | 2 +- .readthedocs.yml | 2 +- docs/requirements.txt | 5 +++++ 5 files changed, 26 insertions(+), 13 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 8810708..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,17 +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] - exclude: "^(docs/|examples/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) + args: + - --disable=consider-using-f-string + exclude: "^(docs/|examples/|tests/|setup.py$)" + - 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 + 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 + types: [python] + files: "^tests/" + args: + - --disable=missing-docstring,consider-using-f-string,duplicate-code diff --git a/.pylintrc b/.pylintrc index 0238b90..e78bad2 100644 --- 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/.readthedocs.yml b/.readthedocs.yml index ffa84c4..49dcab3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -4,4 +4,4 @@ python: version: 3 -requirements_file: requirements.txt +requirements_file: docs/requirements.txt 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 From 68bcd55383e08e409e43f8efaf0b43f47128193d Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 5 Nov 2021 14:49:30 -0400 Subject: [PATCH 4/8] Disabled unspecified-encoding pylint check Signed-off-by: dherrada --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index e78bad2..cfd1c41 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From 58c68071066d54f1321b02b12b3f8881a5667929 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 8 Nov 2021 13:00:29 -0500 Subject: [PATCH 5/8] Linted --- adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py | 21 ++++++++-------- examples/wiznet5k_wsgiserver_test.py | 27 ++++++++++----------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py b/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py index b5768fb..e5c79ef 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py @@ -192,8 +192,8 @@ def send_dhcp_message(self, state, time_elapsed, renew=False): # HW Type - ETH _BUFF[245] = 0x01 # Client MAC Address - for mac in range(0, len(self._mac_address)): - _BUFF[246 + mac] = self._mac_address[mac] + for mac, val in enumerate(self._mac_address): + _BUFF[246 + mac] = val # Option - Host Name _BUFF[252] = 12 @@ -471,9 +471,13 @@ def _dhcp_state_machine(self): print("* DHCP: Time to renew lease") if ( - self._dhcp_state == STATE_DHCP_DISCOVER - or self._dhcp_state == STATE_DHCP_REQUEST - ) and time.monotonic() > (self._start_time + self._response_timeout): + self._dhcp_state + in ( + STATE_DHCP_DISCOVER, + STATE_DHCP_REQUEST, + ) + and time.monotonic() > (self._start_time + self._response_timeout) + ): self._dhcp_state = STATE_DHCP_WAIT if self._sock is not None: self._sock.close() @@ -481,13 +485,10 @@ def _dhcp_state_machine(self): def request_dhcp_lease(self): """Request to renew or acquire a DHCP lease.""" - if self._dhcp_state == STATE_DHCP_LEASED or self._dhcp_state == STATE_DHCP_WAIT: + if self._dhcp_state in (STATE_DHCP_LEASED, STATE_DHCP_WAIT): self._dhcp_state = STATE_DHCP_START - while ( - self._dhcp_state != STATE_DHCP_LEASED - and self._dhcp_state != STATE_DHCP_WAIT - ): + while self._dhcp_state not in (STATE_DHCP_LEASED, STATE_DHCP_WAIT): self._dhcp_state_machine() return self._dhcp_state == STATE_DHCP_LEASED diff --git a/examples/wiznet5k_wsgiserver_test.py b/examples/wiznet5k_wsgiserver_test.py index a0ba423..5cf31ba 100644 --- a/examples/wiznet5k_wsgiserver_test.py +++ b/examples/wiznet5k_wsgiserver_test.py @@ -20,36 +20,35 @@ import busio import digitalio import neopixel -import time import adafruit_requests as requests +from adafruit_wsgi.wsgi_app import WSGIApp from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket import adafruit_wiznet5k.adafruit_wiznet5k_wsgiserver as server -from adafruit_wsgi.wsgi_app import WSGIApp print("Wiznet5k Web Server Test") -def get_mac(i2c): +def get_mac(i2c_obj): "Read MAC from 24AA02E48 chip and return it" - mac = bytearray(6) - while not i2c.try_lock(): + mac_addr = bytearray(6) + while not i2c_obj.try_lock(): pass - i2c.writeto(0x50, bytearray((0xFA,))) - i2c.readfrom_into(0x50, mac, start=0, end=6) - i2c.unlock() - return mac + i2c_obj.writeto(0x50, bytearray((0xFA,))) + i2c_obj.readfrom_into(0x50, mac_addr, start=0, end=6) + i2c_obj.unlock() + return mac_addr def get_static_file(filename): "Static file generator" with open(filename, "rb") as f: - bytes = None - while bytes is None or len(bytes) == 2048: - bytes = f.read(2048) - yield bytes + b = None + while b is None or len(b) == 2048: + b = f.read(2048) + yield b # Status LED @@ -113,7 +112,7 @@ def large(request): # pylint: disable=unused-argument @web_app.route("/btc") -def btc(request): +def btc(request): # pylint: disable=unused-argument print("BTC handler") r = requests.get("http://api.coindesk.com/v1/bpi/currentprice/USD.json") result = r.text From 42e8a4c6426a2ceeacc1a908d90392504a348106 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 12:40:32 -0500 Subject: [PATCH 6/8] Renamed function --- examples/wiznet5k_wsgiserver_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wiznet5k_wsgiserver_test.py b/examples/wiznet5k_wsgiserver_test.py index 5cf31ba..3d1c604 100644 --- a/examples/wiznet5k_wsgiserver_test.py +++ b/examples/wiznet5k_wsgiserver_test.py @@ -106,7 +106,7 @@ def large(request): # pylint: disable=unused-argument @web_app.route("/code") -def large(request): # pylint: disable=unused-argument +def code(request): # pylint: disable=unused-argument print("Static file code.py handler") return ("200 OK", [], get_static_file("code.py")) From fdafe3ba1572f726ae8a08458fadb9680690da93 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 7/8] Updated readthedocs file Signed-off-by: dherrada --- .readthedocs.yaml | 15 +++++++++++++++ .readthedocs.yml | 7 ------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .readthedocs.yaml delete mode 100644 .readthedocs.yml diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..95ec218 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +python: + version: "3.6" + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 49dcab3..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -python: - version: 3 -requirements_file: docs/requirements.txt From 0444cb75e1a1b920ab63752add1a149d670b0966 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:11:11 -0600 Subject: [PATCH 8/8] update rtd py version --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 95ec218..1335112 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt