From 893ffaf17c6d96d5daf5847afe2451086aeb556a Mon Sep 17 00:00:00 2001 From: M1ha Date: Tue, 6 Jul 2021 10:19:12 +0500 Subject: [PATCH] 1. Removed six dependency 2. pytz and typing are installed for old python versions only 3. psycopg2-bynary is installed in test environment instead of psycopg2 --- docs/basic_information.md | 5 ++--- requirements-test.txt | 14 +++++++------- requirements.txt | 9 ++++----- setup.py | 2 +- src/django_clickhouse/clickhouse_models.py | 3 +-- src/django_clickhouse/database.py | 1 - src/django_clickhouse/models.py | 3 +-- src/django_clickhouse/routers.py | 3 +-- src/django_clickhouse/storages.py | 3 +-- src/django_clickhouse/utils.py | 3 +-- tests/test_utils.py | 3 +-- 11 files changed, 20 insertions(+), 29 deletions(-) diff --git a/docs/basic_information.md b/docs/basic_information.md index 1363342..4547b1a 100644 --- a/docs/basic_information.md +++ b/docs/basic_information.md @@ -16,9 +16,8 @@ It is based on [infi.clickhouse-orm](https://github.com/Infinidat/infi.clickhous * [Django](https://docs.djangoproject.com/) 1.7+ * [Yandex ClickHouse](https://clickhouse.yandex/) * [infi.clickhouse-orm](https://github.com/Infinidat/infi.clickhouse_orm) -* [pytz](https://pypi.org/project/pytz/) -* [six](https://pypi.org/project/six/) -* [typing](https://pypi.org/project/typing/) +* [pytz](https://pypi.org/project/pytz/) for python before 3.3 +* [typing](https://pypi.org/project/typing/) for python before 3.5 * [psycopg2](https://www.psycopg.org/) * [celery](http://www.celeryproject.org/) * [statsd](https://pypi.org/project/statsd/) diff --git a/requirements-test.txt b/requirements-test.txt index e4635ac..cf60e8d 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,11 +1,11 @@ -Django (>=1.7) -pytz -six -typing -psycopg2 -infi.clickhouse-orm celery +Django (>=1.7) +infi.clickhouse-orm +pytz; python_version < '3.3' statsd +typing; python_version < '3.5' + +psycopg2-binary django-pg-returning django-pg-bulk-update -redis \ No newline at end of file +redis diff --git a/requirements.txt b/requirements.txt index fffdef8..b230716 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ -Django (>=1.7) -pytz -six -typing; python_version < "3.5" -infi.clickhouse-orm celery +Django (>=1.7) +infi.clickhouse-orm +pytz; python_version < '3.3' statsd +typing; python_version < '3.5' diff --git a/setup.py b/setup.py index bad7ac8..1ca5fc3 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ with open('requirements.txt') as f: setup( name='django-clickhouse', - version='1.0.3', + version='1.0.4', packages=['django_clickhouse'], package_dir={'': 'src'}, url='https://github.com/carrotquest/django-clickhouse', diff --git a/src/django_clickhouse/clickhouse_models.py b/src/django_clickhouse/clickhouse_models.py index ed2d7fa..b4817f5 100644 --- a/src/django_clickhouse/clickhouse_models.py +++ b/src/django_clickhouse/clickhouse_models.py @@ -11,7 +11,6 @@ from typing import List, Tuple, Iterable, Set, Any, Optional from django.db.models import Model as DjangoModel, QuerySet as DjangoQuerySet from infi.clickhouse_orm.engines import CollapsingMergeTree from infi.clickhouse_orm.models import Model as InfiModel, ModelBase as InfiModelBase -from six import with_metaclass from statsd.defaults.django import statsd from .compatibility import namedtuple @@ -41,7 +40,7 @@ class ClickHouseModelMeta(InfiModelBase): return res -class ClickHouseModel(with_metaclass(ClickHouseModelMeta, InfiModel)): +class ClickHouseModel(InfiModel, metaclass=ClickHouseModelMeta): """ Base model for all other models """ diff --git a/src/django_clickhouse/database.py b/src/django_clickhouse/database.py index 516d533..2668015 100644 --- a/src/django_clickhouse/database.py +++ b/src/django_clickhouse/database.py @@ -3,7 +3,6 @@ from typing import Generator, Optional, Type, Iterable from infi.clickhouse_orm.database import Database as InfiDatabase, DatabaseException from infi.clickhouse_orm.utils import parse_tsv -from six import next from io import BytesIO from statsd.defaults.django import statsd diff --git a/src/django_clickhouse/models.py b/src/django_clickhouse/models.py index 7342719..e7a5ec1 100644 --- a/src/django_clickhouse/models.py +++ b/src/django_clickhouse/models.py @@ -5,7 +5,6 @@ It saves all operations to storage in order to write them to ClickHouse later. from typing import Optional, Any, Type, Set -import six from django.db import transaction from django.db.models import QuerySet as DjangoQuerySet, Model as DjangoModel, Manager as DjangoManager from django.db.models.manager import BaseManager @@ -64,7 +63,7 @@ class ClickHouseSyncBulkUpdateQuerySetMixin(ClickHouseSyncRegisterMixin, BulkUpd pk_name = self.model._meta.pk.name if returning is None: returning = pk_name - elif isinstance(returning, six.string_types): + elif isinstance(returning, str): returning = [pk_name, returning] else: returning = list(returning) + [pk_name] diff --git a/src/django_clickhouse/routers.py b/src/django_clickhouse/routers.py index 9fcfe54..ddb4348 100644 --- a/src/django_clickhouse/routers.py +++ b/src/django_clickhouse/routers.py @@ -4,7 +4,6 @@ This file defines router to find appropriate database from typing import Type import random -import six from infi.clickhouse_orm.migrations import Operation, DropTable, CreateTable from .clickhouse_models import ClickHouseModel @@ -47,7 +46,7 @@ class DefaultRouter: if hints.get('model'): model = '%s.%s.%s' % (app_label, config.MODELS_MODULE, hints['model']) \ - if isinstance(hints['model'], six.string_types) else hints['model'] + if isinstance(hints['model'], str) else hints['model'] model = lazy_class_import(model) diff --git a/src/django_clickhouse/storages.py b/src/django_clickhouse/storages.py index 43d972b..cf2ba4f 100644 --- a/src/django_clickhouse/storages.py +++ b/src/django_clickhouse/storages.py @@ -11,7 +11,6 @@ import logging from typing import Any, Optional, List, Tuple import os -from six import with_metaclass from statsd.defaults.django import statsd from .configuration import config @@ -152,7 +151,7 @@ class Storage: raise NotImplemented() -class RedisStorage(with_metaclass(SingletonMeta, Storage)): +class RedisStorage(Storage, metaclass=SingletonMeta): """ Fast in-memory storage made on bases of redis and redis-py library. Requires: diff --git a/src/django_clickhouse/utils.py b/src/django_clickhouse/utils.py index 6e38fcc..a580d0d 100644 --- a/src/django_clickhouse/utils.py +++ b/src/django_clickhouse/utils.py @@ -7,7 +7,6 @@ from itertools import chain from typing import Union, Any, Optional, TypeVar, Set, Dict, Iterable, Tuple, Iterator, Callable, List import pytz -import six from importlib import import_module from importlib.util import find_spec from django.db.models import Model as DjangoModel @@ -76,7 +75,7 @@ def lazy_class_import(obj: Union[str, Any]) -> Any: :param obj: A string class path or object to return :return: Imported object """ - if isinstance(obj, six.string_types): + if isinstance(obj, str): module_name, obj_name = obj.rsplit('.', 1) module = import_module(module_name) diff --git a/tests/test_utils.py b/tests/test_utils.py index bcbe3a4..c6f5eca 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,6 @@ from queue import Queue import pytz from django.test import TestCase -from six import with_metaclass from django_clickhouse.models import ClickHouseSyncModel from django_clickhouse.utils import get_tz_offset, format_datetime, lazy_class_import, int_ranges, exec_in_parallel, \ @@ -110,7 +109,7 @@ class TestExecInParallel(TestCase): class TestSingletonMeta(TestCase): def test_singleton(self): - class Single(with_metaclass(SingletonMeta)): + class Single(metaclass=SingletonMeta): def __init__(self): self.test = 1