Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Added pre-commit linting as GitHub workflow (#6407)

NyanKiyoshiea9836b4ddeb
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 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.yml
index 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-test
jobs:
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@v1
with:
@@ -67,10 +75,24 @@ jobs:
path: junit/test-results.xml
if: ${{ always() }}
- - uses: NyanKiyoshi/[email protected]
+ # Publish detected differences as comment
+ - uses: NyanKiyoshi/pytest-django-queries-ci-tools@v1
with:
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.yaml
index 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.0
hooks:
- id: trailing-whitespace
exclude: ^templates/templated_email/compiled/
+ exclude_types: [svg]
- id: end-of-file-fixer
exclude: ^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.0
hooks:
- id: seed-isort-config
@@ -25,21 +31,14 @@ repos:
- id: isort
- repo: https://github.com/pycqa/pydocstyle
- rev: 4.0.0
+ rev: 5.1.1
hooks:
- id: pydocstyle
files: ^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.790
hooks:
- id: mypy
language: system
@@ -58,6 +57,6 @@ repos:
hooks:
- id: gql-schema-check
language: 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.yml
deleted file mode 100644
index 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.sh
diff --git a/saleor/account/migrations/0035_staffnotificationrecipient.py b/saleor/account/migrations/0035_staffnotificationrecipient.py
index 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.deletion
from django.conf import settings
from django.db import migrations, models
-import django.db.models.deletion
class Migration(migrations.Migration):
diff --git a/saleor/checkout/calculations.py b/saleor/checkout/calculations.py
index edc6e1602e..c3dfad67d4 100644
--- a/saleor/checkout/calculations.py
+++ b/saleor/checkout/calculations.py
@@ -7,6 +7,7 @@ from ..plugins.manager import get_plugins_manager
if TYPE_CHECKING:
from prices import TaxedMoney
+
from .models import Checkout, CheckoutLine
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index 388445394c..2ba4ba665b 100644
--- a/saleor/checkout/models.py
+++ b/saleor/checkout/models.py
@@ -22,9 +22,10 @@ from ..shipping.models import ShippingMethod
if TYPE_CHECKING:
# flake8: noqa
- from ..product.models import ProductVariant
from django_measurement import Weight
+
from ..payment.models import Payment
+ from ..product.models import ProductVariant
class CheckoutQueryset(models.QuerySet):
diff --git a/saleor/core/payments.py b/saleor/core/payments.py
index 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, CheckoutLine
from ..discount import DiscountInfo
from ..payment.interface import (
- PaymentData,
- GatewayResponse,
- TokenConfig,
CustomerSource,
+ GatewayResponse,
+ PaymentData,
PaymentGateway,
+ TokenConfig,
)
diff --git a/saleor/core/prices.py b/saleor/core/prices.py
index d189c38c50..5739efcb06 100644
--- a/saleor/core/prices.py
+++ b/saleor/core/prices.py
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Union
from babel.numbers import get_currency_precision
if TYPE_CHECKING:
- from prices import TaxedMoney, Money, TaxedMoneyRange
+ from prices import Money, TaxedMoney, TaxedMoneyRange
def quantize_price(
diff --git a/saleor/core/utils/anonymization.py b/saleor/core/utils/anonymization.py
index 5f4351c8d9..73db1dd2a1 100644
--- a/saleor/core/utils/anonymization.py
+++ b/saleor/core/utils/anonymization.py
@@ -8,8 +8,8 @@ from ...account.models import Address, User
from .random_data import create_address, create_fake_user
if TYPE_CHECKING:
- from ...order.models import Order
from ...checkout.models import Checkout
+ from ...order.models import Order
logger = logging.getLogger(__name__)
diff --git a/saleor/csv/events.py b/saleor/csv/events.py
index 69e4682f14..8e1410fa45 100644
--- a/saleor/csv/events.py
+++ b/saleor/csv/events.py
@@ -4,9 +4,9 @@ from . import ExportEvents
from .models import ExportEvent
if TYPE_CHECKING:
- from .models import ExportFile
- from ..app.models import App
from ..account.models import User
+ from ..app.models import App
+ from .models import ExportFile
UserType = Optional["User"]
diff --git a/saleor/csv/utils/export.py b/saleor/csv/utils/export.py
index 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_data
if TYPE_CHECKING:
# flake8: noqa
from django.db.models import QuerySet
+
from ..models import ExportFile
diff --git a/saleor/discount/utils.py b/saleor/discount/utils.py
index 217b81b840..300bee71b5 100644
--- a/saleor/discount/utils.py
+++ b/saleor/discount/utils.py
@@ -13,10 +13,10 @@ from .models import NotApplicable, Sale, VoucherCustomer
if TYPE_CHECKING:
# flake8: noqa
- from .models import Voucher
- from ..product.models import Collection, Product
from ..checkout.models import Checkout, CheckoutLine
from ..order.models import Order
+ from ..product.models import Collection, Product
+ from .models import Voucher
def increase_voucher_usage(voucher: "Voucher") -> None:
diff --git a/saleor/graphql/account/mutations/jwt.py b/saleor/graphql/account/mutations/jwt.py
index 19a0030ee8..1af709cf41 100644
--- a/saleor/graphql/account/mutations/jwt.py
+++ b/saleor/graphql/account/mutations/jwt.py
@@ -3,10 +3,8 @@ from typing import Optional
import graphene
import jwt
from 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_token
from django.utils import timezone
from django.utils.crypto import get_random_string
from graphene.types.generic import GenericScalar
diff --git a/saleor/graphql/account/utils.py b/saleor/graphql/account/utils.py
index 35ad5a489c..65c5cc0d52 100644
--- a/saleor/graphql/account/utils.py
+++ b/saleor/graphql/account/utils.py
@@ -15,6 +15,7 @@ from ...core.permissions import AccountPermissions
if TYPE_CHECKING:
from django.db.models import QuerySet
+
from ...account.models import User
from ...app.models import App
diff --git a/saleor/graphql/meta/resolvers.py b/saleor/graphql/meta/resolvers.py
index 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_MAP
def resolve_object_with_metadata_type(instance: ModelWithMetadata):
# Imports inside resolvers to avoid circular imports.
+ from ...invoice import models as invoice_models
from ..account import types as account_types
from ..app import types as app_types
from ..checkout import types as checkout_types
+ from ..invoice import types as invoice_types
from ..order import types as order_types
from ..page import types as page_types
from ..product import types as product_types
from ..shipping import types as shipping_types
- from ..invoice import types as invoice_types
- from ...invoice import models as invoice_models
MODEL_TO_TYPE_MAP = {
product_models.Attribute: product_types.Attribute,
diff --git a/saleor/graphql/product/utils.py b/saleor/graphql/product/utils.py
index b2366d7f2c..7411f382bb 100644
--- a/saleor/graphql/product/utils.py
+++ b/saleor/graphql/product/utils.py
@@ -12,6 +12,7 @@ from ...warehouse.models import Stock
if TYPE_CHECKING:
from django.db.models import QuerySet
+
from ...product.models import Attribute, ProductVariant
diff --git a/saleor/graphql/wishlist/resolvers.py b/saleor/graphql/wishlist/resolvers.py
index 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-import
from django.db.models.query import QuerySet
from graphene.types import ResolveInfo
+
from ...account.models import User
from ...wishlist.models import WishlistItem
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index 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 Order
from ..account.models import User
from ..payment.models import Payment
from ..warehouse.models import Warehouse
+ from .models import Order
logger = logging.getLogger(__name__)
diff --git a/saleor/order/migrations/0074_auto_20190930_0731.py b/saleor/order/migrations/0074_auto_20190930_0731.py
index 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.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/payment/gateways/braintree/plugin.py b/saleor/payment/gateways/braintree/plugin.py
index 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, TokenConfig
from ...interface import CustomerSource
+ from . import GatewayResponse, PaymentData, TokenConfig
def require_active_plugin(fn):
diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.py
index 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, PaymentData
from ...interface import CustomerSource
+ from . import GatewayResponse, PaymentData
def require_active_plugin(fn):
diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.py
index 3cc2d9ea2c..cf6e3477ae 100644
--- a/saleor/plugins/avatax/__init__.py
+++ b/saleor/plugins/avatax/__init__.py
@@ -19,7 +19,7 @@ if TYPE_CHECKING:
# flake8: noqa
from ...checkout.models import Checkout, CheckoutLine
from ...order.models import Order
- from ...product.models import Product, ProductVariant, ProductType
+ from ...product.models import Product, ProductType, ProductVariant
logger = logging.getLogger(__name__)
diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.py
index be73b65918..8949294247 100644
--- a/saleor/plugins/base_plugin.py
+++ b/saleor/plugins/base_plugin.py
@@ -17,13 +17,13 @@ from .models import PluginConfiguration
if TYPE_CHECKING:
# flake8: noqa
- from ..core.taxes import TaxType
+ from ..account.models import Address, User
from ..checkout.models import Checkout, CheckoutLine
+ from ..core.taxes import TaxType
from ..discount import DiscountInfo
- from ..product.models import Product, ProductType
- from ..account.models import Address, User
- from ..order.models import Fulfillment, OrderLine, Order
from ..invoice.models import Invoice
+ from ..order.models import Fulfillment, Order, OrderLine
+ from ..product.models import Product, ProductType
PluginConfigurationType = List[dict]
diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.py
index 171c2d617e..4b72a726fc 100644
--- a/saleor/plugins/manager.py
+++ b/saleor/plugins/manager.py
@@ -18,19 +18,19 @@ from .models import PluginConfiguration
if TYPE_CHECKING:
# flake8: noqa
- from .base_plugin import BasePlugin
- from ..checkout.models import Checkout, CheckoutLine
- from ..product.models import Product, ProductType
from ..account.models import Address, User
- from ..order.models import Fulfillment, OrderLine, Order
+ from ..checkout.models import Checkout, CheckoutLine
from ..invoice.models import Invoice
+ from ..order.models import Fulfillment, Order, OrderLine
from ..payment.interface import (
- PaymentData,
- TokenConfig,
- GatewayResponse,
CustomerSource,
+ GatewayResponse,
+ PaymentData,
PaymentGateway,
+ TokenConfig,
)
+ from ..product.models import Product, ProductType
+ from .base_plugin import BasePlugin
class PluginsManager(PaymentInterface):
diff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.py
index 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 Address
from ...checkout.models import Checkout, CheckoutLine
from ...discount import DiscountInfo
-
- from ...account.models import Address
- from ...order.models import OrderLine, Order
+ from ...order.models import Order, OrderLine
from ..models import PluginConfiguration
diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.py
index 9c78be7048..5b94ac91c6 100644
--- a/saleor/plugins/webhook/plugin.py
+++ b/saleor/plugins/webhook/plugin.py
@@ -13,11 +13,11 @@ from ..base_plugin import BasePlugin
from .tasks import trigger_webhooks_for_event
if TYPE_CHECKING:
- from ...order.models import Fulfillment, Order
from ...account.models import User
- from ...product.models import Product
from ...checkout.models import Checkout
from ...invoice.models import Invoice
+ from ...order.models import Fulfillment, Order
+ from ...product.models import Product
class WebhookPlugin(BasePlugin):
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 5c445e9419..990a7f54a1 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -37,10 +37,10 @@ from . import AttributeInputType
if TYPE_CHECKING:
# flake8: noqa
+ from django.db.models import OrderBy
from prices import Money
from ..account.models import User
- from django.db.models import OrderBy
class Category(MPTTModel, ModelWithMetadata, SeoModel):
diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.py
index 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, ProductVariant
def calculate_revenue_for_variant(
@@ -36,7 +36,7 @@ def delete_categories(categories_ids: List[str]):
Set products of deleted categories as unpublished, delete categories
and update products minimal variant prices.
"""
- from ..models import Product, Category
+ from ..models import Category, Product
categories = 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.py
index b06c118afc..dcf3e147a6 100644
--- a/saleor/product/utils/costs.py
+++ b/saleor/product/utils/costs.py
@@ -7,6 +7,7 @@ from ...core.taxes import zero_money
if TYPE_CHECKING:
from prices import Money
+
from ..models import Product, ProductVariant
diff --git a/saleor/seo/schema/email.py b/saleor/seo/schema/email.py
index 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_uri
from ...core.utils.json_serializer import HTMLSafeJSON
if TYPE_CHECKING:
- from ...order.models import OrderLine, Order
+ from ...order.models import Order, OrderLine
def get_organization():
diff --git a/saleor/urls.py b/saleor/urls.py
index 8589b4d398..179be8baff 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -27,6 +27,7 @@ urlpatterns = [
if settings.DEBUG:
import warnings
+
from .core import views
try:
diff --git a/saleor/warehouse/management.py b/saleor/warehouse/management.py
index 62cefaf426..17251620ff 100644
--- a/saleor/warehouse/management.py
+++ b/saleor/warehouse/management.py
@@ -9,7 +9,7 @@ from ..core.exceptions import AllocationError, InsufficientStock
from .models import Allocation, Stock, Warehouse
if TYPE_CHECKING:
- from ..order.models import OrderLine, Order
+ from ..order.models import Order, OrderLine
@transaction.atomic
diff --git a/templates/formatted_address.html b/templates/formatted_address.html
index 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.email
index 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.email
index 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" %}