Skip to content

Commit

Permalink
Drop Python 2 support
Browse files Browse the repository at this point in the history
This removes Py2-specific features:

* encoding declaration (Python 3 defaults to UTF-8)
* future feature imports
* u-prefixed unicode literals
* six library
  • Loading branch information
patrys committed Dec 14, 2017
1 parent 7ae13c2 commit dbbfba8
Show file tree
Hide file tree
Showing 181 changed files with 102 additions and 521 deletions.
4 changes: 1 addition & 3 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python
from __future__ import unicode_literals

#!/usr/bin/env python3
import os
import sys

Expand Down
1 change: 0 additions & 1 deletion saleor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, unicode_literals
from .celeryconf import app as celery_app

__all__ = ['celery_app']
Expand Down
2 changes: 0 additions & 2 deletions saleor/cart/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import logging

from django.utils.translation import pgettext_lazy
Expand Down
2 changes: 0 additions & 2 deletions saleor/cart/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Cart-related context processors."""
from __future__ import unicode_literals

from .utils import get_cart_from_request


Expand Down
2 changes: 0 additions & 2 deletions saleor/cart/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Cart-related forms and fields."""
from __future__ import unicode_literals

from django import forms
from django.conf import settings
from django.core.exceptions import NON_FIELD_ERRORS, ObjectDoesNotExist
Expand Down
5 changes: 1 addition & 4 deletions saleor/cart/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Cart-related ORM models."""
from __future__ import unicode_literals

from collections import namedtuple
from decimal import Decimal
from uuid import uuid4

from django.conf import settings
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.encoding import python_2_unicode_compatible, smart_str
from django.utils.encoding import smart_str
from django.utils.timezone import now
from django.utils.translation import pgettext_lazy
from django_prices.models import PriceField
Expand Down Expand Up @@ -243,7 +241,6 @@ def partition(self):
return partition(self.lines.all(), grouper, ProductGroup)


@python_2_unicode_compatible
class CartLine(models.Model, ItemLine):
"""A single cart line.
Expand Down
2 changes: 0 additions & 2 deletions saleor/cart/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf.urls import url

from . import views
Expand Down
2 changes: 0 additions & 2 deletions saleor/cart/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Cart-related utility functions."""
from __future__ import unicode_literals

from datetime import timedelta
from functools import wraps
from uuid import UUID
Expand Down
2 changes: 0 additions & 2 deletions saleor/cart/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Cart-related views."""
from __future__ import unicode_literals

from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.template.response import TemplateResponse
Expand Down
2 changes: 0 additions & 2 deletions saleor/celeryconf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import os
from celery import Celery
from django.conf import settings
Expand Down
4 changes: 1 addition & 3 deletions saleor/checkout/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Checkout session state management."""
from __future__ import unicode_literals

from datetime import date
from functools import wraps

Expand All @@ -26,7 +24,7 @@
STORAGE_SESSION_KEY = 'checkout_storage'


class Checkout(object):
class Checkout:
"""Represents a checkout session.
This object acts a temporary storage for the entire checkout session. An
Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Checkout-related forms."""
from __future__ import unicode_literals

from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import pgettext_lazy
Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf.urls import url

from . import views
Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.shortcuts import redirect
from django.template.response import TemplateResponse

Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/views/discount.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from datetime import date
from functools import wraps

Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/views/shipping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.shortcuts import redirect
from django.template.response import TemplateResponse

Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/views/summary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.contrib import messages
from django.shortcuts import redirect
from django.template.response import TemplateResponse
Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/views/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from functools import wraps

from django.core.exceptions import ValidationError
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf import settings
from django.core.checks import register, Warning

Expand Down
8 changes: 0 additions & 8 deletions saleor/core/analytics.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import uuid

import google_measurement_protocol as ga
import six
from django.conf import settings

FINGERPRINT_PARTS = [
Expand All @@ -20,10 +16,6 @@
def get_client_id(request):
parts = [request.META.get(key, '') for key in FINGERPRINT_PARTS]
name = '_'.join(parts)
# In Python2 name is unicode type
# We encode it to avoid UnicodeDecodeError in uuid package
if six.PY2:
name = name.encode('utf-8')
return uuid.uuid5(UUID_NAMESPACE, name)


Expand Down
2 changes: 0 additions & 2 deletions saleor/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import json

from django.conf import settings
Expand Down
1 change: 0 additions & 1 deletion saleor/core/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from django_filters import FilterSet


Expand Down
2 changes: 0 additions & 2 deletions saleor/core/management/commands/populatedb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.conf import settings
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import logging

from django.conf import settings
Expand Down
1 change: 0 additions & 1 deletion saleor/core/permissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from django.contrib.auth.models import Permission


Expand Down
2 changes: 0 additions & 2 deletions saleor/core/sitemaps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.contrib.sitemaps import Sitemap

from ..product.models import Category, Product
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/storages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage

Expand Down
2 changes: 0 additions & 2 deletions saleor/core/templatetags/attributes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.template import Library

from ...product.utils import get_attributes_display_map
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/templatetags/jsonld.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import json

from django.template import Library
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/templatetags/markdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

from django import template
from django.utils.safestring import mark_safe
from markdown import markdown as format_markdown
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/templatetags/materializecss.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django import forms
from django.template.loader import get_template
from django import template
Expand Down
3 changes: 1 addition & 2 deletions saleor/core/templatetags/shop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
try:
from itertools import zip_longest
except ImportError:
Expand Down Expand Up @@ -50,7 +49,7 @@ def get_sort_by_toggle(context, field):
# enable ascending sort
# new_sort_by is used to construct a link with already toggled
# sort_by value
new_sort_by = u'-%s' % field
new_sort_by = '-%s' % field
sorting_icon = static('/images/arrow_up_icon.svg')
is_active = True
else:
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/templatetags/status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.template import Library
from payments import PaymentStatus

Expand Down
2 changes: 0 additions & 2 deletions saleor/core/templatetags/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.template import Library
from saleor import __version__

Expand Down
2 changes: 0 additions & 2 deletions saleor/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf.urls import url

from . import views
Expand Down
3 changes: 0 additions & 3 deletions saleor/core/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# coding: utf-8
from __future__ import unicode_literals

import decimal
from json import JSONEncoder

Expand Down
3 changes: 0 additions & 3 deletions saleor/core/utils/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import unicode_literals


def get_sort_by_choices(filter_set):
return [(choice[0], choice[1].lower()) for choice in
filter_set.filters['sort_by'].field.choices[1::2]]
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/utils/form_renderer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from bootstrap3.renderers import FormRenderer as BaseFormRenderer


Expand Down
19 changes: 8 additions & 11 deletions saleor/core/utils/random_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import itertools
import os
import random
Expand All @@ -10,7 +8,6 @@
from django.contrib.auth.models import Group, Permission
from django.core.files import File
from django.template.defaultfilters import slugify
from django.utils.six import moves
from faker import Factory
from faker.providers import BaseProvider
from payments import PaymentStatus
Expand All @@ -19,14 +16,13 @@
from ...discount.models import Sale, Voucher
from ...order import OrderStatus
from ...order.models import DeliveryGroup, Order, OrderLine, Payment
from ...product.models import (AttributeChoiceValue, Category, Product,
ProductAttribute, ProductClass, ProductImage,
ProductVariant, Stock, StockLocation)
from ...product.models import (
AttributeChoiceValue, Category, Product, ProductAttribute, ProductClass,
ProductImage, ProductVariant, Stock, StockLocation)
from ...shipping.models import ANY_COUNTRY, ShippingMethod
from ...userprofile.models import Address, User
from ...userprofile.utils import store_user_address


fake = Factory.create()
STOCK_LOCATION = 'default'

Expand Down Expand Up @@ -188,9 +184,10 @@ def get_variant_combinations(product):
for attr
in product.product_class.variant_attributes.all()}
all_combinations = itertools.product(*variant_attr_map.values())
return [{str(attr_value.attribute.pk): str(attr_value.pk)
for attr_value in combination}
for combination in all_combinations]
return [
{str(attr_value.attribute.pk): str(attr_value.pk)
for attr_value in combination}
for combination in all_combinations]


def get_price_override(schema, combinations_num, current_price):
Expand Down Expand Up @@ -221,7 +218,7 @@ def create_products_by_class(product_class, schema,

prices = get_price_override(
schema, len(variant_combinations), product.price)
variants_with_prices = moves.zip_longest(
variants_with_prices = itertools.zip_longest(
variant_combinations, prices)

for i, variant_price in enumerate(variants_with_prices, start=1337):
Expand Down
2 changes: 0 additions & 2 deletions saleor/core/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.template.response import TemplateResponse
from django.contrib import messages
from django.utils.translation import pgettext_lazy
Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/category/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.utils.translation import pgettext_lazy
from django_filters import CharFilter, OrderingFilter

Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/category/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django import forms
from django.shortcuts import get_object_or_404
from django.utils.translation import pgettext_lazy
Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/category/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf.urls import url

from . import views
Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/category/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/customer/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django import forms
from django.db.models import Q
from django.utils.translation import pgettext_lazy
Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/customer/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf.urls import url

from . import views
Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/customer/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
Expand Down
2 changes: 0 additions & 2 deletions saleor/dashboard/discount/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django import forms
from django.db.models import Q
from django.utils.translation import pgettext_lazy
Expand Down
Loading

0 comments on commit dbbfba8

Please sign in to comment.