Skip to content

Commit

Permalink
Support Directives in go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
VarshaUN committed Jan 19, 2025
1 parent fc982a6 commit 34453dc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/packagedcode/go_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def parse_gomod(location):
gomods = GoModule()
require = []
exclude = []
replace = []

for i, line in enumerate(lines):
line = preprocess(line)
Expand Down Expand Up @@ -157,6 +158,23 @@ def parse_gomod(location):
)
)
continue

if 'replace' in line and '(' in line:
for repl in lines[i + 1:]:
repl = preprocess(repl)
if ')' in repl:
break
parsed_dep_link = parse_dep_link(repl)
ns_name = parsed_dep_link.group('ns_name')
namespace, _, name = ns_name.rpartition('/')
if parsed_dep_link:
replace.append(GoModule(
namespace=namespace,
name=name,
version=parsed_dep_link.group('version')
)
)
continue

parsed_module_name = parse_module(line)
if parsed_module_name:
Expand Down Expand Up @@ -186,8 +204,18 @@ def parse_gomod(location):
)
continue

if 'replace' in line:
replace.append(GoModule(
namespace=namespace,
name=name,
version=parsed_module_name.group('version')
)
)
continue

gomods.require = require
gomods.exclude = exclude
gomods.replace = replace

return gomods

Expand Down Expand Up @@ -253,3 +281,4 @@ def parse_gosum(location):
gosums.append(dep)

return gosums

0 comments on commit 34453dc

Please sign in to comment.