Skip to content

Commit

Permalink
Python 3.12 upgrade (#6)
Browse files Browse the repository at this point in the history
* minor cleanup
* replace setup.py with pyproject.toml
* Add github workflows
* linting fixes
* fix: license declaraction
* run django-upgrade
* add pull request template
* fix: bandit findings
* refactor test entrypoint
* switch back to keyvaluestore
* fix testing command in ci
* bump version
* update readme.md
  • Loading branch information
SunnyR authored Jun 7, 2024
1 parent b3030e6 commit 96eca19
Show file tree
Hide file tree
Showing 27 changed files with 1,005 additions and 174 deletions.
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Defines the coding style for different editors and IDEs.
# http://editorconfig.org

# top-most EditorConfig file
root = true

# 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]
indent_size = 4

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

# Rules for makefile
[Makefile]
indent_style = tab
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
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
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
*.py[co]
*.swp
*.bak

# docs
_build

# Packages
*.egg
Expand All @@ -8,8 +13,46 @@ build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

.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/
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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

18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

4 changes: 0 additions & 4 deletions CODEOWNERS

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lint:
find . -name '*.py' | xargs flake8 --ignore=E501,W601
poetry run flake8 . --extend-ignore=D,E501,W601 --extend-exclude=docs/ --statistics --count

test:
(cd testing; python manage.py test)
poetry run python ./runtests.py
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# django-keyvaluestore

django-keyvaluestore implements a very simple database-based key-value store for Django.

This package is a fork and only maintained on an as needed basis since the upstream package is no longer maintained at - https://github.com/vikingco/django-keyvaluestore.

## Install

```bash
pip install git+https://github.com/sdelements/django-keyvaluestore@master
```

## Usage

The interface is straightforward::

```python
from keyvaluestore import get_value_for_key, set_key_value
set_key_value('foo', 'bar')
get_value_for_key('foo')
```
13 changes: 0 additions & 13 deletions README.rst

This file was deleted.

11 changes: 0 additions & 11 deletions ci.sh

This file was deleted.

1 change: 0 additions & 1 deletion keyvaluestore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
__version__ = '0.5'
8 changes: 3 additions & 5 deletions keyvaluestore/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from keyvaluestore.models import KeyValueStore


@admin.register(KeyValueStore)
class KeyValueStoreAdmin(admin.ModelAdmin):
list_display = ('key', 'value')
search_fields = ('key', 'value')


admin.site.register(KeyValueStore, KeyValueStoreAdmin)
list_display = ("key", "value")
search_fields = ("key", "value")
5 changes: 3 additions & 2 deletions keyvaluestore/managers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.db import models
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.db import models


class KeyValueStoreManager(models.Manager):
def get_value_for_key(self, key):
from keyvaluestore.utils import get_cache_key

cached_key = get_cache_key(key)
cached = cache.get(cached_key)

Expand All @@ -16,6 +17,6 @@ def get_value_for_key(self, key):

return obj.value
except ObjectDoesNotExist:
raise KeyError(u"The request key '%s' could not be found." % key)
raise KeyError("The request key '%s' could not be found." % key)
else:
return cached
24 changes: 16 additions & 8 deletions keyvaluestore/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='KeyValueStore',
name="KeyValueStore",
fields=[
('key', models.CharField(max_length=200, unique=True, serialize=False, primary_key=True, db_index=True)),
('value', models.TextField()),
(
"key",
models.CharField(
max_length=200,
unique=True,
serialize=False,
primary_key=True,
db_index=True,
),
),
("value", models.TextField()),
],
options={
'verbose_name': 'Key Value pair',
'verbose_name_plural': 'Key Value pairs',
"verbose_name": "Key Value pair",
"verbose_name_plural": "Key Value pairs",
},
bases=(models.Model,),
),
Expand Down
11 changes: 6 additions & 5 deletions keyvaluestore/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.cache import cache
from django.db import models
from django.utils.translation import gettext_lazy as _

from keyvaluestore.managers import KeyValueStoreManager

Expand All @@ -12,11 +12,11 @@ class KeyValueStore(models.Model):
objects = KeyValueStoreManager()

class Meta:
verbose_name = _('Key Value pair')
verbose_name_plural = _('Key Value pairs')
verbose_name = _("Key Value pair")
verbose_name_plural = _("Key Value pairs")

def __unicode__(self):
return '%s: %s' % (self.key, self.value)
return "%s: %s" % (self.key, self.value)

def save(self, *args, **kwargs):
cache.delete(self.cached_key)
Expand All @@ -27,4 +27,5 @@ def save(self, *args, **kwargs):
@property
def cached_key(self):
from keyvaluestore.utils import get_cache_key

return get_cache_key(self.key)
6 changes: 4 additions & 2 deletions keyvaluestore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def get_cache_key(key):
return 'kvs_%s' % (key, )
return "kvs_%s" % (key,)


def get_value_for_key(key):
Expand All @@ -18,7 +18,9 @@ def get_value_or_default(key, default):


def set_key_value(key, value):
obj, created = KeyValueStore.objects.get_or_create(key=key, defaults={'value': value})
obj, created = KeyValueStore.objects.get_or_create(
key=key, defaults={"value": value}
)
if not created:
obj.value = value
obj.save()
Expand Down
Loading

0 comments on commit 96eca19

Please sign in to comment.