Merge pull request #1750 from github/interpreters-in-samples

Fix for interpreters from samples
This commit is contained in:
Brandon Keepers
2014-11-26 16:51:08 -05:00
4 changed files with 58 additions and 20 deletions

View File

@@ -559,6 +559,8 @@ Crystal:
- .cr - .cr
ace_mode: ruby ace_mode: ruby
tm_scope: source.ruby tm_scope: source.ruby
interpreters:
- crystal
Cucumber: Cucumber:
extensions: extensions:
@@ -736,6 +738,8 @@ Erlang:
- .es - .es
- .escript - .escript
- .hrl - .hrl
interpreters:
- escript
F#: F#:
type: programming type: programming
@@ -931,6 +935,8 @@ Gnuplot:
- .gnuplot - .gnuplot
- .plot - .plot
- .plt - .plt
interpreters:
- gnuplot
Go: Go:
type: programming type: programming
@@ -1196,6 +1202,8 @@ Ioke:
color: "#078193" color: "#078193"
extensions: extensions:
- .ik - .ik
interpreters:
- ioke
Isabelle: Isabelle:
type: programming type: programming
@@ -1703,6 +1711,8 @@ Nu:
filenames: filenames:
- Nukefile - Nukefile
tm_scope: source.scheme tm_scope: source.scheme
interpreters:
- nush
NumPy: NumPy:
group: Python group: Python
@@ -1889,6 +1899,8 @@ Parrot Assembly:
- pasm - pasm
extensions: extensions:
- .pasm - .pasm
interpreters:
- parrot
tm_scope: none tm_scope: none
Parrot Internal Representation: Parrot Internal Representation:
@@ -1899,6 +1911,8 @@ Parrot Internal Representation:
- pir - pir
extensions: extensions:
- .pir - .pir
interpreters:
- parrot
Pascal: Pascal:
type: programming type: programming
@@ -1941,6 +1955,8 @@ Perl6:
- .p6m - .p6m
- .pl6 - .pl6
- .pm6 - .pm6
interpreters:
- perl6
tm_scope: none tm_scope: none
PigLatin: PigLatin:
@@ -2005,6 +2021,8 @@ Prolog:
- .ecl - .ecl
- .pro - .pro
- .prolog - .prolog
interpreters:
- swipl
Propeller Spin: Propeller Spin:
type: programming type: programming
@@ -2068,6 +2086,8 @@ Python:
- wscript - wscript
interpreters: interpreters:
- python - python
- python2
- python3
Python traceback: Python traceback:
type: data type: data
@@ -2088,6 +2108,8 @@ QMake:
extensions: extensions:
- .pro - .pro
- .pri - .pri
interpreters:
- qmake
R: R:
type: programming type: programming
@@ -2242,6 +2264,8 @@ Ruby:
- .watchr - .watchr
interpreters: interpreters:
- ruby - ruby
- macruby
- rake
filenames: filenames:
- .pryrc - .pryrc
- Appraisals - Appraisals
@@ -2328,6 +2352,8 @@ Scala:
- .scala - .scala
- .sbt - .sbt
- .sc - .sc
interpreters:
- scala
Scaml: Scaml:
group: HTML group: HTML

View File

@@ -52,14 +52,16 @@ module Linguist
}) })
end end
else else
path = File.join(dirname, filename)
if File.extname(filename) == "" if File.extname(filename) == ""
raise "#{File.join(dirname, filename)} is missing an extension, maybe it belongs in filenames/ subdir" raise "#{path} is missing an extension, maybe it belongs in filenames/ subdir"
end end
yield({ yield({
:path => File.join(dirname, filename), :path => path,
:language => category, :language => category,
:interpreter => File.exist?(filename) ? Linguist.interpreter_from_shebang(File.read(filename)) : nil, :interpreter => Linguist.interpreter_from_shebang(File.read(path)),
:extname => File.extname(filename) :extname => File.extname(filename)
}) })
end end
@@ -131,10 +133,11 @@ module Linguist
script = script == 'env' ? tokens[1] : script script = script == 'env' ? tokens[1] : script
# "python2.6" -> "python" # If script has an invalid shebang, we might get here
if script =~ /((?:\d+\.?)+)/ return unless script
script.sub! $1, ''
end # "python2.6" -> "python2"
script.sub! $1, '' if script =~ /(\.\d+)$/
# Check for multiline shebang hacks that call `exec` # Check for multiline shebang hacks that call `exec`
if script == 'sh' && if script == 'sh' &&
@@ -142,7 +145,7 @@ module Linguist
script = $1 script = $1
end end
script File.basename(script)
else else
nil nil
end end

View File

@@ -1,2 +0,0 @@
#!/usr/bin/env python
puts "Not Python"

View File

@@ -31,23 +31,29 @@ class TestSamples < Test::Unit::TestCase
assert_equal data['languages_total'], data['languages'].inject(0) { |n, (_, c)| n += c } assert_equal data['languages_total'], data['languages'].inject(0) { |n, (_, c)| n += c }
assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c } assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c }
assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } } assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } }
assert !data["interpreters"].empty?
end end
# Check that there aren't samples with extensions that aren't explicitly defined in languages.yml # Check that there aren't samples with extensions or interpreters that
def test_parity # aren't explicitly defined in languages.yml
extensions = Samples.cache['extnames']
languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__) languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
languages = YAML.load_file(languages_yml) YAML.load_file(languages_yml).each do |name, options|
define_method "test_samples_have_parity_with_languages_yml_for_#{name}" do
languages.each do |name, options|
options['extensions'] ||= [] options['extensions'] ||= []
if extnames = Samples.cache['extnames'][name]
if extnames = extensions[name]
extnames.each do |extname| extnames.each do |extname|
next if extname == '.script!' next if extname == '.script!'
assert options['extensions'].include?(extname), "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" assert options['extensions'].include?(extname), "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml"
end end
end end
options['interpreters'] ||= []
if interpreters = Samples.cache['interpreters'][name]
interpreters.each do |interpreter|
# next if extname == '.script!'
assert options['interpreters'].include?(interpreter), "#{name} has a sample with an interpreter (#{interpreter}) that isn't explicitly defined in languages.yml"
end
end
end end
end end
@@ -76,4 +82,9 @@ class TestSamples < Test::Unit::TestCase
end end
end end
end end
def test_shebang
assert_equal "crystal", Linguist.interpreter_from_shebang("#!/usr/bin/env bin/crystal")
assert_equal "python2", Linguist.interpreter_from_shebang("#!/usr/bin/python2.4")
end
end end