1313from beet import Context , InvalidProjectConfig , PluginOptions , TextFile , load_config , Function
1414from beet .library .base import _dump_files # type: ignore ; private method used to deterministicify pack dumping
1515from nbtlib .contrib .minecraft import StructureFileData , StructureFile # type: ignore ; no stub
16- from pydantic . v1 import BaseModel , Extra
16+ from pydantic import BaseModel
1717from repro_zipfile import ReproducibleZipFile # type: ignore ; no stub
1818
1919from gm4 .plugins .versioning import VersioningConfig
@@ -41,17 +41,17 @@ class SmithedConfig(PluginOptions):
4141class PMCConfig (PluginOptions ):
4242 uid : int
4343
44- class ManifestConfig (PluginOptions , extra = Extra . ignore ):
44+ class ManifestConfig (PluginOptions , extra = " ignore" ):
4545 minecraft : list [str ] = SUPPORTED_GAME_VERSIONS
46- versioning : Optional [VersioningConfig ]
46+ versioning : Optional [VersioningConfig ] = None
4747 # distribution
48- website : Optional [WebsiteConfig ]
49- modrinth : Optional [ModrinthConfig ]
50- smithed : Optional [SmithedConfig ]
51- pmc : Optional [PMCConfig ]
48+ website : Optional [WebsiteConfig ] = None
49+ modrinth : Optional [ModrinthConfig ] = None
50+ smithed : Optional [SmithedConfig ] = None
51+ pmc : Optional [PMCConfig ] = None
5252 # promo
53- video : str | None
54- wiki : str | None
53+ video : str | None = None
54+ wiki : str | None = None
5555 credits : CreditsModel
5656
5757# models for meta.json and cached manifest
@@ -102,7 +102,7 @@ def create(ctx: Context):
102102 for pack_id in [p .name for p in sorted (ctx .directory .glob (glob ))]:
103103 try :
104104 config = load_config (Path (pack_id ) / "beet.yaml" )
105- gm4_meta = ctx .validate ("gm4" , validator = ManifestConfig , options = config .meta ["gm4" ]) # manually parse config into models
105+ gm4_meta = ctx .validate ("gm4" , validator = ManifestConfig , options = config .meta ["gm4" ]) # manually parse config into models
106106
107107 manifest_section [pack_id ] = ManifestModuleModel (
108108 id = config .id ,
@@ -142,7 +142,7 @@ def create(ctx: Context):
142142 manifest .base = {"version" : base_config ["version" ]}
143143
144144 # Cache the new manifest, so sub-pipelines can access it
145- ctx .cache ["gm4_manifest" ].json = manifest .dict ()
145+ ctx .cache ["gm4_manifest" ].json = manifest .model_dump ()
146146
147147 # Read in the previous manifest, if found
148148 version = os .getenv ("VERSION" , "1.21.5" )
@@ -158,21 +158,21 @@ def create(ctx: Context):
158158 sys .exit (1 ) # quit the build and mark the github action as failed
159159 else :
160160 logger .warning ("No existing meta.json manifest file was located" )
161- ctx .cache ["previous_manifest" ].json = ManifestFileModel (last_commit = "" ,modules = [],libraries = {},contributors = []).dict ()
161+ ctx .cache ["previous_manifest" ].json = ManifestFileModel (last_commit = "" ,modules = [],libraries = {},contributors = []).model_dump ()
162+
162163
163-
164164
165165def update_patch (ctx : Context ):
166166 """Checks the datapack files for changes from last build, and increments patch number"""
167167 yield
168168 logger = parent_logger .getChild ("update_patch" )
169169
170170 # load current manifest from cache
171- this_manifest = ManifestCacheModel .parse_obj (ctx .cache ["gm4_manifest" ].json )
171+ this_manifest = ManifestCacheModel .model_validate (ctx .cache ["gm4_manifest" ].json )
172172 pack = ({e .id :e for e in (this_manifest .libraries | this_manifest .modules ).values ()})[ctx .project_id ]
173173
174174 # attempt to load prior meta.json manifest
175- last_manifest = ManifestFileModel .parse_obj (ctx .cache ["previous_manifest" ].json )
175+ last_manifest = ManifestFileModel .model_validate (ctx .cache ["previous_manifest" ].json )
176176 released_modules : dict [str , ManifestModuleModel ] = {m .id :m for m in last_manifest .modules if m .version }| {l .id :l for l in last_manifest .libraries .values ()}
177177
178178 # determine this modules status
@@ -214,7 +214,7 @@ def update_patch(ctx: Context):
214214 else : # no changes, keep the patch
215215 pack .version = released .version
216216
217- ctx .cache ["gm4_manifest" ].json = this_manifest .dict ()
217+ ctx .cache ["gm4_manifest" ].json = this_manifest .model_dump ()
218218
219219
220220def write_meta (ctx : Context ):
@@ -232,7 +232,7 @@ def write_meta(ctx: Context):
232232
233233def write_credits (ctx : Context ):
234234 """Writes the credits metadata to CREDITS.md. and collects for README.md"""
235- manifest = ManifestCacheModel .parse_obj (ctx .cache ["gm4_manifest" ].json )
235+ manifest = ManifestCacheModel .model_validate (ctx .cache ["gm4_manifest" ].json )
236236 contributors = manifest .contributors
237237 module = manifest .modules .get (ctx .project_id )
238238 credits = module .credits if module else {}
@@ -254,7 +254,7 @@ def write_credits(ctx: Context):
254254 linked_credits [title ].append (f"[{ name } ]({ links [0 ]} )" )
255255 else :
256256 linked_credits [title ].append (f"{ name } " )
257-
257+
258258 # format credits for CREDITS.md
259259 text = "# Credits\n "
260260 for title in linked_credits :
@@ -277,7 +277,7 @@ def write_update_function(init: Optional[Function], ctx: Context):
277277 if not init :
278278 return
279279
280- manifest = ManifestCacheModel .parse_obj (ctx .cache ["gm4_manifest" ].json )
280+ manifest = ManifestCacheModel .model_validate (ctx .cache ["gm4_manifest" ].json )
281281 modules = manifest .modules
282282
283283 score = f"{ ctx .project_id .removeprefix ('gm4_' )} gm4_modules"
@@ -309,7 +309,7 @@ def write_update_function(init: Optional[Function], ctx: Context):
309309
310310def repro_structure_to_bytes (content : StructureFileData ) -> bytes :
311311 """a modified Structure.to_bytes from beet, which ensures the GZip does not add
312- the current time.time to the nbt file header.
312+ the current time.time to the nbt file header.
313313 Used for deterministic pack builds and auto-patch detection"""
314314 dst = BytesIO ()
315315 with GzipFile (fileobj = dst , mode = "wb" , mtime = 0 ) as fileobj :
0 commit comments