this code works great for bash shell, how to fix it for macos zsh? .ONESHELL: Need to…
- User
this code works great for bash shell, how to fix it for macos zsh? .ONESHELL:
Need to specify bash in order for conda activate to work.
SHELL=/bin/zsh ROOT_DIR=(HOME)/mambaforge/bin/:$(PATH)
MAMBA requires two inits
SOURCE=source ($(MANAGER) info)/etc/profile.d/conda.sh; source ((MANAGER).sh
Note that the extra activate is needed to ensure that the activate floats env to the front of PATH
ACTIVATE=(MANAGER) activate $(ENV_NAME)
ACTIVATE=(MANAGER) activate ; (ENV_NAME)
Prerequisite: mambaforge installed
Creates a proper environment from the environment file
create_env_from_file: $(MANAGER) env create -f environment.yml
Builds the current repo and installs into the environment
install_pkg: ($(ACTIVATE); pip install .)
Builds the current repo and installs into the environment, while also tracking any new changes to it.
develop: ($(ACTIVATE); pip install -e .)
Removes the package from the env
uninstall_pkg: ((PACKAGE_NAME))
build_env: git submodule update --init make create_env_from_file ($(ACTIVATE); pre-commit install) make install_pkg
doc: cd ./docs && ($(ACTIVATE); make html)
clean: ((MANAGER) deactivate; (ENV_NAME) -y)
update: make uninstall_pkg make install_pkg
test: ($(ACTIVATE); pytest)
- Assistant
To adapt your Makefile code for Zsh (
zshshell) on macOS, we need to make a few changes. The adjustments mainly pertain to how command substitution and environment variable declarations are handled inzsh.Here's an updated version of your code that should work properly with
zsh:.SHELLFLAGS = -c # Specify Zsh as the shell SHELL = /bin/zsh ROOT_DIR = $(PWD) PACKAGE_NAME = aps_core_py MANAGER = mamba ENV_NAME = aps-core-py-env export PATH := $(HOME)/mambaforge/bin/:$(PATH) # MAMBA requires two inits SOURCE = source $$(mamba info)/etc/profile.d/conda.sh; source $$(mamba info)/etc/profile.d/$(MANAGER).sh # Note that the extra activate is needed to ensure that the activate floats env to the front of PATH ACTIVATE = $$(SOURCE); $$(MANAGER) activate; $$(MANAGER) activate $(ENV_NAME) # Prerequisite: mambaforge installed # Creates a proper environment from the environment file create_env_from_file: $(MANAGER) env create -f environment.yml # Builds the current repo and installs into the environment install_pkg: ($$(ACTIVATE); pip install .) # Builds the current repo and installs into the environment, while also tracking any new changes to it. develop: ($$(ACTIVATE); pip install -e .) # Removes the package from the env uninstall_pkg: ($$(ACTIVATE); pip uninstall -y $(PACKAGE_NAME)) build_env: git submodule update --init make create_env_from_file ($$(ACTIVATE); pre-commit install) make install_pkg doc: cd ./docs && ($$(ACTIVATE); make html) clean: ($$(SOURCE); $$(MANAGER) deactivate; $$(MANAGER) env remove --name $(ENV_NAME) -y) update: make uninstall_pkg make install_pkg test: ($$(ACTIVATE); pytest)Key Changes Made:
-
Escape the dollar sign: In
zsh, you need to use$$to refer to the Makefile variable rather than$. This is because$is also used to denote variable substitution inzsh, hence doubling it is necessary inside a Makefile to ensure it's recognized correctly. -
SHELLFLAGS: Added
-ctoSHELLFLAGSto ensure that each line is treated as a command rather than a simple script file, allowing multiple commands to run in the subshells properly. -
Source command handling: The source command is used correctly in
zsh; just ensure that the scripts frommambaorcondaare available.
Everything else seems to work fine with
zsh, but you might still want to verify ifmambaoperates correctly in azshsetting, especially with path visibility and function availability.Now you should be able to run this Makefile seamlessly on a macOS machine using
zsh. -