Skip to content

Commit

Permalink
Signed-off-by: Jono Yang <[email protected]>
Browse files Browse the repository at this point in the history
Signed-off-by: Varsha U N <[email protected]>

Signed-off-by: Jono Yang <[email protected]>
Signed-off-by: Varsha U N <[email protected]>

Support Directives in go.mod

Signed-off-by: Varsha U N <[email protected]>
  • Loading branch information
JonoYang authored and VarshaUN committed Jan 19, 2025
1 parent b5d204e commit f64c755
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/licensedcode/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def select_ngrams(ngrams, with_pos=False):
>>> list(select_ngrams(x for x in [(2, 1, 3), (1, 1, 3), (5, 1, 3), (2, 6, 1), (7, 3, 4)]))
[(2, 1, 3), (1, 1, 3), (5, 1, 3), (2, 6, 1), (7, 3, 4)]
"""
ngram = None
last = None
for pos, ngram in enumerate(ngrams):
# FIXME: use a proper hash
Expand Down
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

8 changes: 8 additions & 0 deletions src/packagedcode/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ def _parse(

if TRACE:
raise

except Exception as e:
# We should continue when an Exception has occured when trying to
# recognize a package
if TRACE:
logger_debug(f'_parse: Exception: {str(e)}')

continue

0 comments on commit f64c755

Please sign in to comment.