1818"""Migration models V8."""
1919
2020import os
21+ from pathlib import Path
2122
2223from marshmallow import EXCLUDE , pre_dump
2324
2425from renku .core .models import jsonld
2526from renku .core .models .calamus import Uri , fields , schema
27+ from renku .core .models .entities import generate_file_id
2628
2729from .v3 import CreatorMixinSchemaV3 , DatasetTagSchemaV3 , EntitySchemaV3 , LanguageSchemaV3 , PersonSchemaV3 , UrlSchemaV3
2830from .v7 import Base , DatasetFileSchemaV7
2931
3032
33+ class DatasetFile (Base ):
34+ """DatasetFile migration model."""
35+
36+ def __init__ (self , ** kwargs ):
37+ """Initialize an instance."""
38+ super ().__init__ (** kwargs )
39+
40+ if hasattr (self , "path" ) and (not self ._id or self ._id .startswith ("_:" )):
41+ hexsha = "UNCOMMITTED"
42+ if self .client and Path (self .path ).exists ():
43+ hexsha = self .client .find_previous_commit ().hexsha
44+
45+ self ._id = generate_file_id (client = self .client , hexsha = hexsha , path = self .path )
46+
47+
3148class Dataset (Base ):
3249 """Dataset migration model."""
3350
@@ -43,11 +60,25 @@ def to_yaml(self, path=None):
4360 """Write content to a YAML file."""
4461 from renku .core .management import LocalClient
4562
63+ for file_ in self .files :
64+ file_ ._project = self ._project
65+
4666 data = DatasetSchemaV8 (flattened = True ).dump (self )
4767 path = path or self ._metadata_path or os .path .join (self .path , LocalClient .METADATA )
4868 jsonld .write_yaml (path = path , data = data )
4969
5070
71+ class DatasetFileSchemaV8 (DatasetFileSchemaV7 ):
72+ """DatasetFile schema."""
73+
74+ class Meta :
75+ """Meta class."""
76+
77+ rdf_type = schema .DigitalDocument
78+ model = DatasetFile
79+ unknown = EXCLUDE
80+
81+
5182class DatasetSchemaV8 (CreatorMixinSchemaV3 , EntitySchemaV3 ):
5283 """Dataset schema."""
5384
@@ -62,7 +93,7 @@ class Meta:
6293 date_created = fields .DateTime (schema .dateCreated , missing = None )
6394 date_published = fields .DateTime (schema .datePublished , missing = None )
6495 description = fields .String (schema .description , missing = None )
65- files = fields .Nested (schema .hasPart , DatasetFileSchemaV7 , many = True )
96+ files = fields .Nested (schema .hasPart , DatasetFileSchemaV8 , many = True )
6697 identifier = fields .String (schema .identifier )
6798 in_language = fields .Nested (schema .inLanguage , LanguageSchemaV3 , missing = None )
6899 keywords = fields .List (schema .keywords , fields .String ())
0 commit comments