Adds path(s) for Brew 's binaries to env['PATH']. We assert-fail if the relevant directory does no exist. Args: package: Name of package. We get of installed package by running `brew --prefix `. env:
(package, env=None, gnubin=True)
| 3428 | |
| 3429 | |
| 3430 | def macos_add_brew_path(package, env=None, gnubin=True): |
| 3431 | ''' |
| 3432 | Adds path(s) for Brew <package>'s binaries to env['PATH']. |
| 3433 | |
| 3434 | We assert-fail if the relevant directory does no exist. |
| 3435 | |
| 3436 | Args: |
| 3437 | package: |
| 3438 | Name of package. We get <package_root> of installed package by |
| 3439 | running `brew --prefix <package>`. |
| 3440 | env: |
| 3441 | The environment dict to modify. If None we use os.environ. If PATH |
| 3442 | is not in <env>, we first copy os.environ['PATH'] into <env>. |
| 3443 | gnubin: |
| 3444 | If true, we also add path to gnu binaries if it exists, |
| 3445 | <package_root>/libexe/gnubin. |
| 3446 | ''' |
| 3447 | if not darwin(): |
| 3448 | return |
| 3449 | if env is None: |
| 3450 | env = os.environ |
| 3451 | if 'PATH' not in env: |
| 3452 | env['PATH'] = os.environ['PATH'] |
| 3453 | package_root = run(f'brew --prefix {package}', capture=1).strip() |
| 3454 | log(f'{package=} {package_root=}') |
| 3455 | def add(path): |
| 3456 | log(f'{path=}') |
| 3457 | if os.path.isdir(path): |
| 3458 | log(f'Prepending to $PATH: {path}') |
| 3459 | PATH = env['PATH'] |
| 3460 | env['PATH'] = f'{path}:{PATH}' |
| 3461 | return 1 |
| 3462 | else: |
| 3463 | log(f'Not a directory: {path=}') |
| 3464 | return 0 |
| 3465 | n = 0 |
| 3466 | n += add(f'{package_root}/bin') |
| 3467 | if gnubin: |
| 3468 | n += add(f'{package_root}/libexec/gnubin') |
| 3469 | assert n, f'Failed to add to $PATH, {package=} {gnubin=}.' |
| 3470 | |
| 3471 | |
| 3472 | def _show_dict(d): |