Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce and run pre-commit #92

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ example/db.sqlite3
*~
\#*\#
.#*.*
*_flymake*
*_flymake*
81 changes: 81 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
default_language_version:
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- id: debug-statements
- id: detect-private-key
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args:
- --py36-plus
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --ignore-init-module-imports
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- 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==22.1.0]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-tidy-imports
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.11.0
hooks:
- id: check-github-workflows
# - repo: https://github.com/mgedmin/check-manifest
# rev: "0.47"
# hooks:
# - id: check-manifest
# # See https://github.com/mgedmin/check-manifest/issues/141
# args: ["--no-build-isolation"]
# Unsure how to solve this failing

exclude: |
(?x)(
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.pytest_cache
| \.nox
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
| ^(
example
| scripts
| tests/project/files
)/
)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Example settings for Django 2.0:

INSTALLED_APPS = (
# ...
'djedi',
"djedi",
)

MIDDLEWARE = [
'djedi.middleware.translation.DjediTranslationMiddleware',
"djedi.middleware.translation.DjediTranslationMiddleware",
# ...
]
```
Expand All @@ -49,7 +49,7 @@ $ django-admin.py migrate djedi
# urls.py

urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
]
```

Expand Down
2 changes: 1 addition & 1 deletion djedi-react/.npm-upgrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"reason": "Not compatible with newer versions"
}
}
}
}
4 changes: 2 additions & 2 deletions djedi-react/test/Node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ test("it handles nodes with null value in response", async () => {
<span
data-i18n="en-us@test"
>

</span>
`);
});
Expand Down Expand Up @@ -773,7 +773,7 @@ Network error",
<span
data-i18n="en-us@5"
>

</span>
</article>
</div>
Expand Down
58 changes: 34 additions & 24 deletions djedi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# coding=utf-8
VERSION = (1, 3, 3, 'final', 0)
VERSION = (1, 3, 3, "final", 0)


def get_version(version=None):
"""Derives a PEP386-compliant version number from VERSION."""
if version is None:
version = VERSION
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
assert version[3] in ("alpha", "beta", "rc", "final")

# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|c}N - for alpha, beta and rc releases

parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:parts])
main = ".".join(str(x) for x in version[:parts])

sub = ''
if version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = ""
if version[3] != "final":
mapping = {"alpha": "a", "beta": "b", "rc": "c"}
sub = mapping[version[3]] + str(version[4])

return main + sub
Expand All @@ -30,33 +29,44 @@ def get_version(version=None):

def configure():
from django.conf import settings as django_settings

from cio.conf import settings

# Djedi default config
config = dict(
ENVIRONMENT={
'default': {
'i18n': django_settings.LANGUAGE_CODE,
'l10n': getattr(django_settings, 'ROOT_URLCONF', 'local').split('.', 1)[0],
'g11n': 'global'
config = {
"ENVIRONMENT": {
"default": {
"i18n": django_settings.LANGUAGE_CODE,
"l10n": getattr(django_settings, "ROOT_URLCONF", "local").split(".", 1)[
0
],
"g11n": "global",
}
},
CACHE='djedi.backends.django.cache.Backend',
STORAGE='djedi.backends.django.db.Backend',
PLUGINS=[
'cio.plugins.txt.TextPlugin',
'cio.plugins.md.MarkdownPlugin',
'djedi.plugins.img.ImagePlugin'
"CACHE": "djedi.backends.django.cache.Backend",
"STORAGE": "djedi.backends.django.db.Backend",
"PLUGINS": [
"cio.plugins.txt.TextPlugin",
"cio.plugins.md.MarkdownPlugin",
"djedi.plugins.img.ImagePlugin",
],
THEME='darth'
)
"THEME": "darth",
}

# Update config with global djedi django settings
config.update(getattr(django_settings, 'DJEDI', {}))
config.update(getattr(django_settings, "DJEDI", {}))

# Overwrite config with prefixed variables from django settings
for setting in ('ENVIRONMENT', 'CACHE', 'STORAGE', 'PIPELINE', 'PLUGINS', 'THEME', 'XSS_DOMAIN'):
conf = getattr(django_settings, 'DJEDI_%s' % setting, None)
for setting in (
"ENVIRONMENT",
"CACHE",
"STORAGE",
"PIPELINE",
"PLUGINS",
"THEME",
"XSS_DOMAIN",
):
conf = getattr(django_settings, "DJEDI_%s" % setting, None)
if conf is not None:
config[setting] = conf

Expand Down
31 changes: 20 additions & 11 deletions djedi/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
from django.contrib import admin
from django.db.models import Model
from django.template.defaultfilters import pluralize

from djedi.admin import cms


def register(admin_class):
name = admin_class.verbose_name
name_plural = getattr(admin_class, 'verbose_name_plural', pluralize(name))
name_plural = getattr(admin_class, "verbose_name_plural", pluralize(name))

model = type(name, (Model,), {
'__module__': __name__,
'Meta': type('Meta', (object,), dict(
managed=False,
abstract=True,
app_label='djedi',
verbose_name=name,
verbose_name_plural=name_plural
))
})
model = type(
name,
(Model,),
{
"__module__": __name__,
"Meta": type(
"Meta",
(object,),
{
"managed": False,
"abstract": True,
"app_label": "djedi",
"verbose_name": name,
"verbose_name_plural": name_plural,
},
),
},
)

admin.site._registry[model] = admin_class(model, admin.site)

Expand Down
Loading