datasnakes / renv

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

Make alternate create_configuration() method. #4

Closed grabear closed 5 years ago

grabear commented 6 years ago

This method creates a pyvenv.cfg file in the environment, which indicates where the environment's Python was copied from, and whether the system site-packages should be made available in the environment. Below is the python implementation:

def create_configuration(self, context):
        """
        Create a configuration file indicating where the environment's Python
        was copied from, and whether the system site-packages should be made
        available in the environment.
        :param context: The information for the environment creation request
                        being processed.
        """
        context.cfg_path = path = os.path.join(context.env_dir, 'pyvenv.cfg')
        with open(path, 'w', encoding='utf-8') as f:
            f.write('home = %s\n' % context.python_dir)
            if self.system_site_packages:
                incl = 'true'
            else:
                incl = 'false'
            f.write('include-system-site-packages = %s\n' % incl)
            f.write('version = %d.%d.%d\n' % sys.version_info[:3])
grabear commented 6 years ago

The create_configuration() function now uses a YAML file for configuring the environment. The ability for using a user generated file relies on the environment directory already existing with this file in it. Currently the following variables are used:

R_ABS_HOME: "/home/ums/r2294/test-R/installs/R-3.4.3/lib64/R"
R_ENV_HOME: "/home/ums/r2294/test-R/renvs/R-3.4.3"
R_LIBS_USER: "/home/ums/r2294/test-R/renvs/R-3.4.3/lib64/R/library"
R_INCLUDE_DIR: "/home/ums/r2294/test-R/renvs/R-3.4.3/lib64/R/include"
R_VERSION: "3.4.3"

# LIST OF DEFAULT variables for .Rprofile
CRAN_MIRROR: "https://cran.rstudio.com/"
CRANEXTRA_MIRROR: "https://mirrors.nics.utk.edu/cran/"

# Determine how to format this for .Rprofile
STANDARD_PKG_LIST:
  BiocInstaller: "Bioconductor"
  devtools: "Devtools"
  tidyverse: "Tidyverse"

REPRODUCIBLE_WORKFLOW_PKG_LIST:
  packrat: "Packrat"
  miniCRAN: "MiniCRAN"

In conjunction with:

            config_dict["R_LIBS_USER"] = context.env_R_libs
            config_dict["R_ENV_HOME"] = context.env_R_home
            config_dict["R_ABS_HOME"] = context.abs_R_home
            config_dict["R_INCLUDE_DIR"] = context.env_R_include
            config_dict["R_VERSION"] = context.R_version
            config_dict.update(__DEFAULT_CONFIG__)
            pkg_lists = self.format_pkg_list(config_dict)
            config_dict.update(pkg_lists)
            config_dict.update(user_config)
            yaml.dump(config_dict, f, default_flow_style=False)

When using system_site_packages = TRUE, config_dict["R_LIBS_USER"] will add the main R library as a secondary search path.

To do list: