Return a dictionary containing all the important go.mod file data. Handle go.mod files from Go. See https://golang.org/ref/mod#go.mod-files for details For example: module example.com/my/thing go 1.12 require example.com/other/thing v1.0.2 requir
(location)
| 62 | |
| 63 | |
| 64 | def parse_gomod(location): |
| 65 | """ |
| 66 | Return a dictionary containing all the important go.mod file data. |
| 67 | |
| 68 | Handle go.mod files from Go. |
| 69 | See https://golang.org/ref/mod#go.mod-files for details |
| 70 | |
| 71 | For example: |
| 72 | |
| 73 | module example.com/my/thing |
| 74 | |
| 75 | go 1.12 |
| 76 | |
| 77 | require example.com/other/thing v1.0.2 |
| 78 | require example.com/new/thing v2.3.4 |
| 79 | exclude example.com/old/thing v1.2.3 |
| 80 | require ( |
| 81 | example.com/new/thing v2.3.4 |
| 82 | example.com/old/thing v1.2.3 |
| 83 | ) |
| 84 | require ( |
| 85 | example.com/new/thing v2.3.4 |
| 86 | example.com/old/thing v1.2.3 |
| 87 | ) |
| 88 | |
| 89 | Each module line is in the form |
| 90 | require github.com/davecgh/go-spew v1.1.1 |
| 91 | or |
| 92 | exclude github.com/davecgh/go-spew v1.1.1 |
| 93 | or |
| 94 | module github.com/alecthomas/participle |
| 95 | |
| 96 | For example:: |
| 97 | |
| 98 | >>> p = parse_module('module github.com/alecthomas/participle') |
| 99 | >>> assert p.group('type') == ('module') |
| 100 | >>> assert p.group('ns_name') == ('github.com/alecthomas/participle') |
| 101 | |
| 102 | >>> p = parse_module('require github.com/davecgh/go-spew v1.1.1') |
| 103 | >>> assert p.group('type') == ('require') |
| 104 | >>> assert p.group('ns_name') == ('github.com/davecgh/go-spew') |
| 105 | >>> assert p.group('version') == ('v1.1.1') |
| 106 | |
| 107 | A line for require or exclude can be in the form: |
| 108 | |
| 109 | github.com/davecgh/go-spew v1.1.1 |
| 110 | |
| 111 | For example:: |
| 112 | |
| 113 | >>> p = parse_dep_link('github.com/davecgh/go-spew v1.1.1') |
| 114 | >>> assert p.group('ns_name') == ('github.com/davecgh/go-spew') |
| 115 | >>> assert p.group('version') == ('v1.1.1') |
| 116 | """ |
| 117 | with io.open(location, encoding='utf-8', closefd=True) as data: |
| 118 | lines = data.readlines() |
| 119 | |
| 120 | gomods = GoModule() |
| 121 | require = [] |
nothing calls this directly
no test coverage detected