Skip to content

Commit

Permalink
Do not crash if there are no deps
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Nov 24, 2022
1 parent 35f5387 commit 9edf2fc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
29 changes: 28 additions & 1 deletion gemfileparser2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
import os
import re

TRACE = False


def logger_debug(*args):
pass


if TRACE:
import logging
import sys

logger = logging.getLogger(__name__)
logging.basicConfig(stream=sys.stdout)
logger.setLevel(logging.DEBUG)

def logger_debug(*args):
return logger.debug(' '.join(isinstance(a, str) and a or repr(a) for a in args))

logger_debug = print


class Dependency(object):
"""
Expand Down Expand Up @@ -157,10 +177,17 @@ def parse_gemfile(self):
# Gemfile contains a call to gemspec
gemfiledir = os.path.dirname(self.filepath)
gemspec_list = glob.glob(os.path.join(gemfiledir, "*.gemspec"))

if not gemspec_list:
logger_debug(f"No gemspec files found: {gemspec_list}")
continue

if len(gemspec_list) > 1:
print("Multiple gemspec files found")
logger_debug("Multiple gemspec files found")
continue

gemspec_file = gemspec_list[0]
# FIXME: the path is not used
self.parse_gemspec(path=os.path.join(gemfiledir, gemspec_file))

elif line.startswith("gem "):
Expand Down
22 changes: 22 additions & 0 deletions tests/data/gemspecs/arel2.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = arel2
s.version = "2.0.7.beta.20110429111451"

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
s.date = %q{2011-04-29}
s.description = %q{Arel is a SQL AST manager for Ruby.}
s.email = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"]
s.files = [".autotest", ".gemtest", "History.txt", "MIT-LICENSE.txt"]
s.homepage = %q{http://github.com/rails/arel}
s.rdoc_options = ["--main", "README.markdown"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{arel}
s.rubygems_version = %q{1.6.1}
s.summary = %q{Arel is a SQL AST manager for Ruby}
s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_as.rb"]

end
8 changes: 8 additions & 0 deletions tests/data/gemspecs/arel2.gemspec-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"development": [],
"runtime": [],
"dependency": [],
"test": [],
"production": [],
"metrics": []
}
4 changes: 4 additions & 0 deletions tests/test_gemfileparser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@ def test_gemspec_3():
check_gemparser_results("gemspecs/arel.gemspec")


def test_gemspec_no_deps():
check_gemparser_results("gemspecs/arel2.gemspec", regen=False)


def test_gemspec_4():
check_gemparser_results("gemspecs/logstash-mixin-ecs_compatibility_support.gemspec")

0 comments on commit 9edf2fc

Please sign in to comment.