datasnakes / renv

Creating virtual environments for R.
MIT License
17 stars 0 forks source link

Make alternate replace_variables() method. #5

Closed grabear closed 5 years ago

grabear commented 6 years ago

This script uses the context variable, which contains all of the paths (#3), along with text copied from a scripting file in order to use the script with context specific paths. Below is the python version of this method:

def replace_variables(self, text, context):
        """
        Replace variable placeholders in script text with context-specific
        variables.
        Return the text passed in , but with variables replaced.
        :param text: The text in which to replace placeholder variables.
        :param context: The information for the environment creation request
                        being processed.
        """
        text = text.replace('__VENV_DIR__', context.env_dir)
        text = text.replace('__VENV_NAME__', context.env_name)
        text = text.replace('__VENV_PROMPT__', context.prompt)
        text = text.replace('__VENV_BIN_NAME__', context.bin_name)
        text = text.replace('__VENV_PYTHON__', context.env_exe)
        return text
grabear commented 6 years ago

This function now takes all of these variables:

        text = text.replace('__VENV_DIR__', context.env_dir)
        text = text.replace('__VENV_NAME__', context.env_name)
        text = text.replace('__VENV_PROMPT__', context.prompt)
        text = text.replace('__VENV_BIN_NAME__', context.bin_name)
        # NEW:
        text = text.replace('__VENV_R__', context.env_R_exe)
        text = text.replace('__VENV_RSCRIPT__', context.env_R_script)
        text = text.replace('__R_LIBS_USER__', context.config_dict["R_LIBS_USER"])
        text = text.replace('__R_VERSION__', context.config_dict["R_VERSION"])
        text = text.replace('__R_HOME__', context.config_dict["R_ENV_HOME"])
        text = text.replace('__R_INCLUDE_DIR__', context.config_dict["R_INCLUDE_DIR"])
        text = text.replace('__CRAN_MIRROR__', context.config_dict["CRAN_MIRROR"])
        text = text.replace('__CRANEXTRA_MIRROR__', context.config_dict["CRANEXTRA_MIRROR"])
        text = text.replace('__STANDARD_PKG_LIST__', context.config_dict["STANDARD_PKG_LIST"])
        text = text.replace('__REPRODUCIBLE_WORKFLOW_PKG_LIST__', context.config_dict["REPRODUCIBLE_WORKFLOW_PKG_LIST"])

Some default values:

__DEFAULT_CONFIG__ = {
    "CRAN_MIRROR": "https://cran.rstudio.com/",
    "CRANEXTRA_MIRROR": "https://mirrors.nics.utk.edu/cran/",
    "STANDARD_PKG_LIST": {
        "BiocInstaller": "Bioconductor",
        "devtools": "Devtools"
    },
    "REPRODUCIBLE_WORKFLOW_PKG_LIST": {
        "tidyverse": "Tidyverse"
    }
}

Things to do:

grabear commented 5 years ago

Merged functionality into the install_scripts() function. https://github.com/datasnakes/renv/commit/d290cc90640d9b905c280c4446e6e1eb07e78959#diff-6b6632261b69ed122b7f2865e4570f5cL354