modforge-cli 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ """
2
+ ModForge-CLI - A CLI tool for building and managing Minecraft modpacks
3
+ """
4
+
5
+ __version__ = "0.1.0"
@@ -0,0 +1,8 @@
1
+ """
2
+ __main__.py - Entry point for the ModForge-CLI CLI
3
+ """
4
+
5
+ from modforge_cli.cli import main
6
+
7
+ if __name__ == "__main__":
8
+ main()
@@ -0,0 +1,5 @@
1
+ """
2
+ Auto-generated file. DO NOT EDIT.
3
+ """
4
+ __version__ = "0.1.5"
5
+ __author__ = "Frank1o3"
@@ -0,0 +1,7 @@
1
+ """
2
+ api package - Exposes the Modrinth API client globally.
3
+ """
4
+
5
+ from .modrinth import ModrinthAPIConfig
6
+
7
+ __all__ = ["ModrinthAPIConfig"]
@@ -0,0 +1,218 @@
1
+ """
2
+ api/modrith_api.py - Modrinth API v2 URL builder using modrinth_api.json
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ from pathlib import Path
9
+ from typing import Any, Dict, List, Optional
10
+ from urllib.parse import quote_plus
11
+
12
+
13
+ class ModrinthAPIConfig:
14
+ """Loads modrinth_api.json and builds Modrinth API URLs."""
15
+
16
+ def __init__(self, config_path: str | Path = "configs/modrinth_api.json"):
17
+ self.config_path = config_path if isinstance(config_path, Path) else Path(config_path)
18
+ self.base_url: str = ""
19
+ self.endpoints: Dict[str, Any] = {}
20
+ self._load_config()
21
+
22
+ def _load_config(self) -> None:
23
+ if not self.config_path.exists():
24
+ raise FileNotFoundError(
25
+ f"Modrinth API config not found: {self.config_path}"
26
+ )
27
+
28
+ with open(self.config_path, "r", encoding="utf-8") as f:
29
+ data = json.load(f)
30
+
31
+ self.base_url = data.get("BASE_URL", "").rstrip("/")
32
+ if not self.base_url:
33
+ raise ValueError("BASE_URL missing in modrinth_api.json")
34
+
35
+ self.endpoints = data.get("ENDPOINTS", {})
36
+ if not isinstance(self.endpoints, Dict):
37
+ raise ValueError("ENDPOINTS section is invalid")
38
+
39
+ def build_url(self, template: str, **kwargs: str) -> str:
40
+ """Format a template string with kwargs and prepend base URL."""
41
+ try:
42
+ path = template.format(**kwargs)
43
+ return f"{self.base_url}{path}"
44
+ except KeyError as e:
45
+ raise ValueError(f"Missing URL parameter: {e}")
46
+
47
+ # === Search ===
48
+
49
+ def search(
50
+ self,
51
+ query: Optional[str] = None,
52
+ facets: Optional[List[List[str]] | str] = None,
53
+ categories: Optional[List[str]] = None,
54
+ loaders: Optional[List[str]] = None,
55
+ game_versions: Optional[List[str]] = None,
56
+ license_: Optional[str] = None,
57
+ project_type: Optional[str] = None,
58
+ offset: Optional[int] = None,
59
+ limit: Optional[int] = 10,
60
+ index: Optional[str] = "relevance",
61
+ ) -> str:
62
+ """
63
+ Build the Modrinth search URL with query parameters.
64
+
65
+ Docs: https://docs.modrinth.com/api-spec#endpoints-search
66
+
67
+ Facets format: [[inner AND], [inner AND]] = outer OR
68
+ Example: [["categories:performance"], ["project_type:mod"]]
69
+
70
+ Args:
71
+ query: Search term (e.g., "sodium")
72
+ facets: Advanced filters as list of lists or JSON string
73
+ categories: Filter by categories (e.g., ["performance"])
74
+ loaders: Filter by loaders (e.g., ["fabric", "quilt"])
75
+ game_versions: Filter by Minecraft versions (e.g., ["1.21.1"])
76
+ license_: Filter by license (e.g., "MIT")
77
+ project_type: "mod", "resourcepack", "shader", "modpack", "datapack"
78
+ offset: Pagination offset
79
+ limit: Results per page (max 100)
80
+ index: Sort by "relevance", "downloads", "updated", "newest"
81
+
82
+ Returns:
83
+ Full search URL with query parameters
84
+ """
85
+ base = self.build_url(self.endpoints["search"])
86
+ params = []
87
+ if query:
88
+ params.append(f"query={quote_plus(query)}")
89
+
90
+ facets_array = []
91
+ if facets:
92
+ if isinstance(facets, str):
93
+ params.append(f"facets={quote_plus(facets)}")
94
+ else:
95
+ facets_array.extend(facets)
96
+
97
+ if project_type:
98
+ facets_array.append([f"project_type:{project_type}"])
99
+ if categories:
100
+ [facets_array.append([f"categories:{c}"]) for c in categories]
101
+ if loaders:
102
+ facets_array.append([f"categories:{l}" for l in loaders])
103
+ if game_versions:
104
+ facets_array.append([f"versions:{v}" for v in game_versions])
105
+ if license_:
106
+ facets_array.append([f"license:{license_}"])
107
+
108
+ if facets_array and not (isinstance(facets, str)):
109
+ params.append(f"facets={quote_plus(json.dumps(facets_array))}")
110
+
111
+ if offset is not None:
112
+ params.append(f"offset={offset}")
113
+ if limit is not None:
114
+ params.append(f"limit={min(limit, 100)}")
115
+ if index:
116
+ params.append(f"index={index}")
117
+
118
+ return f"{base}?{'&'.join(params)}" if params else base
119
+
120
+ # === Projects ===
121
+
122
+ def project(self, project_id: str) -> str:
123
+ return self.build_url(self.endpoints["projects"]["project"], id=project_id)
124
+
125
+ def project_versions(self, project_id: str) -> str:
126
+ return self.build_url(
127
+ self.endpoints["projects"]["project_versions"], id=project_id
128
+ )
129
+
130
+ def project_dependencies(self, project_id: str) -> str:
131
+ return self.build_url(self.endpoints["projects"]["dependencies"], id=project_id)
132
+
133
+ def project_gallery(self, project_id: str) -> str:
134
+ return self.build_url(self.endpoints["projects"]["gallery"], id=project_id)
135
+
136
+ def project_icon(self, project_id: str) -> str:
137
+ return self.build_url(self.endpoints["projects"]["icon"], id=project_id)
138
+
139
+ def check_following(self, project_id: str) -> str:
140
+ return self.build_url(
141
+ self.endpoints["projects"]["check_following"], id=project_id
142
+ )
143
+
144
+ # === Versions ===
145
+
146
+ def version(self, version_id: str) -> str:
147
+ return self.build_url(self.endpoints["versions"]["version"], id=version_id)
148
+
149
+ def version_files(self, version_id: str) -> str:
150
+ return self.build_url(self.endpoints["versions"]["files"], id=version_id)
151
+
152
+ def version_file_download(self, version_id: str, filename: str) -> str:
153
+ return self.build_url(
154
+ self.endpoints["versions"]["download"], id=version_id, filename=filename
155
+ )
156
+
157
+ def file_by_hash(self, hash_: str) -> str:
158
+ return self.build_url(self.endpoints["versions"]["file_by_hash"], hash=hash_)
159
+
160
+ def versions_by_hash(self, hash_: str) -> str:
161
+ return self.build_url(
162
+ self.endpoints["versions"]["versions_by_hash"], hash=hash_
163
+ )
164
+
165
+ def latest_version_for_hash(self, hash_: str, algorithm: str = "sha1") -> str:
166
+ return self.build_url(
167
+ self.endpoints["versions"]["latest_for_hash"], hash=hash_, algo=algorithm
168
+ )
169
+
170
+ # === Tags ===
171
+
172
+ def categories(self) -> str:
173
+ return self.build_url(self.endpoints["tags"]["categories"])
174
+
175
+ def loaders(self) -> str:
176
+ return self.build_url(self.endpoints["tags"]["loaders"])
177
+
178
+ def game_versions(self) -> str:
179
+ return self.build_url(self.endpoints["tags"]["game_versions"])
180
+
181
+ def licenses(self) -> str:
182
+ return self.build_url(self.endpoints["tags"]["licenses"])
183
+
184
+ def environments(self) -> str:
185
+ return self.build_url(self.endpoints["tags"]["environments"])
186
+
187
+ # === Teams ===
188
+
189
+ def team(self, team_id: str) -> str:
190
+ return self.build_url(self.endpoints["teams"]["team"], id=team_id)
191
+
192
+ def team_members(self, team_id: str) -> str:
193
+ return self.build_url(self.endpoints["teams"]["members"], id=team_id)
194
+
195
+ # === User ===
196
+
197
+ def user(self, user_id: str) -> str:
198
+ return self.build_url(self.endpoints["user"]["user"], id=user_id)
199
+
200
+ def user_projects(self, user_id: str) -> str:
201
+ return self.build_url(self.endpoints["user"]["user_projects"], id=user_id)
202
+
203
+ def user_notifications(self, user_id: str) -> str:
204
+ return self.build_url(self.endpoints["user"]["notifications"], id=user_id)
205
+
206
+ def user_avatar(self, user_id: str) -> str:
207
+ return self.build_url(self.endpoints["user"]["avatar"], id=user_id)
208
+
209
+ # === Bulk ===
210
+
211
+ def bulk_projects(self) -> str:
212
+ return self.build_url(self.endpoints["bulk"]["projects"])
213
+
214
+ def bulk_versions(self) -> str:
215
+ return self.build_url(self.endpoints["bulk"]["versions"])
216
+
217
+ def bulk_version_files(self) -> str:
218
+ return self.build_url(self.endpoints["bulk"]["version_files"])