Skip to content

Commit 9edf2fc

Browse files
committed
Do not crash if there are no deps
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 35f5387 commit 9edf2fc

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

gemfileparser2/__init__.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
import os
1515
import re
1616

17+
TRACE = False
18+
19+
20+
def logger_debug(*args):
21+
pass
22+
23+
24+
if TRACE:
25+
import logging
26+
import sys
27+
28+
logger = logging.getLogger(__name__)
29+
logging.basicConfig(stream=sys.stdout)
30+
logger.setLevel(logging.DEBUG)
31+
32+
def logger_debug(*args):
33+
return logger.debug(' '.join(isinstance(a, str) and a or repr(a) for a in args))
34+
35+
logger_debug = print
36+
1737

1838
class Dependency(object):
1939
"""
@@ -157,10 +177,17 @@ def parse_gemfile(self):
157177
# Gemfile contains a call to gemspec
158178
gemfiledir = os.path.dirname(self.filepath)
159179
gemspec_list = glob.glob(os.path.join(gemfiledir, "*.gemspec"))
180+
181+
if not gemspec_list:
182+
logger_debug(f"No gemspec files found: {gemspec_list}")
183+
continue
184+
160185
if len(gemspec_list) > 1:
161-
print("Multiple gemspec files found")
186+
logger_debug("Multiple gemspec files found")
162187
continue
188+
163189
gemspec_file = gemspec_list[0]
190+
# FIXME: the path is not used
164191
self.parse_gemspec(path=os.path.join(gemfiledir, gemspec_file))
165192

166193
elif line.startswith("gem "):

tests/data/gemspecs/arel2.gemspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
Gem::Specification.new do |s|
4+
s.name = arel2
5+
s.version = "2.0.7.beta.20110429111451"
6+
7+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8+
s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
9+
s.date = %q{2011-04-29}
10+
s.description = %q{Arel is a SQL AST manager for Ruby.}
11+
s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"]
12+
s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"]
13+
s.files = [".autotest", ".gemtest", "History.txt", "MIT-LICENSE.txt"]
14+
s.homepage = %q{http://github.com/rails/arel}
15+
s.rdoc_options = ["--main", "README.markdown"]
16+
s.require_paths = ["lib"]
17+
s.rubyforge_project = %q{arel}
18+
s.rubygems_version = %q{1.6.1}
19+
s.summary = %q{Arel is a SQL AST manager for Ruby}
20+
s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_as.rb"]
21+
22+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"development": [],
3+
"runtime": [],
4+
"dependency": [],
5+
"test": [],
6+
"production": [],
7+
"metrics": []
8+
}

tests/test_gemfileparser2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,9 @@ def test_gemspec_3():
7171
check_gemparser_results("gemspecs/arel.gemspec")
7272

7373

74+
def test_gemspec_no_deps():
75+
check_gemparser_results("gemspecs/arel2.gemspec", regen=False)
76+
77+
7478
def test_gemspec_4():
7579
check_gemparser_results("gemspecs/logstash-mixin-ecs_compatibility_support.gemspec")

0 commit comments

Comments
 (0)