From 0eb60012eabb31f219d59f84c614ffe06d3bf2d3 Mon Sep 17 00:00:00 2001 From: Devon Blandin Date: Mon, 17 Sep 2018 11:30:07 -0400 Subject: [PATCH] Add .py3 file extension pattern only when python 3 is specified --- lib/cc/engine/analyzers/analyzer_base.rb | 6 +++++- lib/cc/engine/analyzers/python/main.rb | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/cc/engine/analyzers/analyzer_base.rb b/lib/cc/engine/analyzers/analyzer_base.rb index fda293c6..48b9039c 100644 --- a/lib/cc/engine/analyzers/analyzer_base.rb +++ b/lib/cc/engine/analyzers/analyzer_base.rb @@ -129,7 +129,7 @@ def file_list engine_config: engine_config, patterns: engine_config.patterns_for( language, - self.class::PATTERNS, + patterns, ), ) end @@ -169,6 +169,10 @@ def handle_exception(processed_source, ex) end nil end + + def patterns + self.class::PATTERNS + end end end end diff --git a/lib/cc/engine/analyzers/python/main.rb b/lib/cc/engine/analyzers/python/main.rb index fec2ccd1..d389f52d 100644 --- a/lib/cc/engine/analyzers/python/main.rb +++ b/lib/cc/engine/analyzers/python/main.rb @@ -12,7 +12,6 @@ module Analyzers module Python class Main < CC::Engine::Analyzers::Base LANGUAGE = "python" - PATTERNS = ["**/*.py", "**/*.py3"].freeze DEFAULT_MASS_THRESHOLD = 32 DEFAULT_PYTHON_VERSION = 2 POINTS_PER_OVERAGE = 50_000 @@ -34,6 +33,19 @@ def parser(path) def python_version engine_config.fetch_language(LANGUAGE).fetch("python_version", DEFAULT_PYTHON_VERSION) end + + def patterns + case python_version + when 2, "2" + ["**/*.py"] + "python2" + when 3, "3" + ["**/*.py", "**/*.py3"] + "python3" + else + raise ArgumentError, "Supported python versions are 2 and 3. You configured: #{python_version.inspect}" + end + end end end end