This project, brewpyenv
, seems like a utility script for migrating Python dependencies managed by Homebrew to pyenv
. It identifies Brew-installed Python packages, replaces them with pyenv
-managed equivalents, and reconfigures the environment accordingly. Includes some solid logging and cleanup functionality.
- Repository: Belish
- Remote:
- Fetch:
https://github.com/jasonnathan/Belish.git
- Push:
https://github.com/jasonnathan/Belish.git
- Fetch:
.
├── LICENSE # Open-source license (unspecified in content above)
├── README.md # Likely placeholder or basic instructions
├── bun.lockb # Bun lockfile for dependency management
├── index.mjs # Entry point (not detailed above)
├── jsconfig.json # Likely for IDE configuration (VSCode, etc.)
├── package.json # Project metadata and scripts
├── pyenv_migration.log # Logs for migration process
├── util.mjs # Core logic for migration and utilities
└── util.test.mjs # Tests for `util.mjs`
-
util.mjs
:- Implements the core migration logic:
- Fetch Brew formulae and identify Python dependencies.
- Replace Brew Python versions with
pyenv
-managed ones. - Generate symlinks for compatibility.
- Update
.zshrc
to prioritizepyenv
paths.
- Handles logging with
winston
, saving logs inpyenv_migration.log
. - Code looks well-structured and async-heavy, with clean separation of logic.
- Implements the core migration logic:
-
util.test.mjs
:- Includes tests for
util.mjs
. They pass, which is reassuring. Seems to cover most functionality.
- Includes tests for
-
index.mjs
:- Entry point, probably orchestrates the workflow but isn’t shown above.
-
Setup:
- Clone the repository and install dependencies:
bun install
- Alternatively, if you’re using npm:
npm install
- Clone the repository and install dependencies:
-
Run the Migration:
- Execute the main migration logic:
node index.mjs
- Outputs logs to
pyenv_migration.log
for debugging.
- Execute the main migration logic:
-
Testing:
- Run tests to validate functionality:
node util.test.mjs
- Run tests to validate functionality:
-
Identify Brew-Managed Python:
- Scans installed Brew packages to find Python-related dependencies.
- Extracts unique Python versions (
python@X.Y
).
-
Replace with
pyenv
:- Installs equivalent Python versions using
pyenv
. - Generates symlinks for Brew binaries pointing to
pyenv
equivalents.
- Installs equivalent Python versions using
-
Reinstall Packages:
- Reinstalls Brew packages that depend on Python using the new environment.
-
Update Environment:
- Modifies
.zshrc
to prioritizepyenv
over Brew for Python management.
- Modifies
-
Cleanup:
- Removes old Brew-managed Python versions.
- Run Migration:
node index.mjs
- Test Utilities:
node util.test.mjs
-
General:
- Clean setup for managing Python environments. This script could save time if managing multiple Python versions via Brew was ever painful.
- Logging is solid, but the log file could grow large—might want a rotation mechanism.
-
Error Handling:
- Handles failures gracefully for most parts but could expand error messages for failed Brew or
pyenv
commands (e.g., missing versions).
- Handles failures gracefully for most parts but could expand error messages for failed Brew or
-
Next Steps:
- Add more command-line options (e.g., dry run mode, verbose logging).
- Expand the README to include instructions on usage and purpose.
- Consider packaging this as an NPM or Bun utility for easier reuse.
-
Refactoring:
index.mjs
likely orchestrates the workflow; could use some comments or splitting into multiple files for clarity.