From b9a34003c1a0e4d286db2da026ad56131f86756e Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 1 Sep 2025 19:56:16 -0500 Subject: [PATCH] fix: address all warnings from pylint --- .pylintrc | 4 +++ docs/index.rst | 3 ++ pyproject.toml | 2 +- src/sideshow_corepos/batch/neworder.py | 40 +++++++++++++++++--------- src/sideshow_corepos/config.py | 2 +- src/sideshow_corepos/web/__init__.py | 2 +- src/sideshow_corepos/web/app.py | 2 +- src/sideshow_corepos/web/views.py | 2 +- tox.ini | 4 +++ 9 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..7eb5e2c --- /dev/null +++ b/.pylintrc @@ -0,0 +1,4 @@ +# -*- mode: conf; -*- + +[MESSAGES CONTROL] +disable=fixme diff --git a/docs/index.rst b/docs/index.rst index 202fa79..a68c7a1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,6 +8,9 @@ This is `Sideshow`_ with integration for `CORE-POS`_. .. _CORE-POS: https://www.core-pos.com/ +.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen + :target: https://github.com/pylint-dev/pylint + .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black diff --git a/pyproject.toml b/pyproject.toml index 9b1b077..0f1258a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ dependencies = [ [project.optional-dependencies] docs = ["Sphinx", "furo"] -tests = ["pytest-cov", "tox"] +tests = ["pylint", "pytest", "pytest-cov", "tox"] [project.entry-points."paste.app_factory"] diff --git a/src/sideshow_corepos/batch/neworder.py b/src/sideshow_corepos/batch/neworder.py index 6e24c66..831f056 100644 --- a/src/sideshow_corepos/batch/neworder.py +++ b/src/sideshow_corepos/batch/neworder.py @@ -43,7 +43,9 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): for more info. """ - def autocomplete_customers_external(self, session, term, user=None): + def autocomplete_customers_external( # pylint: disable=empty-docstring + self, session, term, user=None + ): """ """ corepos = self.app.get_corepos_handler() op_model = corepos.get_model_office_op() @@ -84,7 +86,9 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): op_session.close() return results - def refresh_batch_from_external_customer(self, batch): + def refresh_batch_from_external_customer( # pylint: disable=empty-docstring + self, batch + ): """ """ corepos = self.app.get_corepos_handler() op_model = corepos.get_model_office_op() @@ -108,8 +112,8 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): .options(orm.joinedload(op_model.CustomerClassic.member_info)) .one() ) - except orm.exc.NoResultFound: - raise ValueError(f"CORE-POS Customer not found: {batch.customer_id}") + except orm.exc.NoResultFound as e: + raise ValueError(f"CORE-POS Customer not found: {batch.customer_id}") from e batch.customer_name = str(customer) batch.phone_number = customer.member_info.phone @@ -117,7 +121,9 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): op_session.close() - def autocomplete_products_external(self, session, term, user=None): + def autocomplete_products_external( # pylint: disable=empty-docstring + self, session, term, user=None + ): """ """ corepos = self.app.get_corepos_handler() op_model = corepos.get_model_office_op() @@ -158,7 +164,9 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): op_session.close() return results - def get_product_info_external(self, session, product_id, user=None): + def get_product_info_external( # pylint: disable=empty-docstring + self, session, product_id, user=None + ): """ """ corepos = self.app.get_corepos_handler() op_model = corepos.get_model_office_op() @@ -170,8 +178,8 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): .filter(op_model.Product.upc == product_id) .one() ) - except orm.exc.NoResultFound: - raise ValueError(f"CORE-POS Product not found: {product_id}") + except orm.exc.NoResultFound as e: + raise ValueError(f"CORE-POS Product not found: {product_id}") from e data = { "product_id": product.upc, @@ -196,7 +204,7 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): op_session.close() return data - def refresh_row_from_external_product(self, row): + def refresh_row_from_external_product(self, row): # pylint: disable=empty-docstring """ """ corepos = self.app.get_corepos_handler() op_model = corepos.get_model_office_op() @@ -208,8 +216,8 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): .filter(op_model.Product.upc == row.product_id) .one() ) - except orm.exc.NoResultFound: - raise ValueError(f"CORE-POS Product not found: {row.product_id}") + except orm.exc.NoResultFound as e: + raise ValueError(f"CORE-POS Product not found: {row.product_id}") from e row.product_scancode = product.upc row.product_brand = product.brand @@ -233,14 +241,20 @@ class NewOrderBatchHandler(base.NewOrderBatchHandler): op_session.close() - def get_case_size_for_external_product(self, product): + def get_case_size_for_external_product( # pylint: disable=empty-docstring + self, product + ): """ """ if product.vendor_items: item = product.vendor_items[0] if item.units is not None: return decimal.Decimal(f"{item.units:0.4f}") + return None - def get_unit_price_reg_for_external_product(self, product): + def get_unit_price_reg_for_external_product( # pylint: disable=empty-docstring + self, product + ): """ """ if product.normal_price is not None: return decimal.Decimal(f"{product.normal_price:0.3f}") + return None diff --git a/src/sideshow_corepos/config.py b/src/sideshow_corepos/config.py index ceaa142..131bd54 100644 --- a/src/sideshow_corepos/config.py +++ b/src/sideshow_corepos/config.py @@ -36,7 +36,7 @@ class SideshowCoreposConfig(WuttaConfigExtension): key = "sideshow_corepos" - def configure(self, config): + def configure(self, config): # pylint: disable=empty-docstring """ """ # batch handlers diff --git a/src/sideshow_corepos/web/__init__.py b/src/sideshow_corepos/web/__init__.py index dd14f99..b192370 100644 --- a/src/sideshow_corepos/web/__init__.py +++ b/src/sideshow_corepos/web/__init__.py @@ -25,5 +25,5 @@ Sideshow-COREPOS - Case/Special Order Tracker for CORE-POS """ -def includeme(config): +def includeme(config): # pylint: disable=missing-function-docstring config.include("sideshow_corepos.web.views") diff --git a/src/sideshow_corepos/web/app.py b/src/sideshow_corepos/web/app.py index 06d01f9..f8f3f04 100644 --- a/src/sideshow_corepos/web/app.py +++ b/src/sideshow_corepos/web/app.py @@ -29,7 +29,7 @@ from wuttaweb import app as base from wutta_corepos.web.db import CoreOpSession -def main(global_config, **settings): +def main(global_config, **settings): # pylint: disable=unused-argument """ Make and return the WSGI app (Paste entry point). """ diff --git a/src/sideshow_corepos/web/views.py b/src/sideshow_corepos/web/views.py index d679b66..62de898 100644 --- a/src/sideshow_corepos/web/views.py +++ b/src/sideshow_corepos/web/views.py @@ -27,7 +27,7 @@ This adds config for readonly views for CORE-POS members and products. """ -def includeme(config): +def includeme(config): # pylint: disable=missing-function-docstring # CORE-POS views config.include("wutta_corepos.web.views.corepos.members") diff --git a/tox.ini b/tox.ini index f278fdb..c2d6be9 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,10 @@ envlist = py38, py39, py310, py311 extras = tests commands = pytest {posargs} +[testenv:pylint] +basepython = python3.11 +commands = pylint sideshow_corepos + [testenv:coverage] basepython = python3.11 commands = pytest --cov=sideshow_corepos --cov-report=html --cov-fail-under=100