File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ module Shebang
112
112
module_function
113
113
114
114
# A regex to match potential shebang permutations.
115
- PYTHON_SHEBANG_REGEX = %r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\. \d {1,2})?)?( |$)}
115
+ PYTHON_SHEBANG_REGEX = %r{^#! ?(?: /usr/bin/(?:env )? )?python(?:[23](?:\. \d {1,2})?)?( |$)}
116
116
117
117
# The length of the longest shebang matching `SHEBANG_REGEX`.
118
118
PYTHON_SHEBANG_MAX_LENGTH = T . let ( "#! /usr/bin/env pythonx.yyy " . length , Integer )
Original file line number Diff line number Diff line change 5
5
6
6
RSpec . describe Language ::Python ::Shebang do
7
7
let ( :file ) { Tempfile . new ( "python-shebang" ) }
8
+ let ( :broken_file ) { Tempfile . new ( "python-shebang" ) }
8
9
let ( :f ) do
9
10
f = { }
10
11
40
41
c
41
42
EOS
42
43
file . flush
44
+
45
+ broken_file . write <<~EOS
46
+ #!python
47
+ a
48
+ b
49
+ c
50
+ EOS
51
+ broken_file . flush
43
52
end
44
53
45
- after { file . unlink }
54
+ after { [ file , broken_file ] . each ( & : unlink) }
46
55
47
56
describe "#detected_python_shebang" do
48
57
it "can be used to replace Python shebangs" do
72
81
EOS
73
82
end
74
83
84
+ it "can replace `#!python` shebang" do
85
+ Utils ::Shebang . rewrite_shebang (
86
+ described_class . detected_python_shebang ( f [ :versioned_python_dep ] ,
87
+ use_python_from_path : true ) , broken_file . path
88
+ )
89
+
90
+ expect ( File . read ( broken_file ) ) . to eq <<~EOS
91
+ #!/usr/bin/env python3
92
+ a
93
+ b
94
+ c
95
+ EOS
96
+ end
97
+
75
98
it "errors if formula doesn't depend on python" do
76
99
expect do
77
100
Utils ::Shebang . rewrite_shebang (
You can’t perform that action at this time.
0 commit comments