Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Added pre-commit linting as GitHub workflow (#6407)
NyanKiyoshiea9836b4ddeb
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.mdindex 70e5876063..016d352844 100644--- a/.github/ISSUE_TEMPLATE/bug_report.md+++ b/.github/ISSUE_TEMPLATE/bug_report.md@@ -8,8 +8,8 @@ about: Create a report to help us improve…### Steps to reproduce the problem-1.-2.+1.+2.### What I expected to happen…diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.ymlindex 6c4c4537d2..e5727ec937 100644--- a/.github/workflows/pytest.yml+++ b/.github/workflows/pytest.yml@@ -10,6 +10,8 @@ on:env:BENCH_PATH: ./queries-results.json+ DATABASE_URL: "postgres://saleor:saleor@postgres:5432/saleor"+ SECRET_KEY: ci-testjobs:build:@@ -57,9 +59,15 @@ jobs:--cov \--junitxml=junit/test-results.xml \--django-db-bench=${{ env.BENCH_PATH }}- env:- DATABASE_URL: "postgres://saleor:saleor@postgres:5432/saleor"+ - uses: actions/cache@v2+ with:+ path: ~/.cache/pre-commit+ key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}+ restore-keys: |+ ${{ runner.os }}-pre-commit-++ # Publish coverage and test results- uses: codecov/codecov-action@v1- uses: actions/upload-artifact@v1with:@@ -67,10 +75,24 @@ jobs:path: junit/test-results.xmlif: ${{ always() }}- - uses: NyanKiyoshi/[email protected]+ # Publish detected differences as comment+ - uses: NyanKiyoshi/pytest-django-queries-ci-tools@v1with:query_raw_dump_path: ${{ env.BENCH_PATH }}diff_endpoint: "https://dtab784j47g1o.cloudfront.net/default/saleor-db-queries-bot-diff"diff_results_base_url: "https://dtab784j47g1o.cloudfront.net"+ if: ${{ github.event_name == 'pull_request' }}++ # Save results for future comparison against pull requests+ - uses: NyanKiyoshi/pytest-django-queries-ci-tools@v1+ with:+ query_raw_dump_path: ${{ env.BENCH_PATH }}upload_endpoint: ${{ secrets.QUERIES_UPLOAD_ENDPOINT_URL }}upload_secret_key: ${{ secrets.QUERIES_UPLOAD_SECRET }}+ if: ${{ github.event_name == 'push' }}++ # Run linters and Django related checks+ - name: Run Linters and Checks+ run: |+ pre-commit run --all+ if: ${{ always() }}diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 38ec78940e..bf28a3cb04 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -6,16 +6,22 @@ repos:language_version: python3.8- repo: https://github.com/pre-commit/pre-commit-hooks- rev: v2.2.3+ rev: v3.3.0hooks:- id: trailing-whitespaceexclude: ^templates/templated_email/compiled/+ exclude_types: [svg]- id: end-of-file-fixerexclude: ^templates/templated_email/compiled/+ exclude_types: [svg]++ - repo: https://gitlab.com/pycqa/flake8+ rev: 3.8.4+ hooks:- id: flake8- repo: https://github.com/asottile/seed-isort-config- rev: v1.9.2+ rev: v2.2.0hooks:- id: seed-isort-config@@ -25,21 +31,14 @@ repos:- id: isort- repo: https://github.com/pycqa/pydocstyle- rev: 4.0.0+ rev: 5.1.1hooks:- id: pydocstylefiles: ^saleor/exclude: tests/- - repo: https://github.com/prettier/prettier- rev: 1.18.2- hooks:- - id: prettier- files: ^saleor/static/*.*\.js$- verbose: true-- repo: https://github.com/pre-commit/mirrors-mypy- rev: v0.761+ rev: v0.790hooks:- id: mypylanguage: system@@ -58,6 +57,6 @@ repos:hooks:- id: gql-schema-checklanguage: system- name: Check for up-to-date GraphQL schema.+ name: Check GraphQL schema is up to date.entry: sh -c "./manage.py get_graphql_schema | diff saleor/graphql/schema.graphql -"stages: [commit]diff --git a/.travis.yml b/.travis.ymldeleted file mode 100644index 94eaa072ee..0000000000--- a/.travis.yml+++ /dev/null@@ -1,67 +0,0 @@-dist: xenial-language: python-sudo: false--python:- - "3.8"--cache:- pip: true- directories:- - node_modules- - $HOME/.cache/pip--install:- - pip install -U pip setuptools wheel- - pip install tox-travis pytest-django-queries- - git clone https://github.com/NyanKiyoshi/pytest-django-queries-ci-tools.git --depth 1 ../queries-ci-tools- - >- if [ -n "$DJANGO" ]; then- cp -r templates/templated_email/compiled ./compiled;- nvm install 10;- npm i;- npm run build-emails;- DIFF=$(diff -q ./compiled templates/templated_email/compiled);- if [ "$DIFF" ]; then- echo "Precompiled emails check failure - make sure you executed: npm run build-emails.";- travis_terminate 1;- fi;- fi;--script:- - tox--env:- global:- - DATABASE_URL="postgres://postgres@localhost:5432/saleor"- - SECRET_KEY="irrelevant"- - QUERIES_RESULTS_PATH=/tmp/queries-results.json- matrix:- - DJANGO="3.1"--matrix:- fast_finish: true- include:- - env: TOXENV=black- python: "3.8"- - env: TOXENV=flake8- python: "3.8"- - env: TOXENV=mypy- python: "3.8"- - env: TOXENV=check_gql_schema- python: "3.8"- - env: TOXENV=check_migrations- python: "3.8"- - env: TOXENV=pydocstyle- python: "3.8"- - env: TOXENV=isort- python: "3.8"--services:- - postgresql--addons:- postgresql: 9.6--after_success:- - ../queries-ci-tools/handle-event.shdiff --git a/saleor/account/migrations/0035_staffnotificationrecipient.py b/saleor/account/migrations/0035_staffnotificationrecipient.pyindex 8eb9b4e294..bf2322517f 100644--- a/saleor/account/migrations/0035_staffnotificationrecipient.py+++ b/saleor/account/migrations/0035_staffnotificationrecipient.py@@ -1,8 +1,8 @@# Generated by Django 2.2.6 on 2019-11-22 10:31+import django.db.models.deletionfrom django.conf import settingsfrom django.db import migrations, models-import django.db.models.deletionclass Migration(migrations.Migration):diff --git a/saleor/checkout/calculations.py b/saleor/checkout/calculations.pyindex edc6e1602e..c3dfad67d4 100644--- a/saleor/checkout/calculations.py+++ b/saleor/checkout/calculations.py@@ -7,6 +7,7 @@ from ..plugins.manager import get_plugins_managerif TYPE_CHECKING:from prices import TaxedMoney+from .models import Checkout, CheckoutLinediff --git a/saleor/checkout/models.py b/saleor/checkout/models.pyindex 388445394c..2ba4ba665b 100644--- a/saleor/checkout/models.py+++ b/saleor/checkout/models.py@@ -22,9 +22,10 @@ from ..shipping.models import ShippingMethodif TYPE_CHECKING:# flake8: noqa- from ..product.models import ProductVariantfrom django_measurement import Weight+from ..payment.models import Payment+ from ..product.models import ProductVariantclass CheckoutQueryset(models.QuerySet):diff --git a/saleor/core/payments.py b/saleor/core/payments.pyindex 777cdcf229..8629f94332 100644--- a/saleor/core/payments.py+++ b/saleor/core/payments.py@@ -6,11 +6,11 @@ if TYPE_CHECKING:from ..checkout.models import Checkout, CheckoutLinefrom ..discount import DiscountInfofrom ..payment.interface import (- PaymentData,- GatewayResponse,- TokenConfig,CustomerSource,+ GatewayResponse,+ PaymentData,PaymentGateway,+ TokenConfig,)diff --git a/saleor/core/prices.py b/saleor/core/prices.pyindex d189c38c50..5739efcb06 100644--- a/saleor/core/prices.py+++ b/saleor/core/prices.py@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Unionfrom babel.numbers import get_currency_precisionif TYPE_CHECKING:- from prices import TaxedMoney, Money, TaxedMoneyRange+ from prices import Money, TaxedMoney, TaxedMoneyRangedef quantize_price(diff --git a/saleor/core/utils/anonymization.py b/saleor/core/utils/anonymization.pyindex 5f4351c8d9..73db1dd2a1 100644--- a/saleor/core/utils/anonymization.py+++ b/saleor/core/utils/anonymization.py@@ -8,8 +8,8 @@ from ...account.models import Address, Userfrom .random_data import create_address, create_fake_userif TYPE_CHECKING:- from ...order.models import Orderfrom ...checkout.models import Checkout+ from ...order.models import Orderlogger = logging.getLogger(__name__)diff --git a/saleor/csv/events.py b/saleor/csv/events.pyindex 69e4682f14..8e1410fa45 100644--- a/saleor/csv/events.py+++ b/saleor/csv/events.py@@ -4,9 +4,9 @@ from . import ExportEventsfrom .models import ExportEventif TYPE_CHECKING:- from .models import ExportFile- from ..app.models import Appfrom ..account.models import User+ from ..app.models import App+ from .models import ExportFileUserType = Optional["User"]diff --git a/saleor/csv/utils/export.py b/saleor/csv/utils/export.pyindex 9672fb7164..59b517d105 100644--- a/saleor/csv/utils/export.py+++ b/saleor/csv/utils/export.py@@ -12,6 +12,7 @@ from .products_data import get_export_fields_and_headers_info, get_products_dataif TYPE_CHECKING:# flake8: noqafrom django.db.models import QuerySet+from ..models import ExportFilediff --git a/saleor/discount/utils.py b/saleor/discount/utils.pyindex 217b81b840..300bee71b5 100644--- a/saleor/discount/utils.py+++ b/saleor/discount/utils.py@@ -13,10 +13,10 @@ from .models import NotApplicable, Sale, VoucherCustomerif TYPE_CHECKING:# flake8: noqa- from .models import Voucher- from ..product.models import Collection, Productfrom ..checkout.models import Checkout, CheckoutLinefrom ..order.models import Order+ from ..product.models import Collection, Product+ from .models import Voucherdef increase_voucher_usage(voucher: "Voucher") -> None:diff --git a/saleor/graphql/account/mutations/jwt.py b/saleor/graphql/account/mutations/jwt.pyindex 19a0030ee8..1af709cf41 100644--- a/saleor/graphql/account/mutations/jwt.py+++ b/saleor/graphql/account/mutations/jwt.py@@ -3,10 +3,8 @@ from typing import Optionalimport grapheneimport jwtfrom django.core.exceptions import ValidationError-from django.middleware.csrf import ( # type: ignore- _compare_masked_tokens,- _get_new_csrf_token,-)+from django.middleware.csrf import _compare_masked_tokens # type: ignore+from django.middleware.csrf import _get_new_csrf_tokenfrom django.utils import timezonefrom django.utils.crypto import get_random_stringfrom graphene.types.generic import GenericScalardiff --git a/saleor/graphql/account/utils.py b/saleor/graphql/account/utils.pyindex 35ad5a489c..65c5cc0d52 100644--- a/saleor/graphql/account/utils.py+++ b/saleor/graphql/account/utils.py@@ -15,6 +15,7 @@ from ...core.permissions import AccountPermissionsif TYPE_CHECKING:from django.db.models import QuerySet+from ...account.models import Userfrom ...app.models import Appdiff --git a/saleor/graphql/meta/resolvers.py b/saleor/graphql/meta/resolvers.pyindex 4b982d5242..9a02802347 100644--- a/saleor/graphql/meta/resolvers.py+++ b/saleor/graphql/meta/resolvers.py@@ -15,15 +15,15 @@ from .permissions import PRIVATE_META_PERMISSION_MAPdef resolve_object_with_metadata_type(instance: ModelWithMetadata):# Imports inside resolvers to avoid circular imports.+ from ...invoice import models as invoice_modelsfrom ..account import types as account_typesfrom ..app import types as app_typesfrom ..checkout import types as checkout_types+ from ..invoice import types as invoice_typesfrom ..order import types as order_typesfrom ..page import types as page_typesfrom ..product import types as product_typesfrom ..shipping import types as shipping_types- from ..invoice import types as invoice_types- from ...invoice import models as invoice_modelsMODEL_TO_TYPE_MAP = {product_models.Attribute: product_types.Attribute,diff --git a/saleor/graphql/product/utils.py b/saleor/graphql/product/utils.pyindex b2366d7f2c..7411f382bb 100644--- a/saleor/graphql/product/utils.py+++ b/saleor/graphql/product/utils.py@@ -12,6 +12,7 @@ from ...warehouse.models import Stockif TYPE_CHECKING:from django.db.models import QuerySet+from ...product.models import Attribute, ProductVariantdiff --git a/saleor/graphql/wishlist/resolvers.py b/saleor/graphql/wishlist/resolvers.pyindex c9377c9785..99c65ed2d6 100644--- a/saleor/graphql/wishlist/resolvers.py+++ b/saleor/graphql/wishlist/resolvers.py@@ -6,6 +6,7 @@ if TYPE_CHECKING:# pylint: disable=unused-importfrom django.db.models.query import QuerySetfrom graphene.types import ResolveInfo+from ...account.models import Userfrom ...wishlist.models import WishlistItemdiff --git a/saleor/order/actions.py b/saleor/order/actions.pyindex ee56ab47eb..1cad9b6232 100644--- a/saleor/order/actions.py+++ b/saleor/order/actions.py@@ -25,10 +25,10 @@ from .utils import ()if TYPE_CHECKING:- from .models import Orderfrom ..account.models import Userfrom ..payment.models import Paymentfrom ..warehouse.models import Warehouse+ from .models import Orderlogger = logging.getLogger(__name__)diff --git a/saleor/order/migrations/0074_auto_20190930_0731.py b/saleor/order/migrations/0074_auto_20190930_0731.pyindex 92caa39f82..ece4504b34 100644--- a/saleor/order/migrations/0074_auto_20190930_0731.py+++ b/saleor/order/migrations/0074_auto_20190930_0731.py@@ -2,6 +2,7 @@import django.contrib.postgres.fields.jsonbfrom django.db import migrations+import saleor.core.utils.json_serializerdiff --git a/saleor/payment/gateways/braintree/plugin.py b/saleor/payment/gateways/braintree/plugin.pyindex e35f886c97..d5103f6d8c 100644--- a/saleor/payment/gateways/braintree/plugin.py+++ b/saleor/payment/gateways/braintree/plugin.py@@ -18,8 +18,8 @@ GATEWAY_NAME = "Braintree"if TYPE_CHECKING:# flake8: noqa- from . import GatewayResponse, PaymentData, TokenConfigfrom ...interface import CustomerSource+ from . import GatewayResponse, PaymentData, TokenConfigdef require_active_plugin(fn):diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.pyindex a49bf77e63..35f4f977f6 100644--- a/saleor/payment/gateways/stripe/plugin.py+++ b/saleor/payment/gateways/stripe/plugin.py@@ -17,8 +17,8 @@ GATEWAY_NAME = "Stripe"if TYPE_CHECKING:# flake8: noqa- from . import GatewayResponse, PaymentDatafrom ...interface import CustomerSource+ from . import GatewayResponse, PaymentDatadef require_active_plugin(fn):diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.pyindex 3cc2d9ea2c..cf6e3477ae 100644--- a/saleor/plugins/avatax/__init__.py+++ b/saleor/plugins/avatax/__init__.py@@ -19,7 +19,7 @@ if TYPE_CHECKING:# flake8: noqafrom ...checkout.models import Checkout, CheckoutLinefrom ...order.models import Order- from ...product.models import Product, ProductVariant, ProductType+ from ...product.models import Product, ProductType, ProductVariantlogger = logging.getLogger(__name__)diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.pyindex be73b65918..8949294247 100644--- a/saleor/plugins/base_plugin.py+++ b/saleor/plugins/base_plugin.py@@ -17,13 +17,13 @@ from .models import PluginConfigurationif TYPE_CHECKING:# flake8: noqa- from ..core.taxes import TaxType+ from ..account.models import Address, Userfrom ..checkout.models import Checkout, CheckoutLine+ from ..core.taxes import TaxTypefrom ..discount import DiscountInfo- from ..product.models import Product, ProductType- from ..account.models import Address, User- from ..order.models import Fulfillment, OrderLine, Orderfrom ..invoice.models import Invoice+ from ..order.models import Fulfillment, Order, OrderLine+ from ..product.models import Product, ProductTypePluginConfigurationType = List[dict]diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.pyindex 171c2d617e..4b72a726fc 100644--- a/saleor/plugins/manager.py+++ b/saleor/plugins/manager.py@@ -18,19 +18,19 @@ from .models import PluginConfigurationif TYPE_CHECKING:# flake8: noqa- from .base_plugin import BasePlugin- from ..checkout.models import Checkout, CheckoutLine- from ..product.models import Product, ProductTypefrom ..account.models import Address, User- from ..order.models import Fulfillment, OrderLine, Order+ from ..checkout.models import Checkout, CheckoutLinefrom ..invoice.models import Invoice+ from ..order.models import Fulfillment, Order, OrderLinefrom ..payment.interface import (- PaymentData,- TokenConfig,- GatewayResponse,CustomerSource,+ GatewayResponse,+ PaymentData,PaymentGateway,+ TokenConfig,)+ from ..product.models import Product, ProductType+ from .base_plugin import BasePluginclass PluginsManager(PaymentInterface):diff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.pyindex 61a8f8e476..66281715aa 100644--- a/saleor/plugins/vatlayer/plugin.py+++ b/saleor/plugins/vatlayer/plugin.py@@ -27,11 +27,10 @@ from . import (if TYPE_CHECKING:# flake8: noqa+ from ...account.models import Addressfrom ...checkout.models import Checkout, CheckoutLinefrom ...discount import DiscountInfo-- from ...account.models import Address- from ...order.models import OrderLine, Order+ from ...order.models import Order, OrderLinefrom ..models import PluginConfigurationdiff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.pyindex 9c78be7048..5b94ac91c6 100644--- a/saleor/plugins/webhook/plugin.py+++ b/saleor/plugins/webhook/plugin.py@@ -13,11 +13,11 @@ from ..base_plugin import BasePluginfrom .tasks import trigger_webhooks_for_eventif TYPE_CHECKING:- from ...order.models import Fulfillment, Orderfrom ...account.models import User- from ...product.models import Productfrom ...checkout.models import Checkoutfrom ...invoice.models import Invoice+ from ...order.models import Fulfillment, Order+ from ...product.models import Productclass WebhookPlugin(BasePlugin):diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 5c445e9419..990a7f54a1 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -37,10 +37,10 @@ from . import AttributeInputTypeif TYPE_CHECKING:# flake8: noqa+ from django.db.models import OrderByfrom prices import Moneyfrom ..account.models import User- from django.db.models import OrderByclass Category(MPTTModel, ModelWithMetadata, SeoModel):diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.pyindex dbe1707c95..42e81b691c 100644--- a/saleor/product/utils/__init__.py+++ b/saleor/product/utils/__init__.py@@ -13,7 +13,7 @@ if TYPE_CHECKING:from django.db.models.query import QuerySet- from ..models import Product, ProductVariant, Category+ from ..models import Category, Product, ProductVariantdef calculate_revenue_for_variant(@@ -36,7 +36,7 @@ def delete_categories(categories_ids: List[str]):Set products of deleted categories as unpublished, delete categoriesand update products minimal variant prices."""- from ..models import Product, Category+ from ..models import Category, Productcategories = Category.objects.select_for_update().filter(pk__in=categories_ids)categories.prefetch_related("products")diff --git a/saleor/product/utils/costs.py b/saleor/product/utils/costs.pyindex b06c118afc..dcf3e147a6 100644--- a/saleor/product/utils/costs.py+++ b/saleor/product/utils/costs.py@@ -7,6 +7,7 @@ from ...core.taxes import zero_moneyif TYPE_CHECKING:from prices import Money+from ..models import Product, ProductVariantdiff --git a/saleor/seo/schema/email.py b/saleor/seo/schema/email.pyindex 49add1f945..4d4771170c 100644--- a/saleor/seo/schema/email.py+++ b/saleor/seo/schema/email.py@@ -7,7 +7,7 @@ from ...core.utils import build_absolute_urifrom ...core.utils.json_serializer import HTMLSafeJSONif TYPE_CHECKING:- from ...order.models import OrderLine, Order+ from ...order.models import Order, OrderLinedef get_organization():diff --git a/saleor/urls.py b/saleor/urls.pyindex 8589b4d398..179be8baff 100644--- a/saleor/urls.py+++ b/saleor/urls.py@@ -27,6 +27,7 @@ urlpatterns = [if settings.DEBUG:import warnings+from .core import viewstry:diff --git a/saleor/warehouse/management.py b/saleor/warehouse/management.pyindex 62cefaf426..17251620ff 100644--- a/saleor/warehouse/management.py+++ b/saleor/warehouse/management.py@@ -9,7 +9,7 @@ from ..core.exceptions import AllocationError, InsufficientStockfrom .models import Allocation, Stock, Warehouseif TYPE_CHECKING:- from ..order.models import OrderLine, Order+ from ..order.models import Order, OrderLine@transaction.atomicdiff --git a/templates/formatted_address.html b/templates/formatted_address.htmlindex 30d7d060a4..ec17567f22 100644--- a/templates/formatted_address.html+++ b/templates/formatted_address.html@@ -1,3 +1,3 @@<address class="formatted-address{% if inline %} inline-address{% endif %}">{% if inline %}{{ address_lines|join:', ' }}{% else %}{{ address_lines|join:'<br>' }}{% endif %}-</address>\ No newline at end of file+</address>diff --git a/templates/templated_email/shared/_footer.email b/templates/templated_email/shared/_footer.emailindex 71d1b51d2e..bb511bb422 100644--- a/templates/templated_email/shared/_footer.email+++ b/templates/templated_email/shared/_footer.email@@ -4,4 +4,4 @@ This is an automatically generated e-mail, please do not reply.{% endblocktrans %}{% blocktrans trimmed context "Base email footer" %}Sincerely, {{ site_name }}-{% endblocktrans %}\ No newline at end of file+{% endblocktrans %}diff --git a/templates/templated_email/shared/_header.email b/templates/templated_email/shared/_header.emailindex 6b27723796..861e82463e 100644--- a/templates/templated_email/shared/_header.email+++ b/templates/templated_email/shared/_header.email@@ -1,2 +1,2 @@{% load i18n %}-{% trans "Hi!" context "Standard e-mail greeting" %}\ No newline at end of file+{% trans "Hi!" context "Standard e-mail greeting" %}