Class: CI::Syntax::Tool::Language::Python
- Defined in:
- lib/ci-syntax-tool/language/python.rb
Instance Attribute Summary collapse
-
#python_bin ⇒ Object
readonly
Returns the value of attribute python_bin.
Instance Method Summary collapse
-
#check_ending(_result) ⇒ Object
Called once after all files are checked Use for cleanup, or adding metadata to the result.
-
#check_file(file_result) ⇒ Object
Called once for each file being checked.
-
#check_starting(_lang_result) ⇒ Object
Called once before any files are checked An opportunity to spawn a process, for example.
- #default_globs ⇒ Object
-
#initialize(args) ⇒ Python
constructor
A new instance of Python.
Methods inherited from Base
#combined_globs, descendant_classes
Constructor Details
#initialize(args) ⇒ Python
Returns a new instance of Python.
11 12 13 14 |
# File 'lib/ci-syntax-tool/language/python.rb', line 11 def initialize(args) super @python_bin = `which python`.chomp end |
Instance Attribute Details
#python_bin ⇒ Object (readonly)
Returns the value of attribute python_bin.
9 10 11 |
# File 'lib/ci-syntax-tool/language/python.rb', line 9 def python_bin @python_bin end |
Instance Method Details
#check_ending(_result) ⇒ Object
Called once after all files are checked Use for cleanup, or adding metadata to the result. result [Language::Result] - populated results of the run. TODO: shutdown sub proc
61 62 |
# File 'lib/ci-syntax-tool/language/python.rb', line 61 def check_ending(_result) end |
#check_file(file_result) ⇒ Object
Called once for each file being checked.
path [String] - path to filename to check file_result [Result::File] - Results object for the outcome. Returns: Result::File
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ci-syntax-tool/language/python.rb', line 33 def check_file(file_result) # A clean compile will emit silence to STDERR and STDOUT, and leave behind a pyc file. output = `#{python_bin} -m py_compile #{file_result.path} 2>&1` # Errors look like this, with no newline (so far: # Sorry: IndentationError: unexpected indent (bad-indentation.py, line 4) output.scan(/Sorry:\s+(.+):\s+(.+)\s+\((.+),\s+line\s+(\d+)\)/).each do |match| file_result.add_issue( line_number: match[3], level: :error, raw_message: match[1], ) end # Check for and delete a PYC file if one was created. pyc_file = file_result.path + 'c' if File.exist?(pyc_file) then FileUtils.rm(pyc_file) end end |
#check_starting(_lang_result) ⇒ Object
Called once before any files are checked An opportunity to spawn a process, for example. TODO: consider spawning a python process, reading filenames see this: stackoverflow.com/a/4284526/3284458
25 26 |
# File 'lib/ci-syntax-tool/language/python.rb', line 25 def check_starting(_lang_result) end |
#default_globs ⇒ Object
16 17 18 |
# File 'lib/ci-syntax-tool/language/python.rb', line 16 def default_globs ['**/*.py'] end |