Use Black's default line length of 88

This commit is contained in:
Martin Mahner 2020-01-08 13:19:52 +01:00
parent 02a6812c80
commit d0f7e2eda6
15 changed files with 32 additions and 90 deletions

View file

@ -19,7 +19,7 @@ code-cleanup: ## Black and isort the Python codebase
autoflake --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables \
--in-place --exclude "**/migrations/*,dpaste/settings/local.py" -r dpaste
isort -rc dpaste
black --line-length=80 --exclude='/(migrations)/' dpaste
black --exclude='/(migrations)/' dpaste
.PHONY: docs
docs: ## Compile the documentation

View file

@ -1,9 +1,7 @@
VERSION = (3, 5)
__version__ = "{major}.{minor}{rest}".format(
major=VERSION[0],
minor=VERSION[1],
rest="".join(str(i) for i in VERSION[2:]),
major=VERSION[0], minor=VERSION[1], rest="".join(str(i) for i in VERSION[2:]),
)
default_app_config = "dpaste.apps.dpasteAppConfig"

View file

@ -43,9 +43,7 @@ class dpasteAppConfig(AppConfig):
# String. A string of characters which are used to create the random slug.
# This is intentionally missing l and I as they look too similar with
# sans-serif fonts.
SLUG_CHOICES = (
"abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890"
)
SLUG_CHOICES = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890"
# String. The lexer key that is pre-selected in the dropdown. Note that
# this is only used if the user has not saved a snippet before, otherwise

View file

@ -20,18 +20,14 @@ def get_expire_values(expires):
else:
expire_type = Snippet.EXPIRE_TIME
expires = expires and expires or config.EXPIRE_DEFAULT
expires = datetime.datetime.now() + datetime.timedelta(
seconds=int(expires)
)
expires = datetime.datetime.now() + datetime.timedelta(seconds=int(expires))
return expires, expire_type
class SnippetForm(forms.ModelForm):
content = forms.CharField(
label=_("Content"),
widget=forms.Textarea(
attrs={"placeholder": _("Awesome code goes here...")}
),
widget=forms.Textarea(attrs={"placeholder": _("Awesome code goes here...")}),
max_length=config.MAX_CONTENT_LENGTH,
strip=False,
)

View file

@ -77,9 +77,7 @@ class MarkdownHighlighter(PlainTextHighlighter):
return mark_safe(
misaka.html(
code_string,
extensions=self.extensions,
render_flags=self.render_flags,
code_string, extensions=self.extensions, render_flags=self.render_flags,
)
)

View file

@ -14,10 +14,7 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
"--dry-run",
action="store_true",
dest="dry_run",
help="Don't do anything.",
"--dry-run", action="store_true", dest="dry_run", help="Don't do anything.",
),
def handle(self, *args, **options):
@ -43,9 +40,7 @@ class Command(BaseCommand):
if len(deleteable_snippets) == 0:
self.stdout.write(u"No snippets to delete.")
return None
self.stdout.write(
u"Will delete %s snippet(s):\n" % deleteable_snippets.count()
)
self.stdout.write(u"Will delete %s snippet(s):\n" % deleteable_snippets.count())
for d in deleteable_snippets:
self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires))

View file

@ -21,10 +21,7 @@ def generate_secret_id(length):
)
secret_id = "".join(
[
R.choice(config.SLUG_CHOICES)
for i in range(length or config.SLUG_LENGTH)
]
[R.choice(config.SLUG_CHOICES) for i in range(length or config.SLUG_LENGTH)]
)
# Check if this slug already exists, if not, return this new slug
@ -52,9 +49,7 @@ class Snippet(models.Model):
_("Secret ID"), max_length=255, blank=True, null=True, unique=True
)
content = models.TextField(_("Content"))
lexer = models.CharField(
_("Lexer"), max_length=30, default=highlight.LEXER_DEFAULT
)
lexer = models.CharField(_("Lexer"), max_length=30, default=highlight.LEXER_DEFAULT)
published = models.DateTimeField(_("Published"), auto_now_add=True)
expire_type = models.PositiveSmallIntegerField(
_("Expire Type"), choices=EXPIRE_CHOICES, default=EXPIRE_CHOICES[0][0]

View file

@ -39,9 +39,7 @@ LANGUAGES = (("en", "English"),)
# os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'locale')),
# )
STATICFILES_STORAGE = (
"django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
)
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
@ -90,9 +88,7 @@ INSTALLED_APPS = [
]
sys.stdout.write(f"\n🐘 Database URL is: {env('DATABASE_URL')}\n")
DATABASES = {
"default": dj_database_url.config(default="sqlite:///dpaste.sqlite")
}
DATABASES = {"default": dj_database_url.config(default="sqlite:///dpaste.sqlite")}
# ==============================================================================
# App specific settings
@ -124,9 +120,7 @@ CSP_STYLE_SRC = ("'self'", "'unsafe-inline'")
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {
"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}
},
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
"handlers": {
"mail_admins": {
"level": "ERROR",

View file

@ -7,9 +7,7 @@ from .base import * # noqa
SECRET_KEY = "test-key"
DATABASES = {
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
}
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
# Drop CSP middleware for Django 3.0 until it was fixed upstream
# https://github.com/mozilla/django-csp/issues/129

View file

@ -145,8 +145,7 @@ class SnippetAPITestCase(TestCase):
def test_expire_choices_invalid_given(self):
# A expire choice that does not exist returns a BadRequest
response = self.client.post(
self.api_url,
{"content": u"Hello Wörld.\n\tGood Bye", "expires": "foobar"},
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": "foobar"},
)
self.assertEqual(response.status_code, 400)
self.assertEqual(Snippet.objects.count(), 0)
@ -163,25 +162,19 @@ class SnippetAPITestCase(TestCase):
)
self.assertEqual(response.status_code, 200)
self.assertEqual(Snippet.objects.count(), 1)
self.assertEqual(
Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_ONETIME
)
self.assertEqual(Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_ONETIME)
def test_valid_expiration_choices_never(self):
response = self.client.post(
self.api_url,
{"content": u"Hello Wörld.\n\tGood Bye", "expires": "never"},
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": "never"},
)
self.assertEqual(response.status_code, 200)
self.assertEqual(Snippet.objects.count(), 1)
self.assertEqual(
Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_KEEP
)
self.assertEqual(Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_KEEP)
def test_valid_expiration_choices_hour(self):
response = self.client.post(
self.api_url,
{"content": u"Hello Wörld.\n\tGood Bye", "expires": 3600},
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": 3600},
)
self.assertEqual(response.status_code, 200)
self.assertEqual(Snippet.objects.count(), 1)
@ -211,11 +204,7 @@ class SnippetAPITestCase(TestCase):
"""
response = self.client.post(
self.api_url,
{
"content": u"Hello Wörld.\n\tGood Bye",
"lexer": "",
"filename": "",
},
{"content": u"Hello Wörld.\n\tGood Bye", "lexer": "", "filename": "",},
)
self.assertEqual(response.status_code, 400)
@ -249,9 +238,7 @@ class SnippetAPITestCase(TestCase):
)
self.assertEqual(response.status_code, 200)
self.assertEqual(Snippet.objects.count(), 1)
self.assertEqual(
Snippet.objects.all()[0].lexer, config.PLAIN_CODE_SYMBOL
)
self.assertEqual(Snippet.objects.all()[0].lexer, config.PLAIN_CODE_SYMBOL)
def test_filename_and_lexer_given(self):
"""

View file

@ -145,9 +145,9 @@ class SnippetTestCase(TestCase):
for i in range(0, 100):
Snippet.objects.create(content="foobar")
slug_list = Snippet.objects.values_list(
"secret_id", flat=True
).order_by("published")
slug_list = Snippet.objects.values_list("secret_id", flat=True).order_by(
"published"
)
# All 1001 Snippets have been created
self.assertEqual(len(set(slug_list)), 100)
@ -170,9 +170,7 @@ class SnippetTestCase(TestCase):
def test_reply(self):
data = self.valid_form_data()
response = self.client.post(self.new_url, data, follow=True)
response = self.client.post(
response.request["PATH_INFO"], data, follow=True
)
response = self.client.post(response.request["PATH_INFO"], data, follow=True)
self.assertContains(response, data["content"])
self.assertEqual(response.status_code, 200)
self.assertEqual(Snippet.objects.count(), 2)
@ -181,9 +179,7 @@ class SnippetTestCase(TestCase):
data = self.valid_form_data()
response = self.client.post(self.new_url, data, follow=True)
del data["content"]
response = self.client.post(
response.request["PATH_INFO"], data, follow=True
)
response = self.client.post(response.request["PATH_INFO"], data, follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(Snippet.objects.count(), 1)

View file

@ -36,9 +36,7 @@ urlpatterns = [
url(
r"^(?P<snippet_id>[a-zA-Z0-9]{%d,})/slim/?$" % L,
xframe_options_exempt(
views.SnippetDetailView.as_view(
template_name="dpaste/details_slim.html"
)
views.SnippetDetailView.as_view(template_name="dpaste/details_slim.html")
),
name="snippet_details_slim",
),

View file

@ -4,9 +4,5 @@ from django.views.decorators.csrf import csrf_exempt
from ..views import APIView
urlpatterns = [
url(
r"^api/$",
csrf_exempt(APIView.as_view()),
name="dpaste_api_create_snippet",
)
url(r"^api/$", csrf_exempt(APIView.as_view()), name="dpaste_api_create_snippet",)
]

View file

@ -84,9 +84,7 @@ class SnippetDetailView(DetailView, FormView):
always expire.
"""
if "delete" in self.request.POST:
snippet = get_object_or_404(
Snippet, secret_id=self.kwargs["snippet_id"]
)
snippet = get_object_or_404(Snippet, secret_id=self.kwargs["snippet_id"])
snippet.delete()
# Append `#` so #delete goes away in Firefox
@ -330,16 +328,11 @@ class APIView(View):
)
expires, expire_type = get_expire_values(expires)
else:
expires = datetime.datetime.now() + datetime.timedelta(
seconds=60 * 60 * 24
)
expires = datetime.datetime.now() + datetime.timedelta(seconds=60 * 60 * 24)
expire_type = Snippet.EXPIRE_TIME
snippet = Snippet.objects.create(
content=content,
lexer=lexer,
expires=expires,
expire_type=expire_type,
content=content, lexer=lexer, expires=expires, expire_type=expire_type,
)
# Custom formatter for the API response

View file

@ -75,7 +75,7 @@ multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=80
line_length=88
[coverage:run]
source = dpaste