Skip to content

Commit

Permalink
Remove django-appconf usage (#84)
Browse files Browse the repository at this point in the history
* Remove django-appconf usage
  • Loading branch information
chinskiy authored Apr 18, 2024
1 parent 9162533 commit bf82531
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dj_anonymizer [![Build Status](https://github.com/preply/dj_anonymizer/actions/workflows/test.yml/badge.svg)](https://travis-ci.com/preply/dj_anonymizer) [![codecov.io](https://codecov.io/github/preply/dj_anonymizer/coverage.svg?branch=master)](https://codecov.io/github/preply/dj_anonymizer?branch=master) [![PyPI version](https://badge.fury.io/py/dj-anonymizer.svg)](https://badge.fury.io/py/dj_anonymizer)
==================================

dj_anonymizer helps anonymize production database with any kind of fake data.
dj_anonymizer is a utility designed to anonymize production databases with various types of mock data, specifically designed for use within Django projects.

Project works with Django 4.2 or higher and Python 3.8 or higher.

Expand Down
14 changes: 11 additions & 3 deletions dj_anonymizer/anonymizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django
from django.conf import settings

from dj_anonymizer.conf import settings
from dj_anonymizer.utils import import_if_exist, truncate_table


Expand Down Expand Up @@ -51,6 +51,14 @@ def key(model):
def anonymize(self, only=None):
anon_list = self.anonym_models.values() if only is None \
else [self.anonym_models[only]]
# Size of chunks what will be used to select data from table.
select_batch_size = getattr(
settings, "ANONYMIZER_SELECT_BATCH_SIZE", 20000
)
# Size of chunks what will be used to update data in table.
update_batch_size = getattr(
settings, "ANONYMIZER_UPDATE_BATCH_SIZE", 500
)
for anonym_cls in anon_list:

if not anonym_cls.get_fields_names():
Expand All @@ -64,7 +72,7 @@ def anonymize(self, only=None):
i = 0
total = queryset.count()
for j in list(range(0, total,
settings.ANONYMIZER_SELECT_BATCH_SIZE)) + [None]:
select_batch_size)) + [None]:
subset = queryset.order_by('pk')[i:j]
for obj in subset:
i += 1
Expand All @@ -76,7 +84,7 @@ def anonymize(self, only=None):
queryset.bulk_update(
subset,
anonym_cls.get_fields_names(),
batch_size=settings.ANONYMIZER_UPDATE_BATCH_SIZE,
batch_size=update_batch_size,
)

def clean(self, only=None):
Expand Down
16 changes: 0 additions & 16 deletions dj_anonymizer/conf.py

This file was deleted.

10 changes: 7 additions & 3 deletions dj_anonymizer/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import importlib
import os

from django.conf import settings
from django.db import connections, router

from dj_anonymizer.conf import settings


VENDOR_TO_TRUNCATE = {
'postgresql': 'TRUNCATE TABLE',
Expand All @@ -23,7 +22,12 @@ def import_if_exist(filename):
"""
Check if file exist in appropriate path and import it
"""
filepath = os.path.join(settings.ANONYMIZER_MODEL_DEFINITION_DIR, filename)
model_devinition_dir = getattr(
settings,
'ANONYMIZER_MODEL_DEFINITION_DIR',
'anonymizer'
)
filepath = os.path.join(model_devinition_dir, filename)
full_filepath = os.path.abspath(filepath + '.py')

if os.path.isfile(full_filepath):
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=============

0.6.1
----------
* Improvement: remove django-appconf implicit dependency (`#84 <https://github.com/preply/dj_anonymizer/pull/84>`__)

0.6.0
----------
* Feature: adds possibility to truncate with cascade option (`#73 <https://github.com/preply/dj_anonymizer/pull/73>`__)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.6.0'
release = '0.6.1-dev'


# -- General configuration ---------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Django>=4.2,<=4.3
django-appconf
flake8==7.0.0
isort==5.13.2
pytest==8.1.1
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description-file = README.md
[isort]
multi_line_output=3
lines_after_imports=2
known_third_party = appconf,django,pytest
known_third_party = django,pytest
known_first_party = dj_anonymizer
default_section = FIRSTPARTY

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def read(*rnames):
name='dj_anonymizer',
packages=['dj_anonymizer'],
include_package_data=True,
version='0.6.0',
description='This project helps anonymize production database '
+ 'with fake data of any kind.',
version='0.6.1-dev',
description='dj_anonymizer is a utility designed to anonymize '
+ 'production databases with various types of mock data, '
+ 'specifically designed for use within Django projects.',
long_description=(read('README.md')),
long_description_content_type='text/markdown',
license='MIT',
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ envlist =
deps =
django42: Django>=4.2,<4.3
django50: Django>=5.0,<5.1
django-appconf
pytest==8.1.1
pytest-django==4.8.0
pytest-mock==3.14.0
Expand Down

0 comments on commit bf82531

Please sign in to comment.