Skip to content

Commit 9027349

Browse files
sbryngelsonAI Assistantqodo-merge-pro[bot]
authored
Homebrew formula (#1039)
Co-authored-by: AI Assistant <[email protected]> Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
1 parent d5e7059 commit 9027349

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Install the prebuilt package and run an example:
146146
brew install mflowcode/mfc/mfc
147147
mkdir -p ~/mfc_quickstart && cd ~/mfc_quickstart
148148
cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py .
149-
mfc run case.py -n 2
149+
mfc case.py -n 2
150150
```
151151

152152
Use `-n X` to select the number of MPI processes. For developer commands (`build`, `test`, etc.), clone the repo and use `./mfc.sh`.

docs/documentation/getting-started.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ Run a quick example:
2323
mkdir -p ~/mfc_quickstart && cd ~/mfc_quickstart
2424
cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py .
2525
# Use -n X to choose the number of MPI processes
26-
mfc run case.py -n 2
26+
mfc case.py -n 2
2727
```
2828

2929
Notes:
30-
- The Homebrew wrapper supports only `mfc run ...`. Developer commands like `build`, `test`, `clean` are available when you clone the repo and use `./mfc.sh`.
30+
- The Homebrew package uses a simplified syntax: just `mfc <case.py>` to run cases.
31+
- Developer commands like `build`, `test`, `clean` are available when you clone the repo and use `./mfc.sh`.
3132
- The package bundles a Python venv and prebuilt binaries; no additional setup is required.
3233
- Examples are installed at `$(brew --prefix mfc)/examples/`.
3334

docs/documentation/running.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ several supercomputer clusters, both interactively and through batch submission.
1313
If you installed MFC via Homebrew, run cases with the `mfc` wrapper:
1414

1515
```bash
16-
mfc run <path/to/case.py> -n 2
16+
mfc <path/to/case.py> -n 2
1717
```
1818

1919
- Use `-n X` to control the number of MPI processes (ranks).
20-
- Only the `run` command is supported in the Homebrew wrapper.
20+
- The Homebrew package uses a simplified syntax: just `mfc <case.py>` to run cases.
2121
- To use developer commands (`build`, `test`, `clean`, etc.), clone the repository and use `./mfc.sh`.
2222
- The wrapper passes through runtime flags like `-t pre_process simulation`, `-n`, and others; it always runs with preinstalled binaries.
2323
- Examples live at `$(brew --prefix mfc)/examples/`.

packaging/homebrew/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Run the 1D Sod shock tube example:
1515
```bash
1616
mkdir -p ~/mfc_example && cd ~/mfc_example
1717
cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py .
18-
mfc run case.py -n 2
18+
mfc case.py -n 2
1919
```
2020

2121
## What's Included
@@ -28,12 +28,12 @@ mfc run case.py -n 2
2828
## Usage
2929

3030
```bash
31-
mfc run <case.py> -n <processes>
31+
mfc <case.py> -n <processes>
3232
```
3333

3434
Use `-n X` to set the number of MPI processes.
3535

36-
**Note**: The Homebrew wrapper supports only `mfc run`. For developer commands (`build`, `test`, `clean`, etc.), [clone the repository](https://github.com/MFlowCode/MFC) and use `./mfc.sh`.
36+
**Note**: The Homebrew wrapper supports only running cases. For developer commands (`build`, `test`, `clean`, etc.), [clone the repository](https://github.com/MFlowCode/MFC) and use `./mfc.sh`.
3737

3838
## Documentation
3939

packaging/homebrew/mfc.rb

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,17 @@ def install
9494
fi
9595
done
9696
97-
SUBCMD="${ARGS[0]-}"
98-
9997
# Friendly help and guardrails
100-
if [[ ${#ARGS[@]} -eq 0 ]] || [[ "${SUBCMD}" == "--help" ]] || [[ "${SUBCMD}" == "-h" ]]; then
98+
if [[ ${#ARGS[@]} -eq 0 ]] || [[ "${ARGS[0]-}" == "--help" ]] || [[ "${ARGS[0]-}" == "-h" ]]; then
10199
cat <<'HHELP'
102100
MFC (Homebrew) #{version}
103101
104102
Usage:
105103
mfc <case.py> [options]
106-
mfc run <case.py> [options]
107104
108105
Examples:
109106
mfc case.py -n 2
110-
mfc run case.py -n 2 -t pre_process simulation
107+
mfc examples/1D_sodshocktube/case.py -n 2 -t pre_process simulation
111108
112109
Notes:
113110
- This Homebrew wrapper uses prebuilt binaries and a preinstalled venv.
@@ -117,18 +114,48 @@ def install
117114
exit 0
118115
fi
119116
120-
# Smart detection: if first arg looks like a case file, auto-prepend "run"
121-
if [[ "${SUBCMD}" =~ .py$ ]] || [[ -f "${SUBCMD}" ]]; then
122-
ARGS=("run" "${ARGS[@]}")
123-
SUBCMD="run"
117+
# Handle --version flag
118+
if [[ "${ARGS[0]-}" == "--version" ]] || [[ "${ARGS[0]-}" == "-v" ]]; then
119+
echo "MFC (Homebrew) #{version}"
120+
exit 0
124121
fi
125122
126-
if [[ "${SUBCMD}" != "run" ]]; then
127-
echo "mfc (Homebrew): only 'run' is supported in the Homebrew package."
128-
echo "Use 'mfc <case.py>' or clone the repository for developer commands."
123+
# Find first non-flag argument
124+
first_nonflag=""
125+
for arg in "${ARGS[@]}"; do
126+
if [[ "$arg" != -* ]]; then
127+
first_nonflag="$arg"
128+
break
129+
fi
130+
done
131+
132+
# Check if no case file provided
133+
if [[ -z "${first_nonflag}" ]]; then
134+
echo "mfc (Homebrew): missing case file."
135+
echo "Usage: mfc <case.py> [options]"
136+
echo "Example: mfc case.py -n 2"
129137
exit 2
130138
fi
131139
140+
# Check if user accidentally used 'mfc run' syntax (even with flags before it)
141+
if [[ "${first_nonflag}" == "run" ]]; then
142+
echo "mfc (Homebrew): The 'run' command is not needed."
143+
echo "Usage: mfc <case.py> [options]"
144+
echo "Example: mfc case.py -n 2"
145+
exit 2
146+
fi
147+
148+
# Require a readable Python file (not a directory)
149+
if [[ ! "${first_nonflag}" =~ .py$ ]] || [[ ! -f "${first_nonflag}" ]]; then
150+
echo "mfc (Homebrew): first argument must be a readable Python case file."
151+
echo "Given: ${first_nonflag}"
152+
echo "Usage: mfc <case.py> [options]"
153+
exit 2
154+
fi
155+
156+
# Always prepend "run" since this wrapper only supports running cases
157+
ARGS=("run" "${ARGS[@]}")
158+
132159
# Create a temporary working directory (Cellar is read-only)
133160
TMPDIR="$(mktemp -d)"
134161
trap 'rm -rf "${TMPDIR}"' EXIT
@@ -226,8 +253,7 @@ def caveats
226253
MFC has been installed successfully!
227254
228255
To run a case:
229-
mfc <case.py>
230-
mfc run <case.py> (explicit form)
256+
mfc <case.py> [options]
231257
232258
Pre-built binaries are also available directly:
233259
pre_process, simulation, post_process

0 commit comments

Comments
 (0)