From d0f7e2eda6d685433e1b4c249efab93ba5bd7210 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Wed, 8 Jan 2020 13:19:52 +0100 Subject: [PATCH] Use Black's default line length of 88 --- Makefile | 2 +- dpaste/__init__.py | 4 +-- dpaste/apps.py | 4 +-- dpaste/forms.py | 8 ++---- dpaste/highlight.py | 4 +-- .../management/commands/cleanup_snippets.py | 9 ++----- dpaste/models.py | 9 ++----- dpaste/settings/base.py | 12 +++------ dpaste/settings/tests.py | 4 +-- dpaste/tests/test_api.py | 27 +++++-------------- dpaste/tests/test_snippet.py | 14 ++++------ dpaste/urls/dpaste.py | 4 +-- dpaste/urls/dpaste_api.py | 6 +---- dpaste/views.py | 13 +++------ setup.cfg | 2 +- 15 files changed, 32 insertions(+), 90 deletions(-) diff --git a/Makefile b/Makefile index 5b8a342..a4b5d33 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/dpaste/__init__.py b/dpaste/__init__.py index 6a97310..c979bf2 100644 --- a/dpaste/__init__.py +++ b/dpaste/__init__.py @@ -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" diff --git a/dpaste/apps.py b/dpaste/apps.py index 98ef963..58d15db 100644 --- a/dpaste/apps.py +++ b/dpaste/apps.py @@ -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 diff --git a/dpaste/forms.py b/dpaste/forms.py index 3bb6848..1e94362 100644 --- a/dpaste/forms.py +++ b/dpaste/forms.py @@ -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, ) diff --git a/dpaste/highlight.py b/dpaste/highlight.py index cd3ba7c..18aae8d 100644 --- a/dpaste/highlight.py +++ b/dpaste/highlight.py @@ -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, ) ) diff --git a/dpaste/management/commands/cleanup_snippets.py b/dpaste/management/commands/cleanup_snippets.py index 740f494..d2721d6 100644 --- a/dpaste/management/commands/cleanup_snippets.py +++ b/dpaste/management/commands/cleanup_snippets.py @@ -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)) diff --git a/dpaste/models.py b/dpaste/models.py index d85568b..bf4864c 100644 --- a/dpaste/models.py +++ b/dpaste/models.py @@ -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] diff --git a/dpaste/settings/base.py b/dpaste/settings/base.py index 7fd7881..63db06f 100644 --- a/dpaste/settings/base.py +++ b/dpaste/settings/base.py @@ -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", diff --git a/dpaste/settings/tests.py b/dpaste/settings/tests.py index 36034cc..bd8821e 100644 --- a/dpaste/settings/tests.py +++ b/dpaste/settings/tests.py @@ -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 diff --git a/dpaste/tests/test_api.py b/dpaste/tests/test_api.py index f50da23..30fa3d2 100644 --- a/dpaste/tests/test_api.py +++ b/dpaste/tests/test_api.py @@ -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): """ diff --git a/dpaste/tests/test_snippet.py b/dpaste/tests/test_snippet.py index 7b38ede..c176155 100644 --- a/dpaste/tests/test_snippet.py +++ b/dpaste/tests/test_snippet.py @@ -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) diff --git a/dpaste/urls/dpaste.py b/dpaste/urls/dpaste.py index 813cd7d..601f62e 100644 --- a/dpaste/urls/dpaste.py +++ b/dpaste/urls/dpaste.py @@ -36,9 +36,7 @@ urlpatterns = [ url( r"^(?P[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", ), diff --git a/dpaste/urls/dpaste_api.py b/dpaste/urls/dpaste_api.py index f5ed723..05d64ce 100644 --- a/dpaste/urls/dpaste_api.py +++ b/dpaste/urls/dpaste_api.py @@ -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",) ] diff --git a/dpaste/views.py b/dpaste/views.py index c9af647..c8a5ade 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -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 diff --git a/setup.cfg b/setup.cfg index 3bed693..9f12619 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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