From 6d6ab9a53193b20ba3f2e6d8691fc50f287616d0 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 5 Jun 2022 14:38:03 -0700 Subject: [PATCH 1/3] Add .pylintrc with fixes for new pylint version --- .pylintrc | 6 ++++++ bookwyrm/tests/connectors/test_openlibrary_connector.py | 2 +- bookwyrm/tests/models/test_import_model.py | 2 +- bookwyrm/tests/views/test_status.py | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 000000000..7f92d0168 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,6 @@ +[MAIN] +ignore=migrations +load-plugins=pylint.extensions.no_self_use + +[MESSAGES CONTROL] +disable=E1101,E1135,E1136,R0903,R0901,R0902,W0707,W0511,W0406,R0401,R0801,C3001 diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index c05eb1a94..8f81b2073 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -229,7 +229,7 @@ class Openlibrary(TestCase): status=200, ) with patch( - "bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data" + "bookwyrm.connectors.openlibrary.Connector.get_authors_from_data" ) as mock: mock.return_value = [] result = self.connector.create_edition_from_data(work, self.edition_data) diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index 7cecfe416..d1ff209f4 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -195,7 +195,7 @@ class ImportJob(TestCase): ) as search: search.return_value = result with patch( - "bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data" + "bookwyrm.connectors.openlibrary.Connector.get_authors_from_data" ): book = item.get_book_from_identifier() diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 355071573..0026c52b5 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -281,7 +281,7 @@ http://www.fish.com/""" result = views.status.to_markdown(text) self.assertEqual( result, - '

hi and fish.com ' "is rad

", + '

hi and fish.com is rad

', ) def test_to_markdown_detect_url(self, *_): @@ -297,7 +297,7 @@ http://www.fish.com/""" """this is mostly handled in other places, but nonetheless""" text = "[hi](http://fish.com) is rad" result = views.status.to_markdown(text) - self.assertEqual(result, '

hi ' "is rad

") + self.assertEqual(result, '

hi is rad

') def test_delete_status(self, mock, *_): """marks a status as deleted""" From b3603c04c54d67eb9e8d81737fc940c476d0101b Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 5 Jun 2022 14:49:21 -0700 Subject: [PATCH 2/3] Add pylint to bw-dev Because pylint requires the app to be fully parseable with all its dependencies, we run it in the web container, and add pylint as a dev dependency. --- Dockerfile | 6 +++++- bw-dev | 5 +++++ requirements.dev.txt | 7 +++++++ requirements.txt | 8 -------- 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 requirements.dev.txt diff --git a/Dockerfile b/Dockerfile index 349dd82b1..99a25768b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,10 @@ RUN mkdir /app /app/static /app/images WORKDIR /app +RUN apt-get update && apt-get install -y gettext libgettextpo-dev tidy && apt-get clean + COPY requirements.txt /app/ RUN pip install -r requirements.txt --no-cache-dir -RUN apt-get update && apt-get install -y gettext libgettextpo-dev tidy && apt-get clean + +COPY requirements.dev.txt /app/ +RUN pip install -r requirements.dev.txt --no-cache-dir diff --git a/bw-dev b/bw-dev index 058f2639b..4dd543c0a 100755 --- a/bw-dev +++ b/bw-dev @@ -140,6 +140,10 @@ case "$CMD" in black) docker-compose run --rm dev-tools black celerywyrm bookwyrm ;; + pylint) + # pylint depends on having the app dependencies in place, so we run it in the web container + runweb pylint bookwyrm/ + ;; prettier) docker-compose run --rm dev-tools npx prettier --write bookwyrm/static/js/*.js ;; @@ -149,6 +153,7 @@ case "$CMD" in --config dev-tools/.stylelintrc.js ;; formatters) + runweb pylint bookwyrm/ docker-compose run --rm dev-tools black celerywyrm bookwyrm docker-compose run --rm dev-tools npx prettier --write bookwyrm/static/js/*.js docker-compose run --rm dev-tools npx stylelint \ diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 000000000..d731ca92e --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1,7 @@ +pytest-django==4.1.0 +pytest==6.1.2 +pytest-cov==2.10.1 +pytest-env==0.6.2 +pytest-xdist==2.3.0 +pytidylib==0.3.2 +pylint==2.14.0 diff --git a/requirements.txt b/requirements.txt index 7614dc421..f1ece86db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,11 +26,3 @@ opentelemetry-sdk==1.8.0 opentelemetry-exporter-otlp-proto-grpc==1.8.0 opentelemetry-instrumentation-django==0.27b0 opentelemetry-instrumentation-celery==0.27b0 - -# Dev -pytest-django==4.1.0 -pytest==6.1.2 -pytest-cov==2.10.1 -pytest-env==0.6.2 -pytest-xdist==2.3.0 -pytidylib==0.3.2 From 6584cb640453c8de5a6849e19e25756c263dcd73 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 5 Jun 2022 14:56:47 -0700 Subject: [PATCH 3/3] Go back to one requirements.txt, simplify workflow The workflow can now use .pylintrc and the pylint req in requirements.txt rather than having the options inline and installing it separately --- .github/workflows/pylint.yml | 3 +-- Dockerfile | 3 --- requirements.dev.txt | 7 ------- requirements.txt | 9 +++++++++ 4 files changed, 10 insertions(+), 12 deletions(-) delete mode 100644 requirements.dev.txt diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 08661e9c2..a3117f7cb 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -21,8 +21,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install pylint - name: Analysing the code with pylint run: | - pylint bookwyrm/ --ignore=migrations --disable=E1101,E1135,E1136,R0903,R0901,R0902,W0707,W0511,W0406,R0401,R0801 + pylint bookwyrm/ diff --git a/Dockerfile b/Dockerfile index 99a25768b..b3cd26e88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,3 @@ RUN apt-get update && apt-get install -y gettext libgettextpo-dev tidy && apt-ge COPY requirements.txt /app/ RUN pip install -r requirements.txt --no-cache-dir - -COPY requirements.dev.txt /app/ -RUN pip install -r requirements.dev.txt --no-cache-dir diff --git a/requirements.dev.txt b/requirements.dev.txt deleted file mode 100644 index d731ca92e..000000000 --- a/requirements.dev.txt +++ /dev/null @@ -1,7 +0,0 @@ -pytest-django==4.1.0 -pytest==6.1.2 -pytest-cov==2.10.1 -pytest-env==0.6.2 -pytest-xdist==2.3.0 -pytidylib==0.3.2 -pylint==2.14.0 diff --git a/requirements.txt b/requirements.txt index f1ece86db..96d98707c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,3 +26,12 @@ opentelemetry-sdk==1.8.0 opentelemetry-exporter-otlp-proto-grpc==1.8.0 opentelemetry-instrumentation-django==0.27b0 opentelemetry-instrumentation-celery==0.27b0 + +# Dev +pytest-django==4.1.0 +pytest==6.1.2 +pytest-cov==2.10.1 +pytest-env==0.6.2 +pytest-xdist==2.3.0 +pytidylib==0.3.2 +pylint==2.14.0