Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using bpkg to install bashunit #168

Open
Chemaclass opened this issue Sep 23, 2023 · 10 comments
Open

Using bpkg to install bashunit #168

Chemaclass opened this issue Sep 23, 2023 · 10 comments
Assignees
Labels

Comments

@Chemaclass
Copy link

I am trying to install bashunit in my local using bpkg, but I dont know exactly what am I doing wrong 🤔

What does this error means? error: Missing "bpkg-json" dependency
What's the ideal way to use this library?
Wouldn’t be a good idea to create a symlink from ~/.local/bin/bpkg to /bin/bpkg when using the curl installation?

Screenshot 2023-09-23 at 13 32 17
@Potherca
Copy link
Member

Potherca commented Sep 26, 2023

On most systems, once installed to /home/ben/.local/bin/, calling bpkg should Just Work:tm:

Running curl -sLo- get.bpkg.sh | bash and bpkg install TypedDevs/bashunit works for me... Calling bpkg-install directly also seems to work.

Full output
/tmp$ curl -sLo- get.bpkg.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3192  100  3192    0     0  13243      0 --:--:-- --:--:-- --:--:-- 13244
  info: Welcome to the 'bpkg' installer!
  info: Checking for git...

  info: Creating temporary files...
  info: Fetching 'bpkg@1.1.4'...
  info: Installing...

  info: Uninstalling /home/ben/.local/bin/bpkg*
    rm: /home/ben/.local/bin/bpkg'
  info: Installing /home/ben/.local/bin/bpkg...
  info: Done!
/tmp$ bpkg install TypedDevs/bashunit

    info: Install /TypedDevs/bashunit/master from remote https://raw.githubusercontent.com [https://github.com]
    info: Install dependencies for bashunit
    fetch: https://raw.githubusercontent.com//TypedDevs/bashunit/master/bashunit
    warn: BPKG_PACKAGE_DEPS is '/tmp/deps'
    write: /tmp/deps/bashunit/bashunit
    bashunit to PATH: /tmp/deps/bin/bashunit
/tmp$ bash $(which bpkg-install) TypedDevs/bashunit

    info: Install /TypedDevs/bashunit/master from remote https://raw.githubusercontent.com [https://github.com]
    info: Install dependencies for bashunit
    fetch: https://raw.githubusercontent.com//TypedDevs/bashunit/master/bashunit
    warn: BPKG_PACKAGE_DEPS is '/tmp/deps'
    write: /tmp/deps/bashunit/bashunit
    bashunit to PATH: /tmp/deps/bin/bashunit

@Chemaclass Could you verify that calling bpkg --version (from any directory other than your .local bin) works?

Using bpkg install bashunit won't work until TypedDevs/bashunit has been cloned/mirrored under https://github.com/bpkg/

@Potherca Potherca transferred this issue from bpkg/bpkg.github.io Sep 26, 2023
@Potherca Potherca self-assigned this Sep 26, 2023
@Chemaclass
Copy link
Author

Chemaclass commented Sep 26, 2023

My issue is that after running curl -sLo- get.bpkg.sh | bash something seems wrong, because I cannot execute bpkg even when the installer says everything was fine 🤔
Screenshot 2023-09-26 at 18 00 25

Screenshot 2023-09-26 at 18 04 04

🎥 Demo

Screen.Recording.2023-09-26.at.17.59.16.mov

@Potherca
Copy link
Member

Potherca commented Sep 27, 2023

Looks like $HOME/.local/bin is not sourced, hence bpkg not being found. That is also the cause of all the other errors.

The option here are:

  1. Install as sudo to have BPKG installed in/usr/local/bin
  2. Set a $PREFIX when installing: (PREFIX=/path/to/bin; curl -sLo- get.bpkg.sh | bash)
  3. Add $HOME/.local/bin to your startup script to be included in $PATH

@samlikins
Copy link
Member

samlikins commented Sep 27, 2023

@Potherca, not to spur any controversy, but I'd recommend the following (single line) command (option #2) instead:

(PREFIX=/path/to/bin; curl -sLo- get.bpkg.sh | bash)

This approach keeps the PREFIX variable from contaminating the session after the command executes and you can keep the pipe into bash not downloading the install script into a file. I believe you can even prefix the command with sudo to install as root too. If you don't care about contamination, you can drop the parenthesis.

Beyond the suggestion of the install option, I'd also encourage (if installing as a non-root user) add the user bin directory to the PATH environment variable to the user shell "profile" file (option #3). Most systems with Bash installed have a .profile file in user directories, and Zsh has a .zshrc file in its stead.

@Potherca
Copy link
Member

Potherca commented Sep 27, 2023

@samlikins Good call! I'll updated my response. 👍

Wouldn't PREFIX need to be export PREFIX to be available? (I'm still not 100% fluent in BASH scoping...)

I do know Zsh doesn't load .profile and neither does BASH when .bash_profile exists. I'm wondering if we might need to mention this somewhere in the docs.

@samlikins
Copy link
Member

@Potherca, nice thought. The export keyword is only used to make the specified variable(s) available in sub-process (ie: child processes). This format does the same thing as prefixing the command with an env set (ie: VAR=foo command). An export would only be necessary if in the command being called the variable was being used in a sub-process, at which point I'd hope the command was written to consider that fact too. If using this style doesn't work for some usage, trying export in front wouldn't be a bad adaptation.

@khru
Copy link

khru commented Sep 27, 2023

@Potherca I've Install bpkg with the command that @samlikins shared (PREFIX=/path/to/bin; curl -sLo- get.bpkg.sh | bash) and bashunitwith the command you shared bpkg install TypedDevs/bashunit and things I see:

Output
bpkg install TypedDevs/bashunit

    info: Install /TypedDevs/bashunit/master from remote https://raw.githubusercontent.com [https://github.com]
    info: Install dependencies for bashunit
    fetch: https://raw.githubusercontent.com//TypedDevs/bashunit/master/bashunit
    warn: BPKG_PACKAGE_DEPS is '/home/evalverde/deps'
    write: /home/evalverde/deps/bashunit/bashunit
    bashunit to PATH: /home/evalverde/deps/bin/bashunit

If I try to run it from the terminal as bashunit it says:

bashunit
zsh: command not found: bashunit

I guess because the script it's not on the $PATH.

But if I run /home/evalverde/deps/bin/bashunit what I get it's:

Output
/home/evalverde/deps/bin/bashunit: línea 11: /home/evalverde/deps/bin/src/default_env_config.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 12: /home/evalverde/deps/bin/src/env_configuration.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 13: /home/evalverde/deps/bin/src/check_os.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 14: /home/evalverde/deps/bin/src/state.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 15: /home/evalverde/deps/bin/src/colors.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 16: /home/evalverde/deps/bin/src/console_results.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 17: /home/evalverde/deps/bin/src/helpers.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 18: /home/evalverde/deps/bin/src/assert.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 19: /home/evalverde/deps/bin/src/test_doubles.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 20: /home/evalverde/deps/bin/src/runner.sh: No existe el archivo o el directorio
/home/evalverde/deps/bin/bashunit: línea 44: Runner::loadTestFiles: orden no encontrada
/home/evalverde/deps/bin/bashunit: línea 1: State::getTestsPassed: orden no encontrada
/home/evalverde/deps/bin/bashunit: línea 1: State::getTestsFailed: orden no encontrada
/home/evalverde/deps/bin/bashunit: línea 1: State::getAssertionsPassed: orden no encontrada
/home/evalverde/deps/bin/bashunit: línea 1: State::getAssertionsFailed: orden no encontrada
/home/evalverde/deps/bin/bashunit: línea 1: Console::renderResult: orden no encontrada

I think the installer it's not working correctly, right?

@samlikins
Copy link
Member

@khru, it looks like you're attempting to install BashUnit globally (not as a dependency), but I think you forgot to add the global flag. The project should have been installed in ~/.local/bin, which should also be in your PATH.

@Chemaclass
Copy link
Author

Chemaclass commented Sep 28, 2023

I added export PATH=$HOME/.local/bin:$PATH to my ~/.zshrc,
and then after running (PREFIX=~/.local/bin; curl -sLo- get.bpkg.sh | bash)
then I was able to use bpkg install TypedDevs/bashunit

And now this is the output:
Screenshot 2023-09-28 at 03 07 06

I think this is because in the installation command we are copying only the entry point file, and not all src/* files

Screenshot 2023-09-28 at 03 08 35

Is this the right place to change? https://github.com/TypedDevs/bashunit/blob/main/bpkg.json#L5 or somewhere else? 🤔

Note: I remember this was a suggestion from here TypedDevs/bashunit#90 (comment)

@samlikins
Copy link
Member

@Chemaclass:

The first thing I want to point out, is that since you added your user bin into the PATH, you didn't need to set PREFIX before the install.

Secondly, the command you ran to install BashUnit was for performing a local install; local to the current directory (which looks to be the user directory). The difference between a local and global install is which configuration is used; local uses the scripts and files properties, while global uses the install property.

The line you referenced (for global installs) would be what is executed when running bpkg install -g typeddevs/bashunit. The local install copies the files referenced in the scripts and files properties to a directory (ie: deps/bashunit) inside the current directory, then adds symbolic links to those files into the project bin directory (ie: deps/bin).

In your project, the primary script (ie: bashunit) references the files in the src directory explicitly, requiring them to always be located in a subdirectory in relation to the script. This is certainly a design decision that constrains the usage. Consider structuring them as if they are all accessible on the PATH. This will make the "helper" scripts easier to use and simplify your design.

Though BashUnit will likely be used as a development dependency, consider the users that decide to install it globally; all files will be installed in a directory which should be on the PATH; the names of your scripts could possibly conflict with other executables. There are two common ways to mitigate this issue; preface the "helper" scripts with bashunit, or leave the executable flag off on the "helper" scripts and source them (assuming they are installed in the same directory as BashUnit). The former is the most common design pattern.

I hope this helps you progress in this avenue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants