Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ class DependencyPopulator(ContentPopulator):
def populate(self, context: ContentPopulatorContext) -> None:
print("Linking dependencies...")
PackageVersion.dependencies.through.objects.all().delete()

# Ensure we have at least one dependency and one dependant
package_count = len(context.packages)
if package_count < 2:
print("Not enough packages to create dependencies.")
return

dependency_count = min(context.dependency_count, package_count - 1)
if dependency_count < 1:
dependency_count = 1

dependencies = [
x.latest.id for x in context.packages[: context.dependency_count]
x.latest.id for x in context.packages[:dependency_count]
]
dependants = context.packages[context.dependency_count :]
dependants = context.packages[dependency_count:]
for package in print_progress(dependants, len(dependants)):
package.latest.dependencies.set(dependencies)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from typing import List
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Remove unused import List

Line 1 imports List but nothing in this file uses it (F401).

Suggested fix
-from typing import List
-
 from thunderstore.community.models import PackageCategory
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from typing import List
from thunderstore.community.models import PackageCategory
🧰 Tools
🪛 Flake8 (7.3.0)

[error] 1-1: 'typing.List' imported but unused

(F401)

🪛 GitHub Actions: Build & Test

[error] 1-1: Mixed line endings detected and file was modified by pre-commit hook (mixed-line-ending).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@django/thunderstore/core/management/commands/content/package_categories.py`
at line 1, Remove the unused typing import by deleting the "from typing import
List" statement at the top of the module; the symbol List is not referenced
anywhere in this file (package_categories.py), so simply remove that import line
to satisfy the linter.


from thunderstore.community.models import PackageCategory
from thunderstore.core.management.commands.content.base import (
ContentPopulator,
ContentPopulatorContext,
)
from thunderstore.utils.iterators import print_progress


class CategoryPopulator(ContentPopulator):
categories = [
"Mods",
"Modpacks",
"Tools",
"Libraries",
"Misc",
"Audio",
"BepInEx",
"MelonLoader",
"Suits",
"Boombox Music",
"TV Videos",
"Posters",
"Equipment",
"Items",
"Monsters",
"Moons",
"Interiors",
"Furniture",
"Vehicles",
"Client-side",
"Server-side",
"Cosmetics",
"Asset Replacements",
"Translations",
"Emotes",
"Weather",
"Hazards",
"Bug Fixes",
"Performance",
"Tweaks & Quality Of Life",
]

def populate(self, context: ContentPopulatorContext) -> None:
print("Populating package categories...")
for community in print_progress(context.communities, len(context.communities)):
for name in self.categories:
slug = name.lower().replace(" ", "-").replace("&", "").replace("--", "-")
PackageCategory.objects.get_or_create(
community=community,
name=name,
defaults={"slug": slug},
)

def clear(self) -> None:
print("Deleting existing package categories...")
PackageCategory.objects.all().delete()
Comment on lines +1 to +58
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Normalize line endings to pass pre-commit

CI indicates mixed line endings in this file, and pre-commit is mutating it.

🧰 Tools
🪛 Flake8 (7.3.0)

[error] 1-1: 'typing.List' imported but unused

(F401)

🪛 GitHub Actions: Build & Test

[error] 1-1: Mixed line endings detected and file was modified by pre-commit hook (mixed-line-ending).

🪛 Ruff (0.15.6)

[warning] 12-43: Mutable default value for class attribute

(RUF012)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@django/thunderstore/core/management/commands/content/package_categories.py`
around lines 1 - 58, This file has mixed line endings causing pre-commit to
modify it; normalize the line endings to LF for the module containing class
CategoryPopulator (and its methods populate and clear) and the categories list
so pre-commit no longer mutates the file—open the file in your editor or run a
tool like dos2unix/gh or set git's eol handling (e.g., git add --renormalize .
or set core.autocrlf appropriately) to convert CRLF to LF, commit the normalized
file, and re-run the checks.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
from django.db.models import signals

from thunderstore.community.models import PackageListing
from thunderstore.community.models import PackageCategory, PackageListing
from thunderstore.core.management.commands.content.base import (
ContentPopulator,
ContentPopulatorContext,
Expand All @@ -19,11 +20,23 @@ def populate(self, context: ContentPopulatorContext) -> None:
PackageListing.post_delete, sender=PackageListing
)

community_categories = {}
for community in context.communities:
community_categories[community.id] = list(
PackageCategory.objects.filter(community=community)
)

for i, package in print_progress(
enumerate(context.packages), len(context.packages)
):
for community in context.communities:
package.get_or_create_package_listing(community)
listing = package.get_or_create_package_listing(community)

cats = community_categories.get(community.id, [])
if cats:
count = random.choices([1, 2, 3, 4, 5], weights=[40, 30, 15, 10, 5])[0]
chosen = random.sample(cats, min(count, len(cats)))
listing.categories.set(chosen)
Comment on lines +35 to +39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clear stale categories when a community has no available categories

On reruns, Line 36 skips assignment when cats is empty, so previous category relations can persist unexpectedly.

🧰 Tools
🪛 Ruff (0.15.6)

[error] 37-37: Standard pseudo-random generators are not suitable for cryptographic purposes

(S311)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@django/thunderstore/core/management/commands/content/package_listing.py`
around lines 35 - 39, The current block uses community_categories and skips
assignment when cats is empty, which leaves previous relations intact; update
the logic around the listing.categories assignment (the code that computes cats,
count, chosen and calls listing.categories.set) to explicitly clear categories
when cats is empty (e.g., call listing.categories.clear() or set an empty list)
instead of skipping assignment so stale categories are removed on reruns.


# Re-enabling previously disabled signals
signals.post_save.connect(PackageListing.post_save, sender=PackageListing)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from thunderstore.community.models import PackageCategory, PackageListingSection
from thunderstore.core.management.commands.content.base import (
ContentPopulator,
ContentPopulatorContext,
)
from thunderstore.utils.iterators import print_progress


class SectionPopulator(ContentPopulator):
def populate(self, context: ContentPopulatorContext) -> None:
print("Populating package listing sections...")
for community in print_progress(context.communities, len(context.communities)):

def get_cat(slug):
return PackageCategory.objects.get(community=community, slug=slug)

# Define sections
# Note: Higher priority value means the section is shown first (descending sort).
sections_data = [
{
"name": "Mods",
"slug": "mods",
"priority": 100,
"exclude": ["modpacks", "asset-replacements"],
"require": [],
},
{
"name": "Asset Replacements",
"slug": "asset-replacements",
"priority": 90,
"exclude": ["modpacks"],
"require": ["asset-replacements"],
},
{
"name": "Tools",
"slug": "tools",
"priority": 85,
"exclude": ["modpacks"],
"require": ["tools"],
},
{
"name": "APIs & Libraries",
"slug": "libraries",
"priority": 80,
"exclude": ["modpacks"],
"require": ["libraries"],
},
{
"name": "Modpacks",
"slug": "modpacks",
"priority": 70,
"exclude": [],
"require": ["modpacks"],
},
]

for s_data in sections_data:
section, created = PackageListingSection.objects.get_or_create(
community=community,
slug=s_data["slug"],
defaults={
"name": s_data["name"],
"priority": s_data["priority"],
},
)

if created:
for ex_slug in s_data["exclude"]:
try:
cat = get_cat(ex_slug)
section.exclude_categories.add(cat)
except PackageCategory.DoesNotExist:
print(f"Warning: Category {ex_slug} not found for section {s_data['slug']}")

for req_slug in s_data["require"]:
try:
cat = get_cat(req_slug)
section.require_categories.add(cat)
except PackageCategory.DoesNotExist:
print(f"Warning: Category {req_slug} not found for section {s_data['slug']}")
Comment on lines +57 to +80
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Section definitions are not synced for existing rows

Because updates are gated behind if created (Line 67), reruns won’t update name, priority, or category filters for existing sections.

Suggested fix
-                section, created = PackageListingSection.objects.get_or_create(
+                section, _created = PackageListingSection.objects.get_or_create(
                     community=community,
                     slug=s_data["slug"],
                     defaults={
                         "name": s_data["name"],
                         "priority": s_data["priority"],
                     },
                 )
-
-                if created:
-                    for ex_slug in s_data["exclude"]:
-                        try:
-                            cat = get_cat(ex_slug)
-                            section.exclude_categories.add(cat)
-                        except PackageCategory.DoesNotExist:
-                            print(f"Warning: Category {ex_slug} not found for section {s_data['slug']}")
-
-                    for req_slug in s_data["require"]:
-                        try:
-                            cat = get_cat(req_slug)
-                            section.require_categories.add(cat)
-                        except PackageCategory.DoesNotExist:
-                            print(f"Warning: Category {req_slug} not found for section {s_data['slug']}")
+                section.name = s_data["name"]
+                section.priority = s_data["priority"]
+                section.save(update_fields=["name", "priority"])
+
+                exclude_cats = []
+                for ex_slug in s_data["exclude"]:
+                    try:
+                        exclude_cats.append(get_cat(ex_slug))
+                    except PackageCategory.DoesNotExist:
+                        print(f"Warning: Category {ex_slug} not found for section {s_data['slug']}")
+
+                require_cats = []
+                for req_slug in s_data["require"]:
+                    try:
+                        require_cats.append(get_cat(req_slug))
+                    except PackageCategory.DoesNotExist:
+                        print(f"Warning: Category {req_slug} not found for section {s_data['slug']}")
+
+                section.exclude_categories.set(exclude_cats)
+                section.require_categories.set(require_cats)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@django/thunderstore/core/management/commands/content/package_sections.py`
around lines 57 - 80, The current logic only handles creations because the
update code is inside the "if created" branch, so existing PackageListingSection
rows never get their name, priority, or exclude/require category filters
updated; change the code to always set section.name and section.priority and
save the section (regardless of created), and then synchronise the M2M relations
for exclude_categories and require_categories by resolving s_data["exclude"] and
s_data["require"] via get_cat into a list (skipping/logging
PackageCategory.DoesNotExist) and then replace the relations (e.g., clear() then
add() or set([...])) instead of only adding when created so re-runs update
existing PackageListingSection records correctly.


def clear(self) -> None:
print("Deleting existing package listing sections...")
PackageListingSection.objects.all().delete()
Comment on lines +1 to +84
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Normalize line endings in this file

Pipeline shows mixed line endings and pre-commit auto-modifies this file.

🧰 Tools
🪛 GitHub Actions: Build & Test

[error] 1-1: Mixed line endings detected and file was modified by pre-commit hook (mixed-line-ending).

🪛 Ruff (0.15.6)

[warning] 15-15: Function definition does not bind loop variable community

(B023)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@django/thunderstore/core/management/commands/content/package_sections.py`
around lines 1 - 84, The file has mixed line endings causing pre-commit
normalization failures; open the file containing the SectionPopulator class
(methods populate and clear, references to PackageListingSection and
PackageCategory), convert all CRLF to LF (Unix) line endings, save and re-commit
the file so git records the normalized endings; optionally run a tool like
dos2unix or set core.autocrlf/.gitattributes and re-stage the file before
committing to ensure pre-commit no longer modifies it.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@
DependencyPopulator,
)
from thunderstore.core.management.commands.content.package import PackagePopulator
from thunderstore.core.management.commands.content.package_categories import (
CategoryPopulator,
)
from thunderstore.core.management.commands.content.package_listing import (
ListingPopulator,
)
from thunderstore.core.management.commands.content.package_sections import (
SectionPopulator,
)
from thunderstore.core.management.commands.content.package_version import (
PackageVersionPopulator,
)
Expand All @@ -42,6 +48,8 @@
[
("community", CommunityPopulator),
("community_site", CommunitySitePopulator),
("category", CategoryPopulator),
("section", SectionPopulator),
("team", TeamPopulator),
("package", PackagePopulator),
("version", PackageVersionPopulator),
Expand Down
Loading