aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2023-05-10 12:30:57 +0200
committerGravatar Johannes Christ <[email protected]>2023-05-10 12:48:51 +0200
commit07855963a1eedd80c410ab2dd51fcae1200c9cee (patch)
tree9ed264f9c5dacd44c4382a6c8d73e56a16af5234 /pydis_site/apps/content
parentMerge pull request #966 from python-discord/dependabot/pip/flake8-bugbear-23.5.9 (diff)
Switch to ruff for linting
Diffstat (limited to 'pydis_site/apps/content')
-rw-r--r--pydis_site/apps/content/models/tag.py3
-rw-r--r--pydis_site/apps/content/resources/guides/pydis-guides/contributing/linting.md2
-rw-r--r--pydis_site/apps/content/tests/helpers.py20
-rw-r--r--pydis_site/apps/content/urls.py2
-rw-r--r--pydis_site/apps/content/utils.py16
-rw-r--r--pydis_site/apps/content/views/tags.py3
6 files changed, 23 insertions, 23 deletions
diff --git a/pydis_site/apps/content/models/tag.py b/pydis_site/apps/content/models/tag.py
index 1a20d775..7c49902f 100644
--- a/pydis_site/apps/content/models/tag.py
+++ b/pydis_site/apps/content/models/tag.py
@@ -30,8 +30,7 @@ class Commit(models.Model):
def lines(self) -> collections.abc.Iterable[str]:
"""Return each line in the commit message."""
- for line in self.message.split("\n"):
- yield line
+ yield from self.message.split("\n")
def format_authors(self) -> collections.abc.Iterable[str]:
"""Return a nice representation of the author(s)' name and email."""
diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/linting.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/linting.md
index f6f8a5f2..b634f513 100644
--- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/linting.md
+++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/linting.md
@@ -4,7 +4,7 @@ description: A guide for linting and setting up pre-commit.
---
Your commit will be rejected by the build server if it fails to lint.
-On most of our projects, we use `flake8` and `pre-commit` to ensure that the code style is consistent across the code base.
+On most of our projects, we use `ruff` and `pre-commit` to ensure that the code style is consistent across the code base.
`pre-commit` is a powerful tool that helps you automatically lint before you commit.
If the linter complains, the commit is aborted so that you can fix the linting errors before committing again.
diff --git a/pydis_site/apps/content/tests/helpers.py b/pydis_site/apps/content/tests/helpers.py
index fad91050..0e7562e8 100644
--- a/pydis_site/apps/content/tests/helpers.py
+++ b/pydis_site/apps/content/tests/helpers.py
@@ -62,19 +62,19 @@ class MockPagesTestCase(TestCase):
├── not_a_page.md
├── tmp.md
├── tmp
- |   ├── _info.yml
- |   └── category
- |    ├── _info.yml
- |      └── subcategory_without_info
+ | ├── _info.yml
+ | └── category
+ | ├── _info.yml
+ | └── subcategory_without_info
└── category
-    ├── _info.yml
-    ├── with_metadata.md
-    └── subcategory
-    ├── with_metadata.md
-       └── without_metadata.md
+ ├── _info.yml
+ ├── with_metadata.md
+ └── subcategory
+ ├── with_metadata.md
+ └── without_metadata.md
"""
- def setUp(self):
+ def setUp(self) -> None:
"""Create the fake filesystem."""
Path(f"{BASE_PATH}/_info.yml").write_text(CATEGORY_INFO)
Path(f"{BASE_PATH}/root.md").write_text(MARKDOWN_WITH_METADATA)
diff --git a/pydis_site/apps/content/urls.py b/pydis_site/apps/content/urls.py
index a7695a27..baae154d 100644
--- a/pydis_site/apps/content/urls.py
+++ b/pydis_site/apps/content/urls.py
@@ -8,7 +8,7 @@ from . import utils, views
app_name = "content"
-def __get_all_files(root: Path, folder: typing.Optional[Path] = None) -> list[str]:
+def __get_all_files(root: Path, folder: Path | None = None) -> list[str]:
"""Find all folders and markdown files recursively starting from `root`."""
if not folder:
folder = root
diff --git a/pydis_site/apps/content/utils.py b/pydis_site/apps/content/utils.py
index c12893ef..347640dd 100644
--- a/pydis_site/apps/content/utils.py
+++ b/pydis_site/apps/content/utils.py
@@ -151,8 +151,11 @@ def set_tag_commit(tag: Tag) -> None:
commit = data["commit"]
author, committer = commit["author"], commit["committer"]
- date = datetime.datetime.strptime(committer["date"], settings.GITHUB_TIMESTAMP_FORMAT)
- date = date.replace(tzinfo=datetime.timezone.utc)
+ date = (
+ datetime.datetime
+ .strptime(committer["date"], settings.GITHUB_TIMESTAMP_FORMAT)
+ .replace(tzinfo=datetime.timezone.utc)
+ )
if author["email"] == committer["email"]:
authors = [author]
@@ -212,9 +215,8 @@ def get_tags() -> list[Tag]:
record_tags(tags)
return tags
- else:
- # Get tags from database
- return list(Tag.objects.all())
+
+ return list(Tag.objects.all())
def get_tag(path: str, *, skip_sync: bool = False) -> Tag | list[Tag]:
@@ -242,13 +244,13 @@ def get_tag(path: str, *, skip_sync: bool = False) -> Tag | list[Tag]:
if tag.last_commit is None and not skip_sync:
set_tag_commit(tag)
return tag
- elif tag.group == name and group is None:
+ elif tag.group == name and group is None: # noqa: RET505
matches.append(tag)
if matches:
return matches
- raise Tag.DoesNotExist()
+ raise Tag.DoesNotExist
def get_tag_category(tags: list[Tag] | None = None, *, collapse_groups: bool) -> dict[str, dict]:
diff --git a/pydis_site/apps/content/views/tags.py b/pydis_site/apps/content/views/tags.py
index 4f4bb5a2..8d3e3321 100644
--- a/pydis_site/apps/content/views/tags.py
+++ b/pydis_site/apps/content/views/tags.py
@@ -1,5 +1,4 @@
import re
-import typing
import frontmatter
import markdown
@@ -22,7 +21,7 @@ COMMAND_REGEX = re.compile(r"`*!tags? (?P<first>[\w-]+)(?P<second> [\w-]+)?`*")
class TagView(TemplateView):
"""Handles tag pages."""
- tag: typing.Union[Tag, list[Tag]]
+ tag: Tag | list[Tag]
is_group: bool
def setup(self, *args, **kwargs) -> None: