quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.57k stars 294 forks source link

Improve MacOS Installer Path Handling #1661

Open iewaij opened 1 year ago

iewaij commented 1 year ago

Hi,

First, thanks so much for making this wonderful tool. I've been an active RMarkdown user, while also working heavily with a VS Code and Python. I'm very excited to see there's a RMarkdown equivalent outside R ecosystem, finally.

I intend to use Quarto with only Python and VS Code on macOS. After using homebrew to install quarto, which is the same as installing with the quarto-1.0.37-macos.pkg file, my shell can't find quarto in the PATH.

$ quarto
zsh: command not found: quarto

After some digging, I discovered that quarto-1.0.37-macos.pkg installed quarto folder in /Applications. A simple solution would be adding Applications/quarto/bin into my PATH. However, what I believe is a more elegant solution is following other command line tool installations such as youtube-dl.

For whomever facing the similar problem and also uses homebrew on macOS, I moved /Applications/quarto to /opt/homebrew/Cellar/quarto. Then I added the symbolic link of quarto to /opt/homebrew/bin/ using the following command (you can also just create a symbolic link without moving):

ln -s /opt/homebrew/Cellar/quarto/bin/quarto /opt/homebrew/bin/quarto

Now my shell can successfully pick quarto up.

quarto
dragonstyle commented 1 year ago

This likely specific to the home brew installation process- the pkg itself does have a post build script that creates a symlink in the path so I expect that something about the way home brew runs the pkg causes this. I will take a look soon!

iewaij commented 1 year ago

This likely specific to the home brew installation process- the pkg itself does have a post build script that creates a symlink in the path so I expect that something about the way home brew runs the pkg causes this. I will take a look soon!

I did try using pkg directly but it wasn't successful. And I believe the cask code is basically doing the same thing. Maybe I overlooked it.

dragonstyle commented 1 year ago

Hmm - ok that is good to know. Here is what we do post install:

#!/bin/sh

if [[ $EUID -eq 0 ]]; then
ln -fs $2/bin/quarto /usr/local/bin/quarto
else

# write path to zshenv
EXPORTLINE='export PATH="'$2'/bin:$PATH"'
EXPORTFILE=~/.zshenv

# Add the path to the zshenv if it doesn't already exist
grep -qxF "$EXPORTLINE" "$EXPORTFILE" || echo "$EXPORTLINE" >> "$EXPORTFILE"

# try creating symlink, its ok if this doesn't work
ln -fs $2/bin/quarto /usr/local/bin/quarto

fi

exit 0

Do you see anything that we're doing here is that is likely to be incompatible with your system? Its possible this works for many but not all system as it is making path assumptions + terminal assumptions...

baggiponte commented 1 year ago

A couple of observations:

  1. Would not assume zshenv is located in ~, you should use $ZDOTDIR/.zshenv (if $ZDOTDIR is unset, then $HOME is used)
  2. macOS messes up with $PATH (wrote about it here) so I believe that putting this in .zshenv won't be optimal. I'd rather append the line to .zshrc.

EDIT: for the moment I use this quick fix in my .zshrc:

if [ -x /Applications/quarto/bin/quarto ]; then
    alias quarto=/Applications/quarto/bin/quarto 
fi
baggiponte commented 1 year ago

Actually I just remembered this is highly coupled with #203. What I just realised is that quarto (using the official formula provided by quarto dev team) is symlinked under /usr/local/bin for both ARM and Intel macs. On the latter, that's not a problem; however on the former it is because the prefix is different! See the install script:

if [[ "${UNAME_MACHINE}" == "arm64" ]]
  then
    # On ARM macOS, this script installs to /opt/homebrew only
    HOMEBREW_PREFIX="/opt/homebrew"
    HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"
  else
    # On Intel macOS, this script installs to /usr/local only
    HOMEBREW_PREFIX="/usr/local"
    HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
  fi
  HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"

After you install brew, you should run the following: eval "$(homebrew/bin/brew shellenv)" - which does the following on an M1 mac:

export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";

So we should change the post-install script a bit like this:

#!/bin/sh

HOMEBREW_PREFIX="$(brew --prefix)"

# or, more complete
UNAME_MACHINE="$(/usr/bin/uname -m)"
if [[ "${UNAME_MACHINE}" == "arm64" ]]
  then
    homebrew_prefix="/opt/homebrew"
  else
    HOMEBREW_PREFIX="/usr/local"
  fi

if [[ $EUID -eq 0 ]]; then
    ln -fs "${2}/bin/quarto" "${HOMEBREW_PREFIX}/bin/quarto"
else

# write path to zshenv
EXPORTLINE='export PATH="'$2'/bin:$PATH"'
EXPORTFILE=~/.zshenv

# Add the path to the zshenv if it doesn't already exist
grep -qxF "$EXPORTLINE" "$EXPORTFILE" || echo "$EXPORTLINE" >> "$EXPORTFILE"

# try creating symlink, its ok if this doesn't work
ln -fs "${2}/bin/quarto" "${HOMEBREW_PREFIX}/bin/quarto"

fi

exit 0

I am not really aware of the contribution guidelines for quarto, but I'd be glad to help out with this.

allenmanning commented 1 year ago

@baggiponte Thanks for offer to contribute and sharing your expertise. As for your question about guidelines, have you seen https://github.com/quarto-dev/quarto-cli/blob/main/CONTRIBUTING.md

memeplex commented 4 months ago

Perhaps you could add the export line to .bashrc also. Or explain how to do it in the installation instructions.