Module: Language::Python
- Extended by:
- Utils::Output::Mixin
- Defined in:
- language/python.rb
Overview
Helper functions for Python formulae.
Defined Under Namespace
Modules: Shebang, Virtualenv
Class Method Summary collapse
- .each_python(build, &block) ⇒ void private
- .homebrew_site_packages(python = "python3.7") ⇒ Pathname private
- .in_sys_path?(python, path) ⇒ Boolean private
- .major_minor_version(python) ⇒ Version? private
- .reads_brewed_pth_files?(python) ⇒ Boolean private
- .setup_install_args(prefix, python = "python3") ⇒ Array<String> private
- .site_packages(python = "python3.7") ⇒ String private
- .user_site_packages(python) ⇒ Pathname private
Methods included from Utils::Output::Mixin
odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_deprecated, pretty_disabled, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled
Class Method Details
.each_python(build, &block) ⇒ void
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.
This method returns an undefined value.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'language/python.rb', line 42 def self.each_python(build, &block) original_pythonpath = ENV.fetch("PYTHONPATH", nil) pythons = { "python@3" => "python3", "pypy" => "pypy", "pypy3" => "pypy3" } pythons.each do |python_formula, python| python_formula = Formulary.factory(python_formula) next if build.without? python_formula.to_s version = major_minor_version python ENV["PYTHONPATH"] = if python_formula.latest_version_installed? nil else homebrew_site_packages(python).to_s end block&.call python, version end ENV["PYTHONPATH"] = original_pythonpath end |
.homebrew_site_packages(python = "python3.7") ⇒ Pathname
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.
23 24 25 |
# File 'language/python.rb', line 23 def self.homebrew_site_packages(python = "python3.7") HOMEBREW_PREFIX/site_packages(python) end |
.in_sys_path?(python, path) ⇒ Boolean
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.
82 83 84 85 86 87 88 |
# File 'language/python.rb', line 82 def self.in_sys_path?(python, path) script = <<~PYTHON import os, sys [os.path.realpath(p) for p in sys.path].index(os.path.realpath("#{path}")) PYTHON quiet_system python, "-c", script end |
.major_minor_version(python) ⇒ Version?
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.
15 16 17 18 19 20 |
# File 'language/python.rb', line 15 def self.major_minor_version(python) version = `#{python} --version 2>&1`.chomp[/(\d\.\d+)/, 1] return unless version Version.new(version) end |
.reads_brewed_pth_files?(python) ⇒ Boolean
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.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'language/python.rb', line 63 def self.reads_brewed_pth_files?(python) return false unless homebrew_site_packages(python).directory? return false unless homebrew_site_packages(python).writable? probe_file = homebrew_site_packages(python)/"homebrew-pth-probe.pth" begin probe_file.atomic_write("import site; site.homebrew_was_here = True") with_homebrew_path { quiet_system python, "-c", "import site; assert(site.homebrew_was_here)" } ensure probe_file.unlink if probe_file.exist? end end |
.setup_install_args(prefix, python = "python3") ⇒ Array<String>
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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'language/python.rb', line 91 def self.setup_install_args(prefix, python = "python3") odisabled "Language::Python.setup_install_args", "pip and `std_pip_args`" shim = <<~PYTHON import setuptools, tokenize __file__ = 'setup.py' exec(compile(getattr(tokenize, 'open', open)(__file__).read() .replace('\\r\\n', '\\n'), __file__, 'exec')) PYTHON %W[ -c #{shim} --no-user-cfg install --prefix=#{prefix} --install-scripts=#{prefix}/bin --install-lib=#{prefix/site_packages(python)} --single-version-externally-managed --record=installed.txt ] end |
.site_packages(python = "python3.7") ⇒ String
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.
28 29 30 31 32 33 34 |
# File 'language/python.rb', line 28 def self.site_packages(python = "python3.7") if (python == "pypy") || (python == "pypy3") "site-packages" else "lib/python#{major_minor_version python}/site-packages" end end |
.user_site_packages(python) ⇒ Pathname
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.
77 78 79 |
# File 'language/python.rb', line 77 def self.user_site_packages(python) Pathname.new(`#{python} -c "import site; print(site.getusersitepackages())"`.chomp) end |