anishathalye / dotbot

A tool that bootstraps your dotfiles ⚡️
MIT License
6.96k stars 288 forks source link

Multiple plugins #251

Open ChrisTsou opened 3 years ago

ChrisTsou commented 3 years ago

Hey, i'm pretty new to everything and i cant figure out how to add multiple plugins. i have the plugins in a folder called "dotbot-plugins" and every plugin is in its own folder ex. dotbot-plugins/sudo, dotbot-plugins/git/ every folder is a submodule. i cant figure out what i should add to the install file to load all plugins.

ChrisTsou commented 3 years ago

i figured it out, i did it with multiple -p flags. also i think --plugin-dir ".../dotbot-plugins/*" may also work but the sudo plugin makes it hang for some reason. i leave this open so someone can tell me the proper way i should do this.

etkeys commented 3 years ago

I've been meaning to try this setup. I attempted it once but didn't commit the folder structure correctly so I opted to just use -p while I transition over to dotbot. Once I finished the bulk of the transition, I'm going attempt to get --plugin-dir to work again. Having said that, I might try to set it up sooner as a test to see if I hit the same problem you did.

dotbot-sudo is an interesting plugin because it contains an extra python file, execute_plugin.py, which sudo.py invokes as a sub-process. When given --plugin-dir, dotbot will load any *.py files in finds along the provided path. I'll make an assumption about your plugin directory and guess that globbling resolution returns these items...

.../dotbot-plugins/git/git.py
.../dotbot-plugins/sudo/execute_plugin.py
.../dotbot-plugins/sudo/sudo.py

execute_plugin.py is not intended to be used by dotbot, let alone loaded as a plugin. Given that, I'd say the problem you're running into might be related to two different processes attempting to load the same resource and the python runtime is being blocked. If this is the case the alternative would be to specifiy the path to each plugin .py file (like how dotbot-sudo's author, DrDynamic, does, or move dotbot-sudo to a different directory so globbling resolution doesn't pick up dotbot-sudo.

ChrisTsou commented 3 years ago

the case about --plugin-dir and sudo plugin seems to be exactly as you describe it since i tried it on its own without any other folder structure or plugins and the same happens, dotbot seems to enter an infinite loop. I set it up as you said and DrDynamic has his install, multiple -p flags. Maybe warn about --plugin-dir in docs or ask plugin authors to conform to 1 .py file plugins or change how --plugin-dir works or remove it alltogether.

etkeys commented 3 years ago

There is an open issue for dotbot-sudo that centers around how execute_plugin.py works and possible oversights (based on my understanding). I've said there that I'd like to dig into that specific problem and I have a couple ideas for what to try.

Based on what I find (hopefully success), I'll report back here with documentation notes that plugin creators should be aware of.

anishathalye commented 3 years ago

Yeah, I'm not sure how to improve the interaction between --plugin-dir and plugins that have multiple files.

It does seem a bit annoying to have to specify all the -p ... arguments (I recommend putting them in the install file, so you don't have to type them out every time).

Would it be better if the plugins could be specified in the install.conf.yaml instead? Like this:

- plugins:
    - dotbot-plugins/sudo
    - dotbot-plugins/git

(I feel like I saw an issue or PR or comment suggesting this, but I can't seem to find it at the moment)

ChrisTsou commented 3 years ago

Definitely better like that. Maybe a conf that runs before anything else? for plugins and default overrides

anishathalye commented 3 years ago

The config is ordered, so it's good enough if the plugins and defaults come first in the file.

etkeys commented 3 years ago

I like the idea of having a plugins directive for the conf files. I had the same thought. It would be helpful for use cases where you have multiple conf files already and you wouldn't need differently install files if you are selective about what plugins are loaded based on the conf file you're going to use.

etkeys commented 3 years ago

@ChrisTsou, I've submitted this PR for dotbot-sudo that reworks how tasks under sudo directive are processed. If you're still inclined to use --plugin-dir and are able, care to give the changes a go?

As far as interaction with --plugin-dir and plugins that have multiple files, I've seen some plugins that put files for their own use in sub directories. Doing this should be sufficient enough to exclude files from being picked up by glob that are not intended to be used by dotbot.

ChrisTsou commented 3 years ago

@etkeys As i said i'm new to everything, so in the process of playing around with linux and different programs i moved from dotbot. but i will download it and your changes in sudo plugin and see again one of these days. As for the second part i noticed that too. i know rust plugin calls other .py files which are in folders and i didnt have any problems with that plugin.

0inp commented 1 year ago

Hi !

Sorry to reopen this issue more than 2 years later, but I can't make dotbot work with multiple (two) plugins. here are my differents files: .gitmodules

[submodule "dotbot"]
        path = dotbot
        url = https://github.com/anishathalye/dotbot
[submodule "dotbot-brew"]
        path = dotbot-plugins/dotbot-brew
        url = https://github.com/d12frosted/dotbot-brew.git
[submodule "dotbot-git"]
        path = dotbot-plugins/dotbot-git
        url = https://github.com/DrDynamic/dotbot-git.git

my file tree of my dotfiles directory

stephanepoint at …/dotfiles via  master (  ) ls -la
total 120
drwxr-xr-x  12 stephanepoint  staff    384 Jan 12 09:21 .
drwxr-xr-x+ 77 stephanepoint  staff   2464 Jan 12 09:21 ..
drwxr-xr-x  17 stephanepoint  staff    544 Jan 12 01:54 .git
-rw-r--r--   1 stephanepoint  staff    602 Mar 10  2021 .gitignore
-rw-r--r--   1 stephanepoint  staff    306 Jan 12 01:22 .gitmodules
-rw-r--r--   1 stephanepoint  staff   1277 Mar 10  2021 README.md
drwxr-xr-x  20 stephanepoint  staff    640 Jan 11 23:01 dotbot
drwxr-xr-x   4 stephanepoint  staff    128 Jan 12 01:20 dotbot-plugins
-rwxr-xr-x   1 stephanepoint  staff    564 Jan 12 01:44 install
-rw-r--r--   1 stephanepoint  staff   1418 Jan 12 01:49 install.conf.yaml
drwxr-xr-x  11 stephanepoint  staff    352 Jan 11 22:52 symlinks
-rw-r--r--   1 stephanepoint  staff  39353 Aug 25 18:05 vim_keys.txt

concerning dotbot here is my install script


set -e

CONFIG="install.conf.yaml"
DOTBOT_DIR="dotbot"

DOTBOT_BIN="bin/dotbot"
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

cd "${BASEDIR}"
git -C "${DOTBOT_DIR}" submodule sync --quiet --recursive
git submodule update --init --recursive "${DOTBOT_DIR}"

"${BASEDIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASEDIR}" --plugin-dir "./dotbot-plugins/" -c "${CONFIG}" "${@}"
# "${BASEDIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASEDIR}" -p "./dotbot-plugins/dotbot-git/git.py" -p "./dotbot-plugins/dotbot-brew/brew.py" -c "${CONFIG}" "${@}"

and here is my install.conf.yaml

- defaults:
    link:
      relink: true

- clean: ['~']

- link:
    # ~/.bashrc: bashrc
    ~/.config: symlinks/config
    ~/.gitconfig: symlinks/gitconfig
    ~/.gitignore: symlinks/gitignore
    ~/.warprc: symlinks/warprc
    ~/.zshrc: symlinks/zshrc

- shell:
  - [python3.10 -m pip install --upgrade pip, Upgrade Pip]
  -
    command: brew cleanup && brew upgrade
    description: Upgrade brew
    stdout: true
    stdin: true
    stderr: true

  - [git submodule update --init --recursive, Install submodules]
  - [PREFIX='/usr/local/opt/browserpass' make hosts-chrome-user -f /usr/local/opt/browserpass/lib/browserpass/Makefile, Configure Browserpass]
  - [pip install --user tmuxp, Install tmux session manager]
  -
    command: sudo chsh -s $(which zsh) ${USER}
    description: Switch to ZSH
    stdout: true
    stdin: true
    stderr: true

- git:
  '~/.pyenv/plugins/pyenv-virtualenv':
    url: 'https://github.com/pyenv/pyenv-virtualenv.git'
    description: 'pyenv-virtualenv'
  '~/.tmux/plugins/tpm':
    url: 'https://github.com/tmux-plugins/tpm.git'
    description: 'tmux plugins manager'
  '~/diff-so-fancy/':
    url: 'https://github.com/so-fancy/diff-so-fancy.git'
    description: 'diff-so-fancy'

- brew:
  - browserpass
  - coreutils
  - fzf
  - gitlint
  - neovim
  - pgcli
  - pyenv
  - ripgrep
  - starship
  - tmux
  - zsh
- tap:
  - homebrew/cask-fonts
- cask:
  - font-hack-nerd-font

The outpus are not the same according to the options I choose to run dotbot. With the --plugin-dir "./dotbot-plugins/" option, only the brew/task/cask actions are understood:

Action git not handled
Action ~/.pyenv/plugins/pyenv-virtualenv not handled
Action ~/.tmux/plugins/tpm not handled
Action ~/diff-so-fancy/ not handled
Action brew not handled
Action tap not handled
Action cask not handled

==> Some tasks were not executed successfully

With the options -p "./dotbot-plugins/dotbot-git/git.py" -p "./dotbot-plugins/dotbot-brew/brew.py", neither of my plugins are used:

An error was encountered while executing action git
Action git not handled
Action ~/.pyenv/plugins/pyenv-virtualenv not handled
Action ~/.tmux/plugins/tpm not handled
Action ~/diff-so-fancy/ not handled
All packages have been installed
Tapping homebrew/cask-fonts
Installing font-hack-nerd-font
Warning: Cask 'font-hack-nerd-font' is already installed.

To re-install font-hack-nerd-font, run:
  brew reinstall --cask font-hack-nerd-font
All packages have been installed

==> Some tasks were not executed successfully

Can you help me, please, to find what is wrong with how I set up my plugins ?

0inp commented 1 year ago

Hey ! I found my problem. This was the fact that the plugin git ask for a dictionnary and not an array your conf should look like

  git:
  '~/.pyenv/plugins/pyenv-virtualenv':
    url: 'https://github.com/pyenv/pyenv-virtualenv.git'
    description: 'pyenv-virtualenv'
  '~/.tmux/plugins/tpm':
    url: 'https://github.com/tmux-plugins/tpm.git'
    description: 'tmux plugins manager'
  '~/diff-so-fancy/':
    url: 'https://github.com/so-fancy/diff-so-fancy.git'
    description: 'diff-so-fancy'

Note the removed dash before the action git.

Either way thank you for dotbot !

erikw commented 1 year ago

For me it seems to work to modify the install script in my dotfiles folder like this

DOTBOT_PLUGIN_DIR=".local/repos/dotbot-plugins"

[...]

"${BASEDIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASEDIR}" --plugin-dir "${DOTBOT_PLUGIN_DIR}/*" -c "${CONFIG}" "${@}"
simon-bueler commented 2 months ago

@anishathalye Would be nice to merge the PR #294 since it would fix this issue, or is there a problem with the PR?

anishathalye commented 2 months ago

No just haven't had time, been too busy with work and other things