From 0db133ffb2b9841ba737329ce1a169954fe283b1 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sat, 14 Mar 2015 19:43:17 +0100 Subject: [PATCH] Detect Cython generated files --- lib/linguist/generated.rb | 13 +++++++++++++ test/test_blob.rb | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index b93f7ea6..4a67fabd 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -62,6 +62,7 @@ module Linguist generated_parser? || generated_net_docfile? || generated_postscript? || + compiled_cython_file? || generated_protocol_buffer_go? || generated_protocol_buffer? || generated_jni_header? || @@ -270,5 +271,17 @@ module Linguist # VCR Cassettes have "recorded_with: VCR" in the second last line. return lines[-2].include?("recorded_with: VCR") end + + # Internal: Is this a compiled C/C++ file from Cython? + # + # Cython-compiled C/C++ files typically contain: + # /* Generated by Cython x.x.x on ... */ + # on the first line. + # + # Return true or false + def compiled_cython_file? + return false unless ['.c', '.cpp'].include? extname + return lines[0].include?("Generated by Cython") + end end end diff --git a/test/test_blob.rb b/test/test_blob.rb index 7c8fddc1..cc4243ea 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -240,6 +240,10 @@ class TestBlob < Minitest::Test # Godep saved dependencies assert sample_blob("Godeps/Godeps.json").generated? assert sample_blob("Godeps/_workspace/src/github.com/kr/s3/sign.go").generated? + + # Cython-generated C/C++ + assert sample_blob("C/sgd_fast.c").generated? + assert sample_blob("C++/wrapper_inner.cpp").generated? end def test_vendored