Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

support parsing BUNDLED WITH #3444

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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