MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / parse_gosum

Function parse_gosum

src/packagedcode/go_mod.py:206–255  ·  view source on GitHub ↗

Return a list of GoSum from parsing the go.sum file at `location`. Handles go.sum file from Go. See https://blog.golang.org/using-go-modules for details A go.sum file contains pinned Go modules checksums of two styles: For example:: github.com/BurntSushi/toml v0.3.1 h1:

(location)

Source from the content-addressed store, hash-verified

204
205
206def parse_gosum(location):
207 """
208 Return a list of GoSum from parsing the go.sum file at `location`.
209
210 Handles go.sum file from Go.
211
212 See https://blog.golang.org/using-go-modules for details
213
214 A go.sum file contains pinned Go modules checksums of two styles:
215
216 For example::
217
218 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
219 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
220
221 ... where the line with /go.mod is for a check of that go.mod file
222 and the other line contains a dirhash for that path as documented as
223 https://pkg.go.dev/golang.org/x/mod/sumdb/dirhash
224
225 For example::
226
227 >>> p = get_dependency('github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=')
228 >>> assert p.group('ns_name') == ('github.com/BurntSushi/toml')
229 >>> assert p.group('version') == ('v0.3.1')
230 >>> assert p.group('checksum') == ('WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=')
231 """
232 with io.open(location, encoding='utf-8', closefd=True) as data:
233 lines = data.readlines()
234
235 gosums = []
236
237 for line in lines:
238 line = line.replace('/go.mod', '')
239 parsed_dep = get_dependency(line)
240
241 ns_name = parsed_dep.group('ns_name')
242 namespace, _, name = ns_name.rpartition('/')
243
244 dep = GoModule(
245 namespace=namespace,
246 name=name,
247 version=parsed_dep.group('version')
248 )
249
250 if dep in gosums:
251 continue
252
253 gosums.append(dep)
254
255 return gosums

Callers

nothing calls this directly

Calls 5

GoModuleClass · 0.85
groupMethod · 0.80
openMethod · 0.45
replaceMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected