Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

this code works great for bash shell, how to fix it for macos zsh? .ONESHELL: Need to…

  1. 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=(PWD)PACKAGENAME=apscorepyMANAGER=mambaENVNAME=aps−core−py−envexportPATH:=(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 ($(MANAGER) info)/etc/profile.d/conda.sh; source ((MANAGER)info)/etc/profile.d/(MANAGER) 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=(MANAGER)init;(MANAGER) init;(MANAGER) activate $(ENV_NAME)

    ACTIVATE=(SOURCE);(SOURCE); (MANAGER) activate ; (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);pipuninstall−y(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);(SOURCE); (MANAGER) deactivate; (MANAGER)envremove−−name(MANAGER) env remove --name (ENV_NAME) -y)

    update: make uninstall_pkg make install_pkg

    test: ($(ACTIVATE); pytest)

  2. Assistant

    To adapt your Makefile code for Zsh (zsh shell) on macOS, we need to make a few changes. The adjustments mainly pertain to how command substitution and environment variable declarations are handled in zsh.

    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:

    1. 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 in zsh, hence doubling it is necessary inside a Makefile to ensure it's recognized correctly.

    2. SHELLFLAGS: Added -c to SHELLFLAGS to ensure that each line is treated as a command rather than a simple script file, allowing multiple commands to run in the subshells properly.

    3. Source command handling: The source command is used correctly in zsh; just ensure that the scripts from mamba or conda are available.

    Everything else seems to work fine with zsh, but you might still want to verify if mamba operates correctly in a zsh setting, especially with path visibility and function availability.

    Now you should be able to run this Makefile seamlessly on a macOS machine using zsh.