gemfileparser2

raw JSON →
0.9.4 verified Fri May 01 auth: no python

Parse Ruby Gemfile, .gemspec and Cocoapod .podspec files using Python. Current version 0.9.4, requires Python >=3.7. Maintenance cadence is sporadic.

pip install gemfileparser2
error ModuleNotFoundError: No module named 'gemfileparser'
cause Package renamed to gemfileparser2 in v0.9.0.
fix
Install gemfileparser2 and import from gemfileparser2.
error AttributeError: 'str' object has no attribute 'read'
cause Passing a file path string to parse() instead of file contents.
fix
Open the file and read its content: open('Gemfile').read()
error gemfileparser2.exceptions.ParseError: Expected ...
cause Malformed Gemfile content (e.g., syntax error in Ruby source).
fix
Ensure the Gemfile is valid Ruby syntax.
breaking The package was renamed from gemfileparser to gemfileparser2 in v0.9.0. All imports must be updated.
fix Change 'from gemfileparser import ...' to 'from gemfileparser2 import ...'
gotcha The parse() method accepts plain text string, not a file path. Passing a file path will fail silently or raise an error.
fix Read the file content with open() and pass the string to parse().
deprecated The old module 'gemfileparser' was restored in v0.9.3 for compatibility but may be removed in future releases.
fix Use 'gemfileparser2' instead of 'gemfileparser'.

Read and parse a Ruby Gemfile.

from gemfileparser2 import GemfileParser
import os

# Parse a Gemfile
with open('Gemfile', 'r') as f:
    content = f.read()
parser = GemfileParser().parse(content)
print(parser.dependencies)