-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Package info #6
Changes from all commits
d3c9ced
f50be58
c43ca87
bc3e60e
d7297c3
7a25821
ac5a6f3
b58e156
85e46ec
8c4d51c
b6d28fe
c1a40a7
506af48
2df69db
6e86e29
6281f19
bf63e19
0239085
0317d14
0cad051
738aeb6
05753b8
24bbd96
9788431
1a5233b
4096ad8
408825e
21b1b4f
e932448
cd0fcb0
09d54c8
bfb3f7a
5079cc8
ef590c6
8825b76
41f40b5
930a8ad
2249851
80f1c23
17d3782
df2f296
286e770
941044a
5cab781
eafbc85
4a8f591
daf3526
9aee81e
631b926
21d7660
8367fb0
f48d550
aee5cc1
72da85f
5b5cb77
23a1c34
447532b
fe0f9d2
39d9716
cd67cc1
01f82b9
567a88d
2bd9954
ca3a8eb
73f1773
d9f2430
41bbce0
181edbd
52470c2
d0228c2
092c957
26afb9c
9a7847e
c1d1f72
ebc6517
f2c816f
86b0db7
cc7f45d
c558112
ed66d62
9addb26
eb69f3a
f6a54f2
cb5a36f
f54db91
f54e709
a9b856a
69ac9bb
876b4fb
d94cc6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Get Environment information for manifest | ||
#' | ||
#' This function takes no arguments and returns a nested list, suitable for | ||
#' inclusion in manifest export. | ||
#' | ||
#' @return nested list of file details, length the same as the input vector. | ||
get_manifest_envirionment_info <- function() { | ||
#: Envvars | ||
return(invisible(NULL)) | ||
} | ||
|
||
#' Get session information for manifest | ||
#' | ||
#' This function takes no arguments and returns a list, suitable for | ||
#' inclusion in manifest export. | ||
#' | ||
#' @return list of session details, including R Version, platform, OS | ||
#' (`running`), locale, timezone, and library paths. | ||
get_r_session_info <- function() { | ||
return( | ||
list( | ||
R.version = utils::sessionInfo()[["R.version"]], | ||
platform = utils::sessionInfo()[["platform"]], | ||
running = utils::sessionInfo()[["running"]], | ||
locale = utils::sessionInfo()[["locale"]], | ||
tzone = utils::sessionInfo()[["tzone"]], | ||
libPaths = .libPaths() # nolint: undesirable_function_linter | ||
) | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#' Get package information for active packages | ||
#' | ||
#' This function takes a vector or (possibly nested) list of package names and | ||
#' returns a nested list of package details, suitable for inclusion in manifest | ||
#' export. | ||
#' | ||
#' @param packagelist vector or list of package names. Best left as default, | ||
#' which includes the currently loaded and attached namespaces separated into | ||
#' useful categories. | ||
#' | ||
#' @return nested list of file details, length 3, with top level keys being | ||
#' `base`, `attached`, and `loaded`. Underneath those keys are lists of package | ||
#' details, with the package names as keys, and further details as returned by | ||
#' [get_individual_package_info()]. | ||
#' @seealso [get_individual_package_info()] | ||
get_package_info <- function( | ||
packagelist = list( | ||
base = utils::sessionInfo()[["basePkgs"]], | ||
attached = names(utils::sessionInfo()[["otherPkgs"]]), | ||
loaded = names(utils::sessionInfo()[["loadedOnly"]]) | ||
) | ||
) { | ||
log_debug("Getting package info.") | ||
if (inherits(packagelist, "character")) { | ||
out <- vapply( | ||
X = packagelist, | ||
FUN = function(x) { | ||
list(x = get_individual_package_info(x)) | ||
}, | ||
FUN.VALUE = list(1L), | ||
USE.NAMES = TRUE | ||
) | ||
} else { | ||
out <- vapply( | ||
X = packagelist, | ||
FUN = function(x) { | ||
list( | ||
x = get_package_info(x) | ||
) | ||
}, | ||
FUN.VALUE = list(1L), | ||
USE.NAMES = TRUE | ||
) | ||
} | ||
return(out) | ||
} | ||
|
||
#' Get package information for a package | ||
#' | ||
#' This function takes a single package name and returns a list of package | ||
#' details, suitable for inclusion in manifest export. | ||
#' | ||
#' @param packagename Singular charater string of package name | ||
#' | ||
#' @return nested list of file details, length 11, with keys: | ||
#' - `package`: The name of the package | ||
#' - `version`: The version of the package | ||
#' - `loaded_with_pkgload`: Is this package loaded with `pkgload`? (logical). | ||
#' Useful for identifying local development versions | ||
#' - `library`: The path of the library the package is installed in | ||
#' - `library_index`: The index of the library in the `.libPaths()` vector | ||
#' - `repository`: The repository the package was pulled from | ||
#' - `platform`: The platform the package was built for | ||
#' - `built`: Information about package build (relevant for binary packages) | ||
#' - `remotetype`: The type of remote repository the package was pulled from | ||
#' - `remotepkgref`: The reference used by `pak` to install the package | ||
#' - `remoteref`: The reference of the package when it was pulled from REPO | ||
#' - `remotesha`: the SHA-1 hash of the reference (if applicable) | ||
get_individual_package_info <- function(packagename) { | ||
if (length(packagename) != 1L || !is.character(packagename)) { | ||
log_error("packagename must be a single string.") | ||
# Early return | ||
stop("packagename must be a single string.") | ||
} | ||
dev_package <- pkgload::is_dev_package(packagename) | ||
if (dev_package) { | ||
log_warn("Package \"{packagename}\" is a development package.") | ||
log_warn("Package information may not be accurate.") | ||
warning("Identifying development packages may not be accurate.") | ||
package_dev_dir <- pkgload::pkg_path( | ||
path = dirname(system.file("DESCRIPTION", package = packagename)) | ||
) | ||
pkg_details <- list( | ||
package = pkgload::pkg_name(package_dev_dir), | ||
version = paste("DEV", pkgload::pkg_version(package_dev_dir)), | ||
library = NA_character_, | ||
library_index = NA_integer_, | ||
repository = NA_character_, | ||
platform = NA_character_, | ||
built = NA_character_, | ||
remotetype = "pkgload", | ||
remotepkgref = normalizePath(package_dev_dir), | ||
remoteref = NA_character_, | ||
remotesha = NA_character_ | ||
) | ||
} else { | ||
if (packagename %in% utils::installed.packages()[, "Package"]) { | ||
installed_index <- which( | ||
utils::installed.packages()[, "Package"] == packagename | ||
) | ||
installed_path <- utils::installed.packages()[installed_index, "LibPath"] | ||
if (length(installed_path) > 1L) { | ||
log_warn( | ||
"Multiple installations of package \"{packagename}\" found: ", | ||
"{installed_path}" | ||
) | ||
log_warn("Using installation first on the search path.") | ||
warning("Multiple installations of package found.") | ||
} | ||
lib_index <- min(which(.libPaths() == installed_path)) #nolint: undesirable_function_linter | ||
lib <- .libPaths()[lib_index] #nolint: undesirable_function_linter | ||
log_trace("Package \"{packagename}\" is installed at {lib}") | ||
} else { | ||
log_error("Package \"{packagename}\" is not installed.") | ||
stop("Package is not installed.") | ||
} | ||
log_trace("Getting package info for {packagename}.") | ||
pkg_details <- as.list( | ||
pkgdepends::lib_status( | ||
library = lib, | ||
packages = packagename | ||
) | ||
) | ||
pkg_details[["library_index"]] <- lib_index | ||
} | ||
details_list <- list( | ||
package = pkg_details[["package"]], | ||
version = pkg_details[["version"]], | ||
loaded_with_pkgload = dev_package, | ||
library = pkg_details[["library"]], | ||
library_index = pkg_details[["library_index"]], | ||
repository = pkg_details[["repository"]], | ||
platform = pkg_details[["platform"]], | ||
built = pkg_details[["built"]], | ||
remotetype = pkg_details[["remotetype"]], | ||
remotepkgref = pkg_details[["remotepkgref"]], | ||
remoteref = pkg_details[["remoteref"]], | ||
remotesha = pkg_details[["remotesha"]] | ||
) | ||
clean_details_list <- lapply( | ||
X = details_list, | ||
FUN = function(x) { | ||
ifelse(is.null(x), NA_character_, x) | ||
} | ||
) | ||
return(clean_details_list) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## save current settings so that we can reset later | ||
threshold <- logger::log_threshold() | ||
appender <- logger::log_appender() | ||
layout <- logger::log_layout() | ||
on.exit({ | ||
## reset logger settings | ||
logger::log_threshold(threshold) | ||
logger::log_layout(layout) | ||
logger::log_appender(appender) | ||
}) | ||
|
||
logger::log_appender(logger::appender_stdout) | ||
logger::log_threshold(logger::FATAL) | ||
logger::log_layout(logger::layout_simple) | ||
AlexAxthelm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
test_that("get_single_file_metadata processes CSV tables correctly", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like this test name/message is out of sync with reality |
||
expect_identical( | ||
get_r_session_info(), | ||
list( | ||
R.version = utils::sessionInfo()[["R.version"]], | ||
platform = utils::sessionInfo()[["platform"]], | ||
running = utils::sessionInfo()[["running"]], | ||
locale = utils::sessionInfo()[["locale"]], | ||
tzone = utils::sessionInfo()[["tzone"]], | ||
libPaths = .libPaths() # nolint: undesirable_function_linter | ||
) | ||
) | ||
}) | ||
|
||
testthat::expect_null( | ||
get_manifest_envirionment_info() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL