Thanks to visit codestin.com
Credit goes to code.bioconductor.org

Browse code

Drop dependency on BBS and Python

Hervé Pagès authored on 10/01/2022 22:27:06
Showing 1 changed files
... ...
@@ -1,3 +1,4 @@
1
+### NOT used at the moment.
1 2
 find_python <- function(python=NULL)
2 3
 {
3 4
     if (is.null(python)) {
... ...
@@ -10,26 +11,26 @@ find_python <- function(python=NULL)
10 11
             python <- Sys.which("python3")
11 12
         }
12 13
         if (python == "")
13
-             stop("\n  No Python executable can be found in PATH.\n  ",
14
+             stop("\n  No Python executable can be found in your PATH.\n  ",
14 15
                   wmsg("Please use the 'python' argument to specify ",
15 16
                        "the path to a valid Python executable."))
16 17
     } else {
18
+        EXPLAIN <- c("'python' must be the path (supplied as ",
19
+                     "a single string) to a Python executable.")
17 20
         if (!isSingleString(python))
18
-            stop(wmsg("'python' must be the path (supplied as a ",
19
-                      "single string) to a Python executable"))
21
+            stop(wmsg(EXPLAIN))
20 22
         if (!file.exists(python) || dir.exists(python))
21 23
             stop("\n  Invalid supplied path: \"", python, "\"\n  ",
22
-                 wmsg("'python' must be the path (supplied as a ",
23
-                      "single string) to a Python executable."))
24
+                 wmsg(EXPLAIN, "."))
24 25
     }
25 26
     python <- as.character(python)
26 27
     version <- try(system2(python, "--version", stdout=TRUE, stderr=TRUE),
27 28
                    silent=TRUE)
28 29
     if (inherits(version, "try-error") ||
29 30
         length(version) == 0L ||
30
-        !grepl("Python", version[[1L]], ignore.case=TRUE))
31
+        !grepl("^Python ", version[[1L]], ignore.case=TRUE))
31 32
     {
32
-        stop("Invalid Python executable: \"", python, "\"\n  ",
33
+        stop("\n  Invalid Python executable: \"", python, "\"\n  ",
33 34
              wmsg("Please use the 'python' argument to specify ",
34 35
                   "the path to a valid Python executable."))
35 36
     }
Browse code

Add utilities prepare_git_repo_for_work() and bump_version_and_commit()

Hervé Pagès authored on 22/11/2021 17:44:37
Showing 1 changed files
... ...
@@ -10,17 +10,17 @@ find_python <- function(python=NULL)
10 10
             python <- Sys.which("python3")
11 11
         }
12 12
         if (python == "")
13
-             stop("\n  No Python executable can be found in PATH.",
14
-                  "\n  Please use the 'python' argument to specify ",
15
-                  "the path to a valid\n  Python executable.")
13
+             stop("\n  No Python executable can be found in PATH.\n  ",
14
+                  wmsg("Please use the 'python' argument to specify ",
15
+                       "the path to a valid Python executable."))
16 16
     } else {
17
-        if (!is.character(python) || length(python) != 1L || is.na(python))
18
-            stop("'python' must be the path (supplied as a ",
19
-                 "single string) to a Python\n  executable")
17
+        if (!isSingleString(python))
18
+            stop(wmsg("'python' must be the path (supplied as a ",
19
+                      "single string) to a Python executable"))
20 20
         if (!file.exists(python) || dir.exists(python))
21
-            stop("\n  Invalid supplied path: \"", python, "\"",
22
-                 "\n  'python' must be the path (supplied as a ",
23
-                 "single string) to a Python\n  executable.")
21
+            stop("\n  Invalid supplied path: \"", python, "\"\n  ",
22
+                 wmsg("'python' must be the path (supplied as a ",
23
+                      "single string) to a Python executable."))
24 24
     }
25 25
     python <- as.character(python)
26 26
     version <- try(system2(python, "--version", stdout=TRUE, stderr=TRUE),
... ...
@@ -29,9 +29,9 @@ find_python <- function(python=NULL)
29 29
         length(version) == 0L ||
30 30
         !grepl("Python", version[[1L]], ignore.case=TRUE))
31 31
     {
32
-        stop("Invalid Python executable: \"", python, "\"",
33
-             "\n  Please use the 'python' argument to specify ",
34
-             "the path to a valid\n  Python executable.")
32
+        stop("Invalid Python executable: \"", python, "\"\n  ",
33
+             wmsg("Please use the 'python' argument to specify ",
34
+                  "the path to a valid Python executable."))
35 35
     }
36 36
     if (!grepl("Python 3\\.", version[[1L]], ignore.case=TRUE))
37 37
         stop("'", python, "' is ", version, " but Python 3 is required")
Browse code

Add updateBiocPackageRepoObjects()

Hervé Pagès authored on 20/11/2021 23:16:15
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,40 @@
1
+find_python <- function(python=NULL)
2
+{
3
+    if (is.null(python)) {
4
+        if (.Platform$OS.type == "windows") {
5
+            ## TODO: Maybe use reticulate::py_versions_windows() (which is
6
+            ## used by reticulate::py_discover_config()) to discover Python
7
+            ## installations on a Windows system. See '?py_versions_windows'.
8
+            python <- Sys.which("python")
9
+        } else {
10
+            python <- Sys.which("python3")
11
+        }
12
+        if (python == "")
13
+             stop("\n  No Python executable can be found in PATH.",
14
+                  "\n  Please use the 'python' argument to specify ",
15
+                  "the path to a valid\n  Python executable.")
16
+    } else {
17
+        if (!is.character(python) || length(python) != 1L || is.na(python))
18
+            stop("'python' must be the path (supplied as a ",
19
+                 "single string) to a Python\n  executable")
20
+        if (!file.exists(python) || dir.exists(python))
21
+            stop("\n  Invalid supplied path: \"", python, "\"",
22
+                 "\n  'python' must be the path (supplied as a ",
23
+                 "single string) to a Python\n  executable.")
24
+    }
25
+    python <- as.character(python)
26
+    version <- try(system2(python, "--version", stdout=TRUE, stderr=TRUE),
27
+                   silent=TRUE)
28
+    if (inherits(version, "try-error") ||
29
+        length(version) == 0L ||
30
+        !grepl("Python", version[[1L]], ignore.case=TRUE))
31
+    {
32
+        stop("Invalid Python executable: \"", python, "\"",
33
+             "\n  Please use the 'python' argument to specify ",
34
+             "the path to a valid\n  Python executable.")
35
+    }
36
+    if (!grepl("Python 3\\.", version[[1L]], ignore.case=TRUE))
37
+        stop("'", python, "' is ", version, " but Python 3 is required")
38
+    python
39
+}
40
+