Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iconsur: prepare virtualenv to avoid issues with [email protected] #165617

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 31 additions & 1 deletion Formula/i/iconsur.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require "language/node"

class Iconsur < Formula
include Language::Python::Virtualenv

desc "macOS Big Sur Adaptive Icon Generator"
homepage "https://github.com/rikumi/iconsur"
# Keep extra_packages in pypi_formula_mappings.json aligned with
# https://github.com/rikumi/iconsur/blob/#{version}/src/fileicon.sh#L230
url "https://registry.npmjs.org/iconsur/-/iconsur-1.7.0.tgz"
sha256 "d732df6bbcaf1418c6f46f9148002cbc1243814692c1c0e5c0cebfcff001c4a1"
license "MIT"
Expand All @@ -22,9 +26,35 @@ class Iconsur < Formula
depends_on :macos
depends_on "node"

# Uses /usr/bin/python on older macOS. Otherwise, it will use python3 from PATH.
# Since fileicon.sh runs `pip3 install --user` to install any missing packages,
# this causes issues if a user has Homebrew Python installed (EXTERNALLY-MANAGED).
# We instead prepare a virtualenv with all missing packages.
on_monterey :or_newer do
depends_on "[email protected]"
end

resource "pyobjc-core" do
url "https://files.pythonhosted.org/packages/50/d5/0b93cb9dc94ab4b78b2b7aa54c80f037e4de69897fff81a5ededa91d2704/pyobjc-core-10.1.tar.gz"
sha256 "1844f1c8e282839e6fdcb9a9722396c1c12fb1e9331eb68828a26f28a3b2b2b1"
end

resource "pyobjc-framework-cocoa" do
url "https://files.pythonhosted.org/packages/5d/1d/964a0da846d49511489bd99ed705f9d85c5081fc832d0dba384c4c0d2fb2/pyobjc-framework-Cocoa-10.1.tar.gz"
sha256 "8faaf1292a112e488b777d0c19862d993f3f384f3927dc6eca0d8d2221906a14"
end

def install
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
bin.install_symlink Dir["#{libexec}/bin/*"]

if MacOS.version >= :monterey
venv = virtualenv_create(libexec/"venv", "python3.12")
venv.pip_install resources
bin.install Dir["#{libexec}/bin/*"]
bin.env_script_all_files libexec/"bin", PATH: "#{venv.root}/bin:${PATH}"
else
bin.install_symlink Dir["#{libexec}/bin/*"]
end
end

test do
Expand Down
4 changes: 4 additions & 0 deletions pypi_formula_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@
"huggingface-cli": {
"exclude_packages": ["certifi"]
},
"iconsur": {
"package_name": "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this line?

Copy link
Member Author

@cho-m cho-m Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's special brew logic I added to allow brew update-python-resources iconsur to work (since iconsur is not a Python package).

Once I finish Homebrew/brew#16780, bump/bump-formula-pr will automatically update resources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, good to know 👍

"extra_packages": ["pyobjc-core", "pyobjc-framework-cocoa"]
},
"img2pdf": {
"exclude_packages": ["pillow"]
},
Expand Down