---
# @action Configures pyenv
# Ensures pyenv is in the `PATH`
# @action Configures pyenv
# Ensures `PYENV_ROOT` is defined
- name: Ensure Bash is configured
  become_user: "{{ user.username }}"
  lineinfile:
    create: true
    line: "{{ item }}"
    mode: 0600
    path: ~/.bashrc
    regexp: "^{{ item }}"
  loop:
    - export PYENV_ROOT="{{ pyenv_src_folder }}"
    - export PATH="$PYENV_ROOT/bin:$PATH"
    - eval "$(pyenv init --path)"

- name: Ensure Zsh is configured
  become_user: "{{ user.username }}"
  lineinfile:
    create: true
    line: "{{ item }}"
    mode: 0600
    path: ~/.zshrc
    regexp: "^{{ item }}"
  loop:
    - export PYENV_ROOT="{{ pyenv_src_folder }}"
    - export PATH="$PYENV_ROOT/bin:$PATH"
    - eval "$(pyenv init --path)"

# @action Installs pyenv
# Pre-installs Python versions specified with the `python_versions` variable
- name: Ensure python versions are installed # noqa 301 503
  command: "pyenv install {{ item }}"
  loop: "{{ python_versions }}"
  when: python_versions is defined
