Add pre-commit config and fix for it

This commit is contained in:
frgmt 2025-01-06 11:38:01 +09:00
parent a422d6c4b8
commit 63362d5804
7 changed files with 84 additions and 31 deletions

View file

@ -26,7 +26,7 @@ jobs:
test: test:
strategy: strategy:
matrix: matrix:
python_version: ['3.10', 3.11, 3.12] python_version: ["3.10", 3.11, 3.12]
django_version: [3.2, 4.0, 4.1.0, 4.2.2, 5.0, 5.1.4] django_version: [3.2, 4.0, 4.1.0, 4.2.2, 5.0, 5.1.4]
exclude: exclude:
- python_version: 3.12 - python_version: 3.12
@ -34,24 +34,24 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python_version }} - name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v3 uses: actions/setup-python@v3
with: with:
python-version: ${{ matrix.python_version }} python-version: ${{ matrix.python_version }}
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -q Django==${{ matrix.django_version }} pip install -q Django==${{ matrix.django_version }}
pip install coverage pytest pip install coverage pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests - name: Run tests
run: | run: |
coverage3 run --source='./encrypted_fields' manage.py test coverage3 run --source='./encrypted_fields' manage.py test
coverage xml coverage xml
# - name: "Upload coverage to Artifact" # - name: "Upload coverage to Artifact"
# uses: actions/upload-artifact@v4 # uses: actions/upload-artifact@v4

2
.gitignore vendored
View file

@ -5,4 +5,4 @@ dist/
.idea .idea
.pypirc .pypirc
.ruff_cache .ruff_cache
.venv .venv

50
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,50 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# exclude docs and static css
exclude: |
(?x)^(
package_test/.*
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace # Trims trailing whitespace.
args: [--markdown-linebreak-ext=md]
- id: check-ast # Checks whether the files parse as valid python.
- id: check-case-conflict # Checks for files that would conflict in case-insensitive filesystems.
- id: check-json # Attempts to load all json files to verify syntax
- id: check-merge-conflict # Check for files that contain merge conflict strings
- id: check-xml # Attempts to load all xml files to verify syntax
- id: check-toml # Attempts to load all toml files to verify syntax
- id: check-yaml # Attempts to load all yaml files to verify syntax
args: [--unsafe]
- id: end-of-file-fixer # Makes sure files end in a newline and only a newline.
- id: check-symlinks # Checks for symlinks which do not point to anything
- id: debug-statements # Check for debugger imports and py37+ breakpoint() calls in python source
- id: check-added-large-files # Prevent giant files from being committed
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
rev: v1.5.5
hooks:
- id: remove-crlf # Replace CRLF end-lines by LF ones before committing
- id: remove-tabs # Replace tabs by whitespaces before committing
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-use-type-annotations
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier # Autoformat yaml and markdown files
types_or: [yaml, markdown]
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
name: pyupgrade
args: [--py312-plus]

View file

@ -17,4 +17,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,31 +1,36 @@
[![Pypi Package](https://badge.fury.io/py/django-fernet-encrypted-fields.png)](http://badge.fury.io/py/django-fernet-encrypted-fields) [![Pypi Package](https://badge.fury.io/py/django-fernet-encrypted-fields.png)](http://badge.fury.io/py/django-fernet-encrypted-fields)
[![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/) [![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/)
### Django Fernet Encrypted Fields ### Django Fernet Encrypted Fields
This package was created as a successor to [django-encrypted-fields](https://github.com/defrex/django-encrypted-fields). This package was created as a successor to [django-encrypted-fields](https://github.com/defrex/django-encrypted-fields).
#### Getting Started #### Getting Started
```shell ```shell
$ pip install django-fernet-encrypted-fields $ pip install django-fernet-encrypted-fields
``` ```
In your `settings.py`, set random SALT_KEY In your `settings.py`, set random SALT_KEY
```python ```python
SALT_KEY = '0123456789abcdefghijklmnopqrstuvwxyz' SALT_KEY = '0123456789abcdefghijklmnopqrstuvwxyz'
``` ```
Then, in `models.py` Then, in `models.py`
```python ```python
from encrypted_fields.fields import EncryptedTextField from encrypted_fields.fields import EncryptedTextField
class MyModel(models.Model): class MyModel(models.Model):
text_field = EncryptedTextField() text_field = EncryptedTextField()
``` ```
Use your model as normal and your data will be encrypted in the database. Use your model as normal and your data will be encrypted in the database.
#### Rotating SALT keys #### Rotating SALT keys
You can rotate salt keys by turning the ```SALT_KEY``` settings.py entry into a list. The first key will be used to encrypt all new data, and decryption of existing values will be attempted with all given keys in order. This is useful for key rotation: place a new key at the head of the list for use with all new or changed data, but existing values encrypted with old keys will still be accessible
You can rotate salt keys by turning the `SALT_KEY` settings.py entry into a list. The first key will be used to encrypt all new data, and decryption of existing values will be attempted with all given keys in order. This is useful for key rotation: place a new key at the head of the list for use with all new or changed data, but existing values encrypted with old keys will still be accessible
```python ```python
SALT_KEY = [ SALT_KEY = [
@ -41,7 +46,6 @@ for obj in MuModel.objects.all():
obj.save() obj.save()
``` ```
#### Available Fields #### Available Fields
Currently build in and unit-tested fields. They have the same APIs as their non-encrypted counterparts. Currently build in and unit-tested fields. They have the same APIs as their non-encrypted counterparts.
@ -57,11 +61,11 @@ Currently build in and unit-tested fields. They have the same APIs as their non-
### Compatible Django Version ### Compatible Django Version
| Compatible Django Version |Specifically tested| | Compatible Django Version | Specifically tested |
|---------------------------|---| | ------------------------- | ------------------- |
| `3.2` |:heavy_check_mark:| | `3.2` | :heavy_check_mark: |
| `4.0` |:heavy_check_mark:| | `4.0` | :heavy_check_mark: |
| `4.1` |:heavy_check_mark:| | `4.1` | :heavy_check_mark: |
| `4.2` |:heavy_check_mark:| | `4.2` | :heavy_check_mark: |
| `5.0` |:heavy_check_mark:| | `5.0` | :heavy_check_mark: |
| `5.1` |:heavy_check_mark:| | `5.1` | :heavy_check_mark: |

View file

@ -22,4 +22,4 @@ strict = true
warn_unreachable = true warn_unreachable = true
warn_no_return = true warn_no_return = true
ignore_missing_imports = true ignore_missing_imports = true
disallow_untyped_decorators = false disallow_untyped_decorators = false

View file

@ -1,4 +1,3 @@
from __future__ import print_function
from setuptools import setup from setuptools import setup
setup( setup(