Skip to content

Commit 0971f4f

Browse files
committed
Add Cantera dependency and pre-install Python venv
Install Cantera and create a Python virtual environment during formula installation, eliminating the need for mfc to create its own venv on first run. This enables full functionality immediately after installation. Changes to formula: - Add cantera as a runtime dependency - Move [email protected] from build-only to runtime dependency - Create Python venv in libexec/venv during installation - Install MFC Python package and all dependencies into venv - Update wrapper to activate pre-installed venv - Link venv into build directory so mfc.sh uses existing environment - Add venv verification to test block - Re-enable mfc --help test since venv is ready Changes to CI: - Add cantera to dependency installation step - Verify venv contains cantera and mfc packages Benefits: - mfc commands work immediately (no setup on first run) - All examples including those requiring Cantera work out of the box - Much faster execution since venv is reused - No cantera==3.1.0 not found errors
1 parent 2152b36 commit 0971f4f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

.github/workflows/homebrew.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install formula dependencies
3636
run: |
3737
echo "Installing MFC dependencies..."
38-
brew install cmake gcc [email protected] boost fftw hdf5 open-mpi openblas
38+
brew install cmake gcc [email protected] boost cantera fftw hdf5 open-mpi openblas
3939
4040
- name: Validate formula syntax
4141
run: |
@@ -100,6 +100,11 @@ jobs:
100100
ls -la $(brew --prefix)/libexec/mfc.sh
101101
ls -la $(brew --prefix)/share/mfc/examples/
102102
103+
echo "Checking Python venv..."
104+
ls -la $(brew --prefix)/Cellar/mfc/*/libexec/venv/
105+
$(brew --prefix)/Cellar/mfc/*/libexec/venv/bin/python --version
106+
$(brew --prefix)/Cellar/mfc/*/libexec/venv/bin/pip list | grep -E "(cantera|mfc)"
107+
103108
echo "Installation verified successfully!"
104109
105110
- name: Uninstall and cleanup

packaging/homebrew/mfc.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ class Mfc < Formula
1212

1313
depends_on "cmake" => :build
1414
depends_on "gcc" => :build
15-
depends_on "[email protected]" => :build
1615

1716
depends_on "boost"
17+
depends_on "cantera"
1818
depends_on "fftw"
1919
depends_on "hdf5"
2020
depends_on "open-mpi"
2121
depends_on "openblas"
22+
depends_on "[email protected]"
2223

2324
def install
2425
# MFC uses a Python wrapper script for building
@@ -46,12 +47,24 @@ def install
4647
# Install examples
4748
pkgshare.install "examples"
4849

50+
# Create Python virtual environment with MFC dependencies
51+
venv = libexec/"venv"
52+
system Formula["[email protected]"].opt_bin/"python3.12", "-m", "venv", venv
53+
54+
# Install MFC Python package and dependencies into venv
55+
system venv/"bin/pip", "install", "--upgrade", "pip", "setuptools", "wheel"
56+
system venv/"bin/pip", "install", "-e", prefix/"toolchain"
57+
4958
# Create a wrapper that sets up a working environment for mfc.sh
50-
# The wrapper uses a temporary directory since Cellar is read-only
59+
# The wrapper uses a temporary directory since Cellar is read-only and
60+
# activates the pre-installed Python virtual environment
5161
(bin/"mfc").write <<~EOS
5262
#!/bin/bash
5363
set -e
5464
65+
# Activate the pre-installed Python virtual environment
66+
source "#{libexec}/venv/bin/activate"
67+
5568
# Create a working directory for MFC in user's cache
5669
MFC_WORK_DIR="${TMPDIR:-/tmp}/mfc-homebrew-$$"
5770
mkdir -p "$MFC_WORK_DIR"
@@ -67,6 +80,10 @@ def install
6780
ln -sf "#{prefix}/toolchain" toolchain
6881
ln -sf "#{libexec}/mfc.sh" mfc.sh
6982
ln -sf "#{pkgshare}/examples" examples
83+
84+
# Link the venv so mfc.sh doesn't try to create its own
85+
mkdir -p build
86+
ln -sf "#{libexec}/venv" build/venv
7087
7188
# Set up environment variables
7289
export MFC_INSTALL_DIR="#{prefix}"
@@ -114,8 +131,16 @@ def caveats
114131
assert_path_exists prefix/"toolchain"
115132
assert_path_exists prefix/"toolchain/mfc"
116133

134+
# Verify Python venv was created with dependencies
135+
assert_path_exists libexec/"venv"
136+
assert_path_exists libexec/"venv/bin/python"
137+
assert_path_exists libexec/"venv/bin/pip"
138+
117139
# Verify examples were installed
118140
assert_path_exists pkgshare/"examples"
119141
assert_path_exists pkgshare/"examples/1D_sodshocktube/case.py"
142+
143+
# Test mfc wrapper functionality with pre-installed venv
144+
system bin/"mfc", "--help"
120145
end
121146
end

0 commit comments

Comments
 (0)