Skip to content

Commit

Permalink
Precommit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed May 26, 2022
1 parent 1f7d5d2 commit 4b6f0c5
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 83 deletions.
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
args: ['--maxkb=10000']
- id: check-case-conflict
- id: check-json
- id: mixed-line-ending

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black]

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: [--py37-plus]
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ django = "==4.0.*"
flake8 = "*"
twine = "*"
setuptools-scm = "*"
pre-commit = "*"

[requires]
python_version = "3.9"
113 changes: 111 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
* Issues: [github.com/datadesk/django-yamlfield/issues](https://github.com/datadesk/django-yamlfield/issues)
* Packaging: [pypi.python.org/pypi/django-yamlfield](https://pypi.python.org/pypi/django-yamlfield)
* Testing: [github.com/datadesk/django-yamlfield/actions](https://github.com/datadesk/django-yamlfield/actions)

1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Add it to one of your models.
from django.db import models
from yamlfield.fields import YAMLField


class YourModel(models.Model):
yaml = YAMLField()
```
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[bdist_wheel]
universal = 1

[flake8]
max-line-length=121
54 changes: 27 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from setuptools import setup, find_packages
from distutils.core import Command

from setuptools import find_packages, setup


def read(fname):
with open(os.path.join(os.path.dirname(__file__), fname)) as f:
Expand Down Expand Up @@ -50,50 +51,49 @@ def finalize_options(self):

def run(self):
from django.conf import settings

settings.configure(
DATABASES={
'default': {
'NAME': ':memory:',
'ENGINE': 'django.db.backends.sqlite3'
}
"default": {"NAME": ":memory:", "ENGINE": "django.db.backends.sqlite3"}
},
MIDDLEWARE_CLASSES=(),
INSTALLED_APPS=('yamlfield',)
INSTALLED_APPS=("yamlfield",),
)
from django.core.management import call_command
import django
from django.core.management import call_command

django.setup()
call_command('test', 'yamlfield')
call_command("test", "yamlfield")


setup(
name='django-yamlfield',
author='Ben Welsh',
author_email='[email protected]',
name="django-yamlfield",
author="Ben Welsh",
author_email="[email protected]",
url="http://django-yamlfield.readthedocs.io/",
description='A Django database field for storing YAML data',
description="A Django database field for storing YAML data",
long_description=read("README.md"),
long_description_content_type="text/markdown",
packages=find_packages(),
include_package_data=True,
license="MIT",
install_requires=(
'PyYAML>=3.10'
),
install_requires=("PyYAML>=3.10"),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Framework :: Django',
'Framework :: Django :: 3.1',
'Framework :: Django :: 4.0',
'License :: OSI Approved :: MIT License',
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Framework :: Django",
"Framework :: Django :: 3.1",
"Framework :: Django :: 4.0",
"License :: OSI Approved :: MIT License",
],
cmdclass={'test': TestCommand,},
cmdclass={
"test": TestCommand,
},
setup_requires=["setuptools_scm"],
use_scm_version={"version_scheme": version_scheme, "local_scheme": local_version},
)
2 changes: 1 addition & 1 deletion yamlfield/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_app_config = 'yamlfield.apps.YAMLFieldAppConfig'
default_app_config = "yamlfield.apps.YAMLFieldAppConfig"
2 changes: 1 addition & 1 deletion yamlfield/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class YAMLFieldAppConfig(AppConfig):
name = 'yamlfield'
name = "yamlfield"
verbose_name = "YAML field"
16 changes: 4 additions & 12 deletions yamlfield/fields.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import yaml
from django.db import models
from django.core.exceptions import ValidationError
from django.db import models

from .serializers import OrderedDumper, OrderedLoader


class YAMLField(models.TextField):

def from_db_value(self, value, expression, connection, context=None):
return self.to_python(value)

Expand All @@ -30,11 +30,7 @@ def get_prep_value(self, value):
if not value or value == "":
return ""
if isinstance(value, (dict, list)):
value = yaml.dump(
value,
Dumper=OrderedDumper,
default_flow_style=False
)
value = yaml.dump(value, Dumper=OrderedDumper, default_flow_style=False)
return value

def value_from_object(self, obj):
Expand All @@ -47,8 +43,4 @@ def value_from_object(self, obj):
value = getattr(obj, self.attname)
if not value or value == "":
return value
return yaml.dump(
value,
Dumper=OrderedDumper,
default_flow_style=False
)
return yaml.dump(value, Dumper=OrderedDumper, default_flow_style=False)
Loading

0 comments on commit 4b6f0c5

Please sign in to comment.