@@ -70,6 +70,23 @@ def deserialize(cls, raw_data: dict) -> 'ProjectInfo':
70
70
71
71
return instance
72
72
73
+ def serialize (self , ** kwargs ) -> dict :
74
+ """
75
+ Serializes project info.
76
+
77
+ Args:
78
+ **kwargs: serialization settings.
79
+
80
+ Notes:
81
+ Not all project versions use all settings.
82
+ Possible kwargs options:
83
+ `is_initial` - Flag of the initial serialization of project information.
84
+
85
+ Returns:
86
+ Project info in the form of a dictionary.
87
+ """
88
+ return super ().serialize ()
89
+
73
90
74
91
@VERSION_REGISTRY .register
75
92
class ProjectInfoV1 (ProjectInfo ):
@@ -83,3 +100,35 @@ class ProjectInfoV2(ProjectInfo):
83
100
ProjectConfig = ProjectConfigV2
84
101
DockerConfig = DockerConfigV2
85
102
VERSION = 2
103
+
104
+ def __init__ (self , project_name : str , main : str = DEFAULT_MAIN ):
105
+ super ().__init__ (project_name , main )
106
+ self .serialization_settings = {}
107
+
108
+ def serialize (self , ** kwargs ) -> dict :
109
+ is_initial = kwargs .get ('is_initial' , False )
110
+ serialized_data = super ().serialize ()
111
+
112
+ if is_initial or self .serialization_settings .get (self .DOCKER_LABEL , {}).get ('ignore_username' , False ):
113
+ self .serialization_settings .setdefault (self .DOCKER_LABEL , {})
114
+ self .serialization_settings [self .DOCKER_LABEL ]['ignore_username' ] = True
115
+ del serialized_data [self .CONFIG_LABEL ][self .DOCKER_LABEL ]['username' ]
116
+
117
+ del serialized_data ['serialization_settings' ]
118
+
119
+ return serialized_data
120
+
121
+ @classmethod
122
+ def deserialize (cls , raw_data : dict ) -> 'ProjectInfoV2' :
123
+ if raw_data .get (cls .CONFIG_LABEL , {}).get (cls .DOCKER_LABEL , {}).get ('username' ) is None :
124
+ docker_username_is_missing = True
125
+ else :
126
+ docker_username_is_missing = False
127
+
128
+ obj = super ().deserialize (raw_data )
129
+
130
+ if docker_username_is_missing :
131
+ obj .serialization_settings .setdefault (cls .DOCKER_LABEL , {})
132
+ obj .serialization_settings [cls .DOCKER_LABEL ]['ignore_username' ] = True
133
+
134
+ return obj
0 commit comments