From ebb33a57ed7b072ddaacbb911cbc8af571f58e6e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 1 Jun 2021 08:25:08 -0400 Subject: [PATCH 01/15] Updated .github/workflows/auto-merge.yml --- .github/workflows/auto-merge.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index 75a2a4f9..61ff5916 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -13,6 +13,8 @@ jobs: github.actor == 'dependabot' || github.actor == 'dependabot-preview[bot]' || github.actor == 'dependabot-preview' || + github.actor == 'pre-commit-ci' || + github.actor == 'pre-commit-ci[bot]' || github.actor == 'renovate[bot]' || github.actor == 'renovate' steps: From 4dba72f8592d6e0cf0f3a4d91ed6bdb2e2a2d109 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 1 Jun 2021 08:31:17 -0400 Subject: [PATCH 02/15] Updated .pre-commit-config.yaml --- .pre-commit-config.yaml | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 89accf86..a273f454 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,16 +5,22 @@ repos: - id: autoflake args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable'] - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 - hooks: - - id: trailing-whitespace - exclude: ^docs/.*|.*.md - - id: end-of-file-fixer - exclude: ^docs/.*|.*.md + - repo: https://github.com/pycqa/isort + rev: 5.8.0 + hooks: + - id: isort + args: ["--profile", "black", "--filter-files"] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: trailing-whitespace + exclude: ^docs/.*|.*.md + - id: end-of-file-fixer + exclude: ^docs/.*|.*.md - - repo: https://github.com/psf/black - rev: 21.5b1 - hooks: - - id: black - language_version: python3 + - repo: https://github.com/psf/black + rev: 21.5b2 + hooks: + - id: black + language_version: python3 From 1640cfd4b950b1e23bbf34f1d1f288d552b0a6af Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 1 Jun 2021 08:37:24 -0400 Subject: [PATCH 03/15] Update README.md (#348) * Update README.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- README.md | 1 + model_clone/mixins/clone.py | 8 +++---- model_clone/tests/test_clone_mixin.py | 24 +++++++++---------- .../tests/test_create_copy_of_instance.py | 2 +- sample/admin.py | 2 +- .../commands/create_default_user.py | 1 - sample/migrations/0001_initial.py | 2 +- sample/migrations/0003_book_created_at.py | 2 +- sample/migrations/0005_page.py | 3 ++- sample/migrations/0006_assignment.py | 3 ++- sample/migrations/0008_page_created_at.py | 2 +- .../migrations/0010_furniture_house_room.py | 3 ++- sample/migrations/0012_backcover_cover.py | 3 ++- sample/migrations/0013_edition.py | 3 ++- sample/migrations/0014_auto_20210422_1449.py | 3 ++- sample/migrations/0015_auto_20210423_0935.py | 3 ++- sample/models.py | 2 +- sample_assignment/migrations/0001_initial.py | 1 + sample_company/migrations/0001_initial.py | 1 + sample_driver/migrations/0001_initial.py | 1 + setup.py | 2 +- 21 files changed, 41 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 75039b0b..22c75996 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Create copies of a model instance with explicit control on how the instance shou |:----:|:---------------:|:--------:|:-------------:| :---------------:|:-------------:|:-----------:| | [![Test](https://github.com/tj-django/django-clone/workflows/Test/badge.svg)](https://github.com/tj-django/django-clone/actions?query=workflow%3ATest) | [![Known Vulnerabilities](https://snyk.io/test/github/tj-django/django-clone/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/tj-django/django-clone?targetFile=requirements.txt) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Coverage)
[![codecov](https://codecov.io/gh/tj-django/django-clone/branch/main/graph/badge.svg?token=2NE21Oe50Q)](https://codecov.io/gh/tj-django/django-clone)| [![Codacy Badge](https://app.codacy.com/project/badge/Grade/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Grade) | [![Updates](https://pyup.io/repos/github/tj-django/django-clone/shield.svg)](https://pyup.io/repos/github/tj-django/django-clone/) | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/tj-django/django-clone/main.svg)](https://results.pre-commit.ci/latest/github/tj-django/django-clone/main) | + ## Table of contents * [Installation](#installation) diff --git a/model_clone/mixins/clone.py b/model_clone/mixins/clone.py index d10306a7..30c817e9 100644 --- a/model_clone/mixins/clone.py +++ b/model_clone/mixins/clone.py @@ -1,20 +1,20 @@ from itertools import repeat -from typing import List, Optional, Dict +from typing import Dict, List, Optional from conditional import conditional from django.core.checks import Error from django.core.exceptions import ValidationError -from django.db import transaction, models, IntegrityError, connections +from django.db import IntegrityError, connections, models, transaction from django.db.models import SlugField from django.utils.text import slugify from model_clone.apps import ModelCloneConfig from model_clone.utils import ( clean_value, - transaction_autocommit, - get_unique_value, context_mutable_attribute, get_fields_and_unique_fields_from_cls, + get_unique_value, + transaction_autocommit, ) diff --git a/model_clone/tests/test_clone_mixin.py b/model_clone/tests/test_clone_mixin.py index c6bf3d51..c3a484cd 100644 --- a/model_clone/tests/test_clone_mixin.py +++ b/model_clone/tests/test_clone_mixin.py @@ -4,28 +4,28 @@ from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.db.transaction import TransactionManagementError +from django.db.utils import IntegrityError from django.test import TestCase, TransactionTestCase from django.utils.text import slugify -from django.db.utils import IntegrityError from django.utils.timezone import make_naive -from mock import patch, PropertyMock +from mock import PropertyMock, patch from sample.models import ( + Author, + BackCover, + Book, + BookSaleTag, + BookTag, + Cover, Edition, + Furniture, + House, Library, - Book, - Author, Page, - House, + Product, Room, - Furniture, - Cover, - BackCover, - BookTag, - BookSaleTag, - Tag, SaleTag, - Product, + Tag, ) User = get_user_model() diff --git a/model_clone/tests/test_create_copy_of_instance.py b/model_clone/tests/test_create_copy_of_instance.py index 395be27e..2da9b245 100644 --- a/model_clone/tests/test_create_copy_of_instance.py +++ b/model_clone/tests/test_create_copy_of_instance.py @@ -5,7 +5,7 @@ from django.utils.text import slugify from model_clone import create_copy_of_instance -from sample.models import Library, Book +from sample.models import Book, Library User = get_user_model() diff --git a/sample/admin.py b/sample/admin.py index e64a9bb8..7416593d 100644 --- a/sample/admin.py +++ b/sample/admin.py @@ -2,7 +2,7 @@ # Register your models here. from model_clone import CloneModelAdmin -from sample.models import Book, Author, Page, Library +from sample.models import Author, Book, Library, Page class PageInline(admin.StackedInline): diff --git a/sample/management/commands/create_default_user.py b/sample/management/commands/create_default_user.py index 5a51dd18..f3214f48 100644 --- a/sample/management/commands/create_default_user.py +++ b/sample/management/commands/create_default_user.py @@ -3,7 +3,6 @@ from django.contrib.auth import get_user_model from django.core.management.base import BaseCommand - User = get_user_model() diff --git a/sample/migrations/0001_initial.py b/sample/migrations/0001_initial.py index d77b1e70..15c07508 100644 --- a/sample/migrations/0001_initial.py +++ b/sample/migrations/0001_initial.py @@ -1,8 +1,8 @@ # Generated by Django 2.2 on 2019-09-26 09:58 +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/sample/migrations/0003_book_created_at.py b/sample/migrations/0003_book_created_at.py index ab45bbe0..38ae3774 100644 --- a/sample/migrations/0003_book_created_at.py +++ b/sample/migrations/0003_book_created_at.py @@ -1,7 +1,7 @@ # Generated by Django 2.2 on 2019-11-21 23:37 -from django.db import migrations, models import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/sample/migrations/0005_page.py b/sample/migrations/0005_page.py index 133a4a7d..d94b84a8 100644 --- a/sample/migrations/0005_page.py +++ b/sample/migrations/0005_page.py @@ -1,7 +1,8 @@ # Generated by Django 3.0 on 2019-12-03 09:47 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample/migrations/0006_assignment.py b/sample/migrations/0006_assignment.py index b0f93488..43ed9e61 100644 --- a/sample/migrations/0006_assignment.py +++ b/sample/migrations/0006_assignment.py @@ -1,7 +1,8 @@ # Generated by Django 3.0.6 on 2020-05-16 17:33 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample/migrations/0008_page_created_at.py b/sample/migrations/0008_page_created_at.py index 243b6389..cdc964d8 100644 --- a/sample/migrations/0008_page_created_at.py +++ b/sample/migrations/0008_page_created_at.py @@ -1,7 +1,7 @@ # Generated by Django 3.1.7 on 2021-04-07 11:58 -from django.db import migrations, models import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/sample/migrations/0010_furniture_house_room.py b/sample/migrations/0010_furniture_house_room.py index 0b6f4678..2d810e00 100644 --- a/sample/migrations/0010_furniture_house_room.py +++ b/sample/migrations/0010_furniture_house_room.py @@ -1,7 +1,8 @@ # Generated by Django 3.1.7 on 2021-04-10 13:50 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample/migrations/0012_backcover_cover.py b/sample/migrations/0012_backcover_cover.py index 9c848b75..b5e7dcd4 100644 --- a/sample/migrations/0012_backcover_cover.py +++ b/sample/migrations/0012_backcover_cover.py @@ -1,7 +1,8 @@ # Generated by Django 3.1.7 on 2021-04-14 17:49 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample/migrations/0013_edition.py b/sample/migrations/0013_edition.py index 2e87686b..c3059559 100644 --- a/sample/migrations/0013_edition.py +++ b/sample/migrations/0013_edition.py @@ -1,8 +1,9 @@ # Generated by Django 3.1.5 on 2021-04-20 00:23 -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone +from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample/migrations/0014_auto_20210422_1449.py b/sample/migrations/0014_auto_20210422_1449.py index 8a654c16..184eb0ed 100644 --- a/sample/migrations/0014_auto_20210422_1449.py +++ b/sample/migrations/0014_auto_20210422_1449.py @@ -1,7 +1,8 @@ # Generated by Django 3.2 on 2021-04-22 14:49 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample/migrations/0015_auto_20210423_0935.py b/sample/migrations/0015_auto_20210423_0935.py index f464dc8b..22700767 100644 --- a/sample/migrations/0015_auto_20210423_0935.py +++ b/sample/migrations/0015_auto_20210423_0935.py @@ -1,7 +1,8 @@ # Generated by Django 3.2 on 2021-04-23 09:35 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample/models.py b/sample/models.py index ebcdd3ae..6d861c4b 100644 --- a/sample/models.py +++ b/sample/models.py @@ -2,8 +2,8 @@ from django.conf import settings from django.db import models -from django.utils.translation import gettext as _ from django.utils import timezone +from django.utils.translation import gettext as _ from model_clone import CloneMixin from model_clone.models import CloneModel diff --git a/sample_assignment/migrations/0001_initial.py b/sample_assignment/migrations/0001_initial.py index 728af10a..5894211f 100644 --- a/sample_assignment/migrations/0001_initial.py +++ b/sample_assignment/migrations/0001_initial.py @@ -1,6 +1,7 @@ # Generated by Django 3.0.6 on 2020-05-16 17:33 from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample_company/migrations/0001_initial.py b/sample_company/migrations/0001_initial.py index 1c18b82e..88d11742 100644 --- a/sample_company/migrations/0001_initial.py +++ b/sample_company/migrations/0001_initial.py @@ -1,6 +1,7 @@ # Generated by Django 3.0.6 on 2020-05-16 17:33 from django.db import migrations, models + import model_clone.mixins.clone diff --git a/sample_driver/migrations/0001_initial.py b/sample_driver/migrations/0001_initial.py index 35819b7e..fa5db61f 100644 --- a/sample_driver/migrations/0001_initial.py +++ b/sample_driver/migrations/0001_initial.py @@ -1,6 +1,7 @@ # Generated by Django 3.0.6 on 2020-05-16 17:33 from django.db import migrations, models + import model_clone.mixins.clone diff --git a/setup.py b/setup.py index ae6840c0..1e18d4d1 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ -import os import io +import os from setuptools import find_packages, setup From 85b3fa66c4ae10e991d3ea46228091df67c3a232 Mon Sep 17 00:00:00 2001 From: jackton1 Date: Tue, 1 Jun 2021 13:08:50 +0000 Subject: [PATCH 04/15] Updated README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 22c75996..75039b0b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Create copies of a model instance with explicit control on how the instance shou |:----:|:---------------:|:--------:|:-------------:| :---------------:|:-------------:|:-----------:| | [![Test](https://github.com/tj-django/django-clone/workflows/Test/badge.svg)](https://github.com/tj-django/django-clone/actions?query=workflow%3ATest) | [![Known Vulnerabilities](https://snyk.io/test/github/tj-django/django-clone/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/tj-django/django-clone?targetFile=requirements.txt) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Coverage)
[![codecov](https://codecov.io/gh/tj-django/django-clone/branch/main/graph/badge.svg?token=2NE21Oe50Q)](https://codecov.io/gh/tj-django/django-clone)| [![Codacy Badge](https://app.codacy.com/project/badge/Grade/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Grade) | [![Updates](https://pyup.io/repos/github/tj-django/django-clone/shield.svg)](https://pyup.io/repos/github/tj-django/django-clone/) | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/tj-django/django-clone/main.svg)](https://results.pre-commit.ci/latest/github/tj-django/django-clone/main) | - ## Table of contents * [Installation](#installation) From e34f80a1e153b04b4df50f0189b9aa2c38836a2a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 1 Jun 2021 10:47:58 -0400 Subject: [PATCH 05/15] Updated comment. --- model_clone/mixins/clone.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/model_clone/mixins/clone.py b/model_clone/mixins/clone.py index 30c817e9..29013d12 100644 --- a/model_clone/mixins/clone.py +++ b/model_clone/mixins/clone.py @@ -250,11 +250,11 @@ def bulk_clone(self, count, attrs=None, batch_size=None, auto_commit=False): def parallel_clone(self, count, attrs=None, batch_size=None, auto_commit=False): # if this takes n time for t records - # t^n i.e 100 * 10ms = 1000ms to clone 100 objects. + # t^n i.e 100 ** 2ms = 10000ms (10s) to clone 100 objects. # I'll like to reduce this down to max time to clone count/batch_size i.e - # If it take 100ms to clone 100 objects with a db of batch_size 100 - # If it takes 10ms to clone 10 objects i'll like to keep this down to 10ms for - # max_num_of_threads i.e 10 threads for 100 objects. + # If it take 10000ms to clone 100 objects with a db of batch_size 100 + # If it takes 20ms to clone 10 objects I'll like to keep this down to 20ms + # i.e max_num_of_threads 10 for 100 objects. # This should run in parallel # Testing jit and cpython if they offer better API's. pass From 229f4a88205fd8eb1b19554e7b121deb261010e7 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 1 Jun 2021 16:28:23 -0400 Subject: [PATCH 06/15] Update index.html --- docs/index.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/index.html b/docs/index.html index 6462b3d4..9e3b7b24 100644 --- a/docs/index.html +++ b/docs/index.html @@ -15,7 +15,7 @@