Module: Language::Python::Shebang Private

Extended by:
T::Helpers
Defined in:
language/python.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Mixin module for Formula adding shebang rewrite features.

Constant Summary collapse

PYTHON_SHEBANG_REGEX =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

A regex to match potential shebang permutations.

%r{\A#! ?(?:/usr/bin/(?:env )?)?python(?:[23](?:\.\d{1,2})?)?( |$)}
PYTHON_SHEBANG_MAX_LENGTH =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

The length of the longest shebang matching SHEBANG_REGEX.

T.let("#! /usr/bin/env pythonx.yyy ".length, Integer)

Class Method Summary collapse

Class Method Details

.detected_python_shebang(formula = T.cast(self, Formula), use_python_from_path: false) ⇒ Utils::Shebang::RewriteInfo

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • formula (Formula) (defaults to: T.cast(self, Formula))
  • use_python_from_path (Boolean) (defaults to: false)

Returns:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'language/python.rb', line 116

def detected_python_shebang(formula = T.cast(self, Formula), use_python_from_path: false)
  python_path = if use_python_from_path
    "/usr/bin/env python3"
  else
    python_deps = formula.deps.select(&:required?).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
    Utils::Path.formula_opt_bin(python_dep)/python_dep.sub("@", "")
  end

  python_shebang_rewrite_info(python_path)
end