diff options
Diffstat (limited to 'Library/Homebrew/language/python.rb')
| -rw-r--r-- | Library/Homebrew/language/python.rb | 28 | 
1 files changed, 27 insertions, 1 deletions
| diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index 9976cfe68..fad788dd7 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -8,6 +8,10 @@ module Language        Version.new(version.to_s)      end +    def self.homebrew_site_packages(version="2.7") +      HOMEBREW_PREFIX/"lib/python#{version}/site-packages" +    end +      def self.each_python build, &block        original_pythonpath = ENV["PYTHONPATH"]        ["python", "python3"].each do |python| @@ -16,11 +20,33 @@ module Language          ENV["PYTHONPATH"] = if Formulary.factory(python).installed?            nil          else -          "#{HOMEBREW_PREFIX}/lib/python#{version}/site-packages" +          homebrew_site_packages(version)          end          block.call python, version if block        end        ENV["PYTHONPATH"] = original_pythonpath      end + +    def self.reads_brewed_pth_files? python +      version = major_minor_version python +      return unless homebrew_site_packages(version).directory? +      probe_file = homebrew_site_packages(version)/"homebrew-pth-probe.pth" +      probe_file.atomic_write("import site; site.homebrew_was_here = True") +      result = quiet_system python, "-c", "import site; assert(site.homebrew_was_here)" +      probe_file.unlink +      result +    end + +    def self.user_site_packages python +      Pathname.new(`#{python} -c "import site; print(site.getusersitepackages())"`.chomp) +    end + +    def self.in_sys_path? python, path +      script = <<-EOS.undent +        import os, sys +        [os.path.realpath(p) for p in sys.path].index(os.path.realpath("#{path}")) +      EOS +      quiet_system python, "-c", script +    end    end  end | 
