Skip to content

Commit

Permalink
Merge pull request Homebrew#193787 from branchvincent/[email protected]
Browse files Browse the repository at this point in the history
ranger: migrate to `[email protected]`
  • Loading branch information
BrewTestBot authored Oct 16, 2024
2 parents 438aae4 + 1c374bb commit 314882b
Showing 1 changed file with 62 additions and 13 deletions.
75 changes: 62 additions & 13 deletions Formula/r/ranger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ class Ranger < Formula

desc "File browser"
homepage "https://ranger.github.io"
url "https://ranger.github.io/ranger-1.9.3.tar.gz"
sha256 "ce088a04c91c25263a9675dc5c43514b7ec1b38c8ea43d9a9d00923ff6cdd251"
license "GPL-3.0-or-later"
revision 2
head "https://github.com/ranger/ranger.git", branch: "master"

stable do
url "https://ranger.github.io/ranger-1.9.3.tar.gz"
sha256 "ce088a04c91c25263a9675dc5c43514b7ec1b38c8ea43d9a9d00923ff6cdd251"

# Drop `imghdr` for python 3.13
# Backport of https://github.com/ranger/ranger/commit/9c0d3ba3495bac80142fad518e29b9061be94cc6
patch :DATA
end

bottle do
rebuild 3
sha256 cellar: :any_skip_relocation, arm64_sequoia: "d658a012014c41c2ff480390de60f9b7d14de34e7f207bd22646a44944ba4ef3"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "f6e82a85ac9ec491664b30f4023e2c96be0485eec8fc34bae355500bd6e87024"
sha256 cellar: :any_skip_relocation, arm64_ventura: "a7df758964227f9f43b50b30e80eb8c2c54f0f0926806b4912de077631e59644"
sha256 cellar: :any_skip_relocation, arm64_monterey: "f6a5f3323c38e5b7cd70ddaee2a29fb1d2f9a68ac690a2aea8eda06baea2c8f6"
sha256 cellar: :any_skip_relocation, sonoma: "3efb7ed3317ce5187e6cab149b54504f15a7cf32e0a7f156dbde05867f966a3d"
sha256 cellar: :any_skip_relocation, ventura: "86a9399e36ac5cba36a307a951f5ae5f7cce3ac697eaa06c73674f565bfb4253"
sha256 cellar: :any_skip_relocation, monterey: "e26848ccdb553fb6914c4165c5985b6d0c25c7df2df21a61d176608a14d923c3"
sha256 cellar: :any_skip_relocation, x86_64_linux: "f1c019d60c241b2080cd53ad4fc8e24bb8c14df3345d09a4f202a798d51a1a8e"
rebuild 4
sha256 cellar: :any_skip_relocation, arm64_sequoia: "29f94668e81c45db4b87f46d183450c306196f58315d34c948090d87552d81a0"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "29f94668e81c45db4b87f46d183450c306196f58315d34c948090d87552d81a0"
sha256 cellar: :any_skip_relocation, arm64_ventura: "29f94668e81c45db4b87f46d183450c306196f58315d34c948090d87552d81a0"
sha256 cellar: :any_skip_relocation, sonoma: "c4a0c957609a0dbc3c20f6bb0e420d1166bb65de6c205acca14ee85c880b68da"
sha256 cellar: :any_skip_relocation, ventura: "c4a0c957609a0dbc3c20f6bb0e420d1166bb65de6c205acca14ee85c880b68da"
sha256 cellar: :any_skip_relocation, x86_64_linux: "29f94668e81c45db4b87f46d183450c306196f58315d34c948090d87552d81a0"
end

depends_on "python@3.12"
depends_on "python@3.13"

def install
virtualenv_install_with_resources
Expand All @@ -34,7 +39,51 @@ def install
(testpath/"test.py").write code
assert_equal code, shell_output("#{bin}/rifle -w cat test.py")

ENV.prepend_path "PATH", Formula["python@3.12"].opt_libexec/"bin"
ENV.prepend_path "PATH", Formula["python@3.13"].opt_libexec/"bin"
assert_equal "Hello World!\n", shell_output("#{bin}/rifle -p 2 test.py")
end
end

__END__
diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py
index ffaa4c0..a7e027e 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -15,7 +15,6 @@ import base64
import curses
import errno
import fcntl
-import imghdr
import os
import struct
import sys
@@ -341,12 +340,28 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware):
with open(path, 'rb') as fobj:
return base64.b64encode(fobj.read()).decode('utf-8')

+ @staticmethod
+ def imghdr_what(path):
+ """Replacement for the deprecated imghdr module"""
+ with open(path, "rb") as img_file:
+ header = img_file.read(32)
+ if header[6:10] in (b'JFIF', b'Exif'):
+ return 'jpeg'
+ elif header[:4] == b'\xff\xd8\xff\xdb':
+ return 'jpeg'
+ elif header.startswith(b'\211PNG\r\n\032\n'):
+ return 'png'
+ if header[:6] in (b'GIF87a', b'GIF89a'):
+ return 'gif'
+ else:
+ return None
+
@staticmethod
def _get_image_dimensions(path):
"""Determine image size using imghdr"""
file_handle = open(path, 'rb')
file_header = file_handle.read(24)
- image_type = imghdr.what(path)
+ image_type = ITerm2ImageDisplayer.imghdr_what(path)
if len(file_header) != 24:
file_handle.close()
return 0, 0

0 comments on commit 314882b

Please sign in to comment.