Repository: repobee/repobee (language: python)

Issue:
Minor typo in resolve_repobee_pip_uri function of install.sh
First off, thanks for writing this tool and making it available!

On recent install attempt, I wanted to use `master` branch, but `install.sh master` failed with invalid URL (due to trailing `@` without tag). I suspect [line 220 of `scripts/install.sh`](https://github.com/repobee/repobee/blob/master/scripts/install.sh#L220) should be changed to

```diff
-            repobee_pip_uri="git+$REPOBEE_HTTPS_URL.git@$version"
+            repobee_pip_uri="git+$REPOBEE_HTTPS_URL.git@$1"
```
since `$version` is not defined in the `resolve_repobee_pip_uri` function.

---
FWIW, this was encountered after trying to install default (which currently is `v3.8.0` tag) using python=3.11.1 via pyenv (on Ubuntu 20.04 LTS). In that case, venv gets created but then the `$HOME/env/bin/pip install --upgrade 'git+https://github.com/repobee/repobee.git@v3.8.0'` command fails, with some sort of syntax error on the  [`"dataclasses>='0.7';python_version<'3.7'"` setup requirement spec](https://github.com/repobee/repobee/blob/v3.8.0/setup.py#L87).

Did not investigate further, as `master` (which drops 3.7 support and the apparently offending requirement) installed just fine.


Discussion / hints:
Hi @spapadim,

> On recent install attempt, I wanted to use master branch, but install.sh master failed with invalid URL (due to trailing @ without tag). I suspect [line 220 of scripts/install.sh](https://github.com/repobee/repobee/blob/master/scripts/install.sh#L220) should be changed to

You are absolutely right. Looking over the install script I found a number of more issues, I will upload an improved version shortly.

> FWIW, this was encountered after trying to install default (which currently is v3.8.0 tag) [.. ] Did not investigate further, as master (which drops 3.7 support and the apparently offending requirement) installed just fine.

Oof, that's not good, the primary install path isn't working for the currently released version. That version specifier should not have single quotes around `'0.7'`, I don't understand how that ever worked :s.

I will make a new release ASAP.
I've released RepoBee v3.8.1 which can actually be installed with the current install script, making fixing it a little bit less urgent. The install script will follow sometime tonight. I obviously need a periodic CI job that ensures that the installer can actually run on the current release...

Thanks for making this problem known to me @spapadim !
Turns out I'd thought ahead at some point and already have tests for the latest release, the scheduled weekly tests failed miserably this weekend. Something in the cosmos changed such that the invalid syntax in that requirement was actually caught to be invalid.

Fix patch:
diff --git a/scripts/install.sh b/scripts/install.sh
index 6246784d..f87df342 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -1,8 +1,10 @@
 #! /bin/bash
 
-if [ -z "$REPOBEE_INSTALL_DIR" ]; then
-    REPOBEE_INSTALL_DIR="$HOME/.repobee"
-fi
+set -o errexit
+set -o nounset
+
+REPOBEE_INSTALL_DIR=${REPOBEE_INSTALL_DIR:-"$HOME/.repobee"}
+REPOBEE_INSTALL_NONINTERACTIVE=${REPOBEE_INSTALL_NONINTERACTIVE:-"false"}
 
 echo "Using install dir '$REPOBEE_INSTALL_DIR'"
 REPOBEE_BIN_DIR="$REPOBEE_INSTALL_DIR/bin"
@@ -77,7 +79,7 @@ function install_repobee() {
     source "$REPOBEE_ENV_ACTIVATE"
     ensure_pip_installed
 
-    echo "Installing RepoBee $version"
+    echo "Installing RepoBee $repobee_pip_uri"
     REPOBEE_INSTALL_DIR="$REPOBEE_INSTALL_DIR" pip_install_quiet_failfast "$repobee_pip_uri"
     create_repobee_executable
 
@@ -165,10 +167,15 @@ function create_repobee_executable() {
 }
 
 function add_to_path() {
+    if [ "$REPOBEE_INSTALL_NONINTERACTIVE" = true ]; then
+        echo "Non-interactive mode, skipping PATH modification"
+        return
+    fi
+
     printf "\n$REPOBEE_BIN_DIR is not on the PATH, so to run RepoBee you must type the full path to $REPOBEE_EXECUTABLE.\n"
     echo "We can add try to add $REPOBEE_BIN_DIR to your PATH by adding it to your profile files (e.g. .bashrc, .zshrc, config.fish, etc), and then you just need to type 'repobee' to run it."
     echo "If you know how to do this manually, then we recommend that you do so such that you get it the way you like it."
-    echo "Do you want us to add try to $REPOBEE_BIN_DIR to your PATH? [y/N]: "
+    echo "Do you want us to try to add $REPOBEE_BIN_DIR to your PATH? [y/N]: "
 
     # careful with read, its options work differently in zsh and bash
     read confirm
@@ -213,23 +220,29 @@ To enable tab completion, see https://docs.repobee.org/en/stable/install.html#ta
 
 function resolve_repobee_pip_uri() {
     # the optional argument can be either a version tag, or a local filepath
-    if [ $1 ]; then
-        if [ -d "$1" ]; then
-            repobee_pip_uri="$1"
+    version="${1:-}"
+    if [ "$version" ]; then
+        if [ -d "$version" ]; then
+            repobee_pip_uri="$version"
         else
             repobee_pip_uri="git+$REPOBEE_HTTPS_URL.git@$version"
         fi
     else
-        repobee_pip_uri="git+$REPOBEE_HTTPS_URL.git@$(get_latest_version)"
+        repobee_pip_uri="repobee==$(get_latest_version)"
     fi
     echo "$repobee_pip_uri"
 }
 
-install "$(resolve_repobee_pip_uri $1)"
-create_autocomplete_scripts
-auto_complete_msg
+function main() {
+    version="${1:-}"
+    install "$(resolve_repobee_pip_uri $version)"
+    create_autocomplete_scripts
+    auto_complete_msg
 
-echo "
+    echo "
 RepoBee was installed successfully. To uninstall, simply remove the directory at $REPOBEE_INSTALL_DIR
 If you are having trouble, please visit the FAQ at https://repobee.readthedocs.io/en/stable/faq.html
-"
+    "
+}
+
+main "${1:-}"


Test patch:
diff --git a/tests/integration_tests/test_dist.py b/tests/integration_tests/test_dist.py
index a208fe7f..1e468999 100644
--- a/tests/integration_tests/test_dist.py
+++ b/tests/integration_tests/test_dist.py
@@ -558,11 +558,12 @@ def install_dir():
 def run_install_script(install_dir: pathlib.Path) -> None:
     env = dict(os.environ)
     env["REPOBEE_INSTALL_DIR"] = str(install_dir)
+    env["REPOBEE_INSTALL_NONINTERACTIVE"] = "true"
 
     with subprocess.Popen(str(INSTALL_SCRIPT), env=env) as process:
         process.communicate(
-            "n"
-        )  # 'n' in answering whether or not to add to PATH
+            "N"
+        )  # 'N' in answering whether or not to add to PATH
     assert process.returncode == 0