Skip to content

Commit

Permalink
Merge pull request #3444 from akostadinov/develop
Browse files Browse the repository at this point in the history
support parsing BUNDLED WITH
  • Loading branch information
pombredanne authored Jun 30, 2023
2 parents 8ed2663 + 6edab47 commit a15174f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/packagedcode/gemfile_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def logger_debug(*args):
SVN = 'SVN'
GEM = 'GEM'
PLATFORMS = 'PLATFORMS'
BUNDLED = 'BUNDLED WITH'
DEPENDENCIES = 'DEPENDENCIES'
SPECS = ' specs:'

Expand Down Expand Up @@ -340,6 +341,7 @@ def get_option(s):
'$' % locals()).match

PLATS = re.compile('^ (?P<platform>.*)$').match
BUNDLED_WITH = re.compile('^\s+(?P<version>(?:\d+.)+\d+)\s*$').match


class GemfileLockParser:
Expand All @@ -358,6 +360,7 @@ def __init__(self, lockfile):
self.STATES = {
DEPENDENCIES: self.parse_dependency,
PLATFORMS: self.parse_platform,
BUNDLED: self.parse_bundler_version,
GIT: self.parse_options,
PATH: self.parse_options,
SVN: self.parse_options,
Expand All @@ -376,6 +379,8 @@ def __init__(self, lockfile):

self.platforms = []

self.bundled_with = None

# init parsing state
self.reset_state()

Expand Down Expand Up @@ -536,6 +541,16 @@ def parse_platform(self, line):
plat = plat.group('platform')
self.platforms.append(plat.strip())

def parse_bundler_version(self, line):
version = BUNDLED_WITH(line)
if not version:
if TRACE:
logger_debug('ERROR: parse_bundler_version: '
'line not matched: %(line)r' % locals())
return
version = version.group('version')
self.bundled_with = version

def flatten(self):
"""
Return the Gems dependency_tree as a sorted list of unique
Expand Down
2 changes: 2 additions & 0 deletions tests/packagedcode/data/gemfile_lock/bundled/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLED WITH
2.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
8 changes: 8 additions & 0 deletions tests/packagedcode/test_gemfile_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ def test_GemfileLockParser_can_parse_platform(self):
expected_loc = 'gemfile_lock/platform/Gemfile.lock.expected.json'
self.check_gemfile_lock(test_file, expected_loc, regen=REGEN_TEST_FIXTURES)

def test_GemfileLockParser_can_parse_bundled(self):
test_file = 'gemfile_lock/bundled/Gemfile.lock'
expected_loc = 'gemfile_lock/bundled/Gemfile.lock.expected.json'
self.check_gemfile_lock(test_file, expected_loc, regen=REGEN_TEST_FIXTURES)

gfl = gemfile_lock.GemfileLockParser(self.get_test_loc(test_file))
assert gfl.bundled_with == "2.0.1"

def test_GemfileLockParser_can_parse_spec_single_level(self):
test_file = 'gemfile_lock/spec/Gemfile.lock1'
expected_loc = 'gemfile_lock/spec/Gemfile.lock1.expected.json'
Expand Down

0 comments on commit a15174f

Please # to comment.