File: pipenv.R

package info (click to toggle)
r-cran-reticulate 1.41.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,088 kB
  • sloc: cpp: 5,154; python: 620; sh: 13; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

pipenv_config <- function(required_module) {

  pipfile <- pipenv_pipfile_path()
  if (!file.exists(pipfile))
    return(NULL)

  python <- pipenv_python()
  python_config(python, required_module, forced = "Pipfile")

}

pipenv_pipfile_path <- function() {

  # check option
  pipfile <- getOption("reticulate.pipenv.pipfile")
  if (!is.null(pipfile))
    return(pipfile)

  # try default
  tryCatch(
    here::here("Pipfile"),
    error = function(e) ""
  )

}

pipenv_python <- function() {

  # validate that pipenv is available on the PATH
  if (!nzchar(Sys.which("pipenv")))
    stop("'pipenv' is not available")

  # move to root directory
  root <- here::here()
  owd <- setwd(root)
  on.exit(setwd(owd), add = TRUE)

  # ask pipenv what the environment path is
  envpath <- system("pipenv --venv", intern = TRUE)
  status <- attr(envpath, "status") %||% 0L
  if (status != 0L) {
    fmt <- "'pipenv --venv' had status %i"
    stopf(fmt, status)
  }

  # get path to python
  virtualenv_python(envpath)

}