@@ -28,6 +28,7 @@ def __init__(self, *args, **kwargs):
28
28
super ().__init__ (* args , ** kwargs )
29
29
30
30
self .__path = None
31
+ self .__fields = None
31
32
32
33
@property
33
34
def path (self ):
@@ -44,6 +45,24 @@ def path(self):
44
45
45
46
return self .__path
46
47
48
+ @property
49
+ def fields (self ):
50
+ if self .__fields is None :
51
+ fields = self .config .get ("fields" , None )
52
+ if fields is None :
53
+ self .__fields = None
54
+ else :
55
+ if not (
56
+ isinstance (fields , list ) and all (isinstance (f , str ) for f in fields )
57
+ ):
58
+ raise TypeError (
59
+ "Option `fields` for build hook `{}` must be a list of strings" .format (
60
+ self .PLUGIN_NAME
61
+ )
62
+ )
63
+ self .__fields = set (fields )
64
+ return self .__fields
65
+
47
66
def load_package_data (self ):
48
67
path = os .path .normpath (os .path .join (self .root , self .path ))
49
68
if not os .path .isfile (path ):
@@ -92,24 +111,24 @@ def _parse_repository(self, repository: str | dict[str, str]) -> str:
92
111
def update (self , metadata : dict [str , Any ]):
93
112
package = self .load_package_data ()
94
113
95
- metadata [ "name" ] = package ["name" ]
114
+ new_metadata = { "name" : package ["name" ]}
96
115
97
116
if "author" in package :
98
- metadata ["author" ] = self ._parse_person (package ["author" ])
117
+ new_metadata ["author" ] = self ._parse_person (package ["author" ])
99
118
100
119
if "contributors" in package :
101
- metadata ["maintainers" ] = [
120
+ new_metadata ["maintainers" ] = [
102
121
self ._parse_person (p ) for p in package ["contributors" ]
103
122
]
104
123
105
124
if "keywords" in package :
106
- metadata ["keywords" ] = package ["keywords" ]
125
+ new_metadata ["keywords" ] = package ["keywords" ]
107
126
108
127
if "description" in package :
109
- metadata ["description" ] = package ["description" ]
128
+ new_metadata ["description" ] = package ["description" ]
110
129
111
130
if "license" in package :
112
- metadata ["license" ] = package ["license" ]
131
+ new_metadata ["license" ] = package ["license" ]
113
132
114
133
# Construct URLs
115
134
urls = {}
@@ -124,4 +143,13 @@ def update(self, metadata: dict[str, Any]):
124
143
125
144
# Write URLs
126
145
if urls :
127
- metadata ["urls" ] = urls
146
+ new_metadata ["urls" ] = urls
147
+
148
+ # Only use required metadata
149
+ metadata .update (
150
+ {
151
+ k : v
152
+ for k , v in new_metadata .items ()
153
+ if (self .fields is None or k in self .fields )
154
+ }
155
+ )
0 commit comments