Skip to content

Commit a15174f

Browse files
authored
Merge pull request #3444 from akostadinov/develop
support parsing BUNDLED WITH
2 parents 8ed2663 + 6edab47 commit a15174f

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/packagedcode/gemfile_lock.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def logger_debug(*args):
109109
SVN = 'SVN'
110110
GEM = 'GEM'
111111
PLATFORMS = 'PLATFORMS'
112+
BUNDLED = 'BUNDLED WITH'
112113
DEPENDENCIES = 'DEPENDENCIES'
113114
SPECS = ' specs:'
114115

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

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

344346

345347
class GemfileLockParser:
@@ -358,6 +360,7 @@ def __init__(self, lockfile):
358360
self.STATES = {
359361
DEPENDENCIES: self.parse_dependency,
360362
PLATFORMS: self.parse_platform,
363+
BUNDLED: self.parse_bundler_version,
361364
GIT: self.parse_options,
362365
PATH: self.parse_options,
363366
SVN: self.parse_options,
@@ -376,6 +379,8 @@ def __init__(self, lockfile):
376379

377380
self.platforms = []
378381

382+
self.bundled_with = None
383+
379384
# init parsing state
380385
self.reset_state()
381386

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

544+
def parse_bundler_version(self, line):
545+
version = BUNDLED_WITH(line)
546+
if not version:
547+
if TRACE:
548+
logger_debug('ERROR: parse_bundler_version: '
549+
'line not matched: %(line)r' % locals())
550+
return
551+
version = version.group('version')
552+
self.bundled_with = version
553+
539554
def flatten(self):
540555
"""
541556
Return the Gems dependency_tree as a sorted list of unique
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLED WITH
2+
2.0.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tests/packagedcode/test_gemfile_lock.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ def test_GemfileLockParser_can_parse_platform(self):
372372
expected_loc = 'gemfile_lock/platform/Gemfile.lock.expected.json'
373373
self.check_gemfile_lock(test_file, expected_loc, regen=REGEN_TEST_FIXTURES)
374374

375+
def test_GemfileLockParser_can_parse_bundled(self):
376+
test_file = 'gemfile_lock/bundled/Gemfile.lock'
377+
expected_loc = 'gemfile_lock/bundled/Gemfile.lock.expected.json'
378+
self.check_gemfile_lock(test_file, expected_loc, regen=REGEN_TEST_FIXTURES)
379+
380+
gfl = gemfile_lock.GemfileLockParser(self.get_test_loc(test_file))
381+
assert gfl.bundled_with == "2.0.1"
382+
375383
def test_GemfileLockParser_can_parse_spec_single_level(self):
376384
test_file = 'gemfile_lock/spec/Gemfile.lock1'
377385
expected_loc = 'gemfile_lock/spec/Gemfile.lock1.expected.json'

0 commit comments

Comments
 (0)