Skip to content

Commit

Permalink
Compatibility with Django 4.2 (#40)
Browse files Browse the repository at this point in the history
* update ugettext_lazy references
* minor cleanup
* tests structure
* replace setup.py to pyproject.toml
* implement github actions
* linting fixes
* fix tests
* drop explicit six usage
* loosen dependency restrictions
* loosen restrictions for deps
* folder rename
* revert pyyaml requirement
* regen lock file
  • Loading branch information
SunnyR authored Jun 7, 2024
1 parent 8bd6dc3 commit 45a66c2
Show file tree
Hide file tree
Showing 37 changed files with 1,320 additions and 237 deletions.
21 changes: 15 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
# EditorConfig is awesome: http://EditorConfig.org
# Defines the coding style for different editors and IDEs.
# http://editorconfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
# Rules for source code.
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
trim_trailing_whitespace = true

# Rules for Python code.
[*.py]
charset = utf-8
indent_style = space
indent_size = 4

# Rules for markdown documents.
[*.md]
indent_size = 4
trim_trailing_whitespace = false

# Rules for makefile
[Makefile]
charset = utf-8
indent_style = tab
indent_size = 8
indent_size = 4
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Summary
- Write a quick summary of what this PR is for


##### Related Links
- Paste link to ticket or any other related sites here

##### Ready for QA Checklist
- [ ] Code Review
- [ ] Dev QA
- [ ] Rebase and Squash
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release

on:
push:
tags:
- '*'
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools poetry tox-gh-actions
poetry install
- name: Build wheels and source tarball
run: poetry build
- name: publish to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
39 changes: 39 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Validate

on:
push:
branches:
- develop
- master
- main
- 'release/**'
pull_request:
branches:
- '*'
workflow_dispatch:

jobs:
validate:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools poetry
poetry install
- name: Linting
run: |
poetry run isort .
poetry run black .
poetry run flake8 . --extend-ignore=D,E501,W601 --extend-exclude=docs/ --statistics --count
- name: Security
run: poetry run bandit -c pyproject.toml -r .
- name: Testing
run: poetry run python ./runtests.py
67 changes: 55 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,58 @@
*.py[co]
.project
.pydevproject
*~
*.db
*.orig
*.DS_Store
*.swp
*.bak

# docs
_build

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.idea
.tox
*.egg-info/*
docs/_build/*
dist/*
*.swp
.vscode/*

.idea

.DS_Store

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

# Configuration
sdelint.cnf

#generated data
usecases/output.csv

# Test files
info.log
htmlcov/

#ides
.idea
.vscode

#custom cert bundle
my_root_certs.crt

# symbolic links
.flake8

conf/
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.13
hooks:
- id: forbid-crlf
- id: remove-crlf
- id: forbid-tabs
exclude_types: [csv]
- id: remove-tabs
exclude_types: [csv]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-merge-conflict
- id: check-yaml
args: [--unsafe]

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort

- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
language_version: python3.12

- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports==1.10.0]
exclude: ^tests
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion AUTHORS

This file was deleted.

5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
init:
pip install -r requirements.txt

lint:
flake8 --max-line-length 120 --extend-ignore=D
poetry run black .
poetry run isort .
poetry run flake8 . --extend-ignore=D,E501,W601 --extend-exclude=docs/ --statistics --count

test:
./runtests.py

coverage:
coverage run --source=multi_import runtests.py && coverage report
poetry run python ./runtests.py
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# django-multi-import

Import/export multi Django resources together atomically.

## Usage

You can run the tests with via::

python setup.py test

or::

python runtests.py
23 changes: 0 additions & 23 deletions README.rst

This file was deleted.

15 changes: 5 additions & 10 deletions multi_import/cache.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from collections import defaultdict

from django.core.exceptions import MultipleObjectsReturned
import six
from tablib.compat import unicode


class CachedObject(object):
Expand All @@ -29,7 +27,7 @@ def __len__(self):

@staticmethod
def _get_value_key(field, value):
return unicode(value).lower() if field.endswith("__iexact") else unicode(value)
return str(value).lower() if field.endswith("__iexact") else str(value)

def add(self, obj):
cached_obj = CachedObject(obj)
Expand All @@ -48,7 +46,7 @@ def add(self, obj):
self.object_count += 1

def get(self, field, value, default=None):
if isinstance(field, six.string_types):
if isinstance(field, str):
field = (field,)
value = (value,)

Expand All @@ -67,9 +65,7 @@ def get(self, field, value, default=None):

def find(self, value, fields=None):
fields = fields or self.lookup_fields
single_fields = (
field for field in fields if isinstance(field, six.string_types)
)
single_fields = (field for field in fields if isinstance(field, str))
for field in single_fields:
result = self.get(field, value)
if result:
Expand All @@ -79,7 +75,7 @@ def find(self, value, fields=None):
def match(self, data, fields=None):
fields = fields or self.lookup_fields
for field in fields:
if isinstance(field, six.string_types):
if isinstance(field, str):
value = data.get(field, None)
else:
value = [data.get(f) for f in field]
Expand All @@ -98,8 +94,7 @@ def _flatten_fields(self, fields):
return set(
item
for sublist in (
(item,) if isinstance(item, six.string_types) else item
for item in fields
(item,) if isinstance(item, str) else item for item in fields
)
for item in sublist
)
Expand Down
Loading

0 comments on commit 45a66c2

Please sign in to comment.