Skip to content

Commit 9a4eb8b

Browse files
committed
Fix Homebrew formula: copy directories instead of symlinking to avoid read-only Cellar issues
- Changed from editable install to regular install, then back to editable - Unset VIRTUAL_ENV in wrapper to ensure mfc.sh uses copied venv - Copy venv, toolchain, and examples directories to tmpdir (not symlink) - This prevents pip install errors and path resolution issues - Formula now passes all tests including `mfc --help`
1 parent eef778c commit 9a4eb8b

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

packaging/homebrew/mfc.rb

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Mfc < Formula
2020
depends_on "openblas"
2121
depends_on "[email protected]"
2222

23+
# Preserve venv RECORD files (needed for pip to manage packages)
24+
skip_clean "libexec/venv"
25+
2326
def install
2427
# Create Python virtual environment
2528
venv = libexec/"venv"
@@ -31,6 +34,7 @@ def install
3134

3235
# Install MFC Python package and dependencies into venv
3336
# Keep toolchain in buildpath for now - mfc.sh needs it there
37+
# Use editable install (-e) to avoid RECORD file issues when venv is copied
3438
system venv/"bin/pip", "install", "-e", buildpath/"toolchain"
3539

3640
# Create symlink so mfc.sh uses our pre-installed venv
@@ -62,16 +66,15 @@ def install
6266
prefix.install "examples"
6367

6468
# Create smart wrapper script that:
65-
# 1. Works around read-only Cellar issue
66-
# 2. Activates venv automatically so cantera/dependencies are available
67-
# 3. Sets up toolchain symlink so mfc.sh can find toolchain/util.sh
69+
# 1. Works around read-only Cellar issue by copying venv to tmpdir
70+
# 2. Sets up toolchain symlink so mfc.sh can find toolchain/util.sh
71+
# 3. Ensures mfc.sh doesn't reinstall packages by copying pyproject.toml
6872
(bin/"mfc").write <<~EOS
6973
#!/bin/bash
7074
set -e
7175
72-
# Activate the pre-installed venv so all Python dependencies are available
73-
# This makes cantera and other packages accessible if users install them in the venv
74-
source "#{venv}/bin/activate"
76+
# Unset VIRTUAL_ENV to ensure mfc.sh uses the copied venv, not the Cellar one
77+
unset VIRTUAL_ENV
7578
7679
# Create a temporary working directory (Cellar is read-only)
7780
TMPDIR=$(mktemp -d)
@@ -81,12 +84,20 @@ def install
8184
cp "#{libexec}/mfc.sh" "$TMPDIR/"
8285
cd "$TMPDIR"
8386
84-
# Create toolchain symlink so mfc.sh can verify it's in MFC root folder
85-
ln -s "#{prefix}/toolchain" toolchain
87+
# Copy toolchain directory (not symlink) so Python paths resolve correctly
88+
# This prevents paths from resolving back to read-only Cellar
89+
cp -R "#{prefix}/toolchain" toolchain
90+
91+
# Copy examples directory (required by mfc.sh Python code)
92+
cp -R "#{prefix}/examples" examples
8693
87-
# Create build directory for mfc.sh to write to (with pre-existing venv symlink)
94+
# Create build directory and copy venv (not symlink - needs to be writable)
95+
# Use cp -R for a full recursive copy
8896
mkdir -p build
89-
ln -s "#{venv}" build/venv
97+
cp -R "#{venv}" build/venv
98+
99+
# Copy pyproject.toml to build/ so mfc.sh thinks dependencies are already installed
100+
cp "#{prefix}/toolchain/pyproject.toml" build/pyproject.toml
90101
91102
# Run mfc.sh with all arguments
92103
exec ./mfc.sh "$@"

0 commit comments

Comments
 (0)