Module: Language::Python::Shebang
- Defined in:
- language/python.rb
Overview
Mixin module for Formula adding shebang rewrite features.
Constant Summary collapse
- PYTHON_SHEBANG_REGEX =
A regex to match potential shebang permutations.
%r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\.\d{1,2})?)?( |$)}.freeze
- PYTHON_SHEBANG_MAX_LENGTH =
The length of the longest shebang matching
SHEBANG_REGEX
. "#! /usr/bin/env pythonx.yyy ".length
Class Method Summary collapse
Class Method Details
.detected_python_shebang(formula = self, use_python_from_path: false) ⇒ Utils::Shebang::RewriteInfo
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'language/python.rb', line 114 def detected_python_shebang(formula = self, use_python_from_path: false) python_path = if use_python_from_path "/usr/bin/env python3" else python_deps = formula.deps.map(&:name).grep(/^python(@.+)?$/) raise ShebangDetectionError.new("Python", "formula does not depend on Python") if python_deps.empty? if python_deps.length > 1 raise ShebangDetectionError.new("Python", "formula has multiple Python dependencies") end python_dep = python_deps.first Formula[python_dep].opt_bin/python_dep.sub("@", "") end python_shebang_rewrite_info(python_path) end |