8000 Localize CLI, Explicit namspace function calls by coatless · Pull Request #21 · coatless-mac/macrtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Localize CLI, Explicit namspace function calls #21

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

Merged
merged 4 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ OS_type: unix
SystemRequirements: macOS
Imports:
askpass,
stats,
sys,
tools,
utils,
Expand All @@ -32,25 +31,6 @@ Imports:
URL: https://mac.thecoatlessprofessor.com/macrtools/
Suggests:
rstudioapi,
mockery,
testthat (>= 3.0.0)
Collate:
'cli-custom.R'
'assertions.R'
'blocks.R'
'renviron.R'
'shell.R'
'utils.R'
'installers.R'
'gfortran.R'
'macos-versions.R'
'paths.R'
'recipes.R'
'system-checks.R'
'xcode-cli.R'
'toolchain.R'
'version-check.R'
'xcode-app-ide.R'
'xcode-select.R'
'xcodebuild.R'
'zzz.R'
Config/testthat/edition: 3
44 changes: 23 additions & 21 deletions R/assertions.R
9E81
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#' @include cli-custom.R


#' @title Assert a condition
#'
#' @description
Expand All @@ -14,18 +11,21 @@
#' @rdname assert
#' @export
assert <- function(condition, message = NULL, call = caller_env()) {
if (isFALSE(condition)) {
cli_error(message, call = call)
if (base::isFALSE(condition)) {
cli::cli_abort(c(
"{.pkg macrtools}: {message}"
), call = call)
}
}

#' @rdname assert
#' @export
assert_mac <- function(call = caller_env()) {
if (!is_macos()) {
cli_error(c(
"This function requires macOS.",
"The current operating system is {.val {tolower(Sys.info()[['sysname']])}}."
current_os <- base::tolower(base::Sys.info()[['sysname']])
cli::cli_abort(c(
"{.pkg macrtools}: This function requires macOS.",
"{.pkg macrtools}: The current operating system is {.val {current_os}}."
),
call = call,
advice = "macrtools only works on macOS systems with Intel or Apple Silicon processors.")
Expand All @@ -39,9 +39,9 @@ assert_macos_supported <- function(call = caller_env()) {

if (!is_macos_r_supported()) {
mac_version <- shell_mac_version()
cli_error(c(
"Your macOS version {.val {mac_version}} is not supported.",
"Supported versions: macOS High Sierra (10.13) through macOS Sequoia (15.x)."
cli::cli_abort(c(
"{.pkg macrtools}: Your macOS version {.val {mac_version}} is not supported.",
"{.pkg macrtools}: Supported versions: macOS High Sierra (10.13) through macOS Sequoia (15.x)."
),
call = call,
advice = "Please upgrade your macOS to a supported version or use an alternative method to install development tools.")
Expand All @@ -52,9 +52,10 @@ assert_macos_supported <- function(call = caller_env()) {
#' @export
assert_aarch64 <- function(call = caller_env()) {
if (!is_aarch64()) {
cli_error(c(
"This function requires an Apple Silicon (M-series) Mac.",
"Current architecture: {.val {system_arch()}}."
arch <- system_arch()
cli::cli_abort(c(
"{.pkg macrtools}: This function requires an Apple Silicon (M-series) Mac.",
"{.pkg macrtools}: Current architecture: {.val {arch}}."
),
call = call,
advice = "This feature is specifically designed for Apple Silicon processors (M1, M2, M3, etc.). Intel Macs require different components.")
Expand All @@ -65,9 +66,10 @@ assert_aarch64 <- function(call = caller_env()) {
#' @export
assert_x86_64 <- function(call = caller_env()) {
if (!is_x86_64()) {
cli_error(c(
"This function requires an Intel-based Mac.",
"Current architecture: {.val {system_arch()}}."
arch <- system_arch()
cli::cli_abort(c(
"{.pkg macrtools}: This function requires an Intel-based Mac.",
"{.pkg macrtools}: Current architecture: {.val {arch}}."
),
call = call,
advice = "This feature is specifically designed for Intel processors. Apple Silicon Macs require different components.")
Expand All @@ -79,10 +81,10 @@ assert_x86_64 <- function(call = caller_env()) {
assert_r_version_supported <- function(call = caller_env()) {
if (!(is_r_version("4.0") || is_r_version("4.1") || is_r_version("4.2") ||
is_r_version("4.3") || is_r_version("4.4"))) {
version_number <- paste(R.version$major, R.version$minor, sep = ".")
cli_error(c(
"The installed R version {.val {version_number}} is not supported.",
"Supported versions: R 4.0.x through R 4.4.x."
version_number <- base::paste(base::R.version$major, base::R.version$minor, sep = ".")
cli::cli_abort(c(
"{.pkg macrtools}: The installed R version {.val {version_number}} is not supported.",
"{.pkg macrtools}: Supported versions: R 4.0.x through R 4.4.x."
),
call = call,
advice = "Please upgrade or downgrade your R installation to a supported version.")
Expand Down
94 changes: 47 additions & 47 deletions R/blocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,59 @@
# Light modifications have occurred to remove use of `ui_*()`

platform_line_ending = function() {
if (.Platform$OS.type == "windows") "\r\n" else "\n"
if (base::.Platform$OS.type == "windows") "\r\n" else "\n"
}

read_utf8 = function(path, n = -1L) {
base::readLines(path, n = n, encoding = "UTF-8", warn = FALSE)
}

write_utf8 = function(path, lines, append = FALSE, line_ending = NULL) {
stopifnot(is.character(path))
stopifnot(is.character(lines))
base::stopifnot(base::is.character(path))
base::stopifnot(base::is.character(lines))

file_mode = if (append) "ab" else "wb"
con = file(path, open = file_mode, encoding = "utf-8")
con = base::file(path, open = file_mode, encoding = "utf-8")

if (is.null(line_ending)) {
if (base::is.null(line_ending)) {
line_ending = platform_line_ending()
}

# convert embedded newlines
lines = gsub("\r?\n", line_ending, lines)
lines = base::gsub("\r?\n", line_ending, lines)
base::writeLines(base::enc2utf8(lines), con, sep = line_ending, useBytes = TRUE)
close(con)
base::close(con)

invisible(TRUE)
base::invisible(TRUE)
}

seq2 = function (from, to)
{
if (length(from) != 1) {
stop(sprintf("%s must be length one.", from))
if (base::length(from) != 1) {
base::stop(base::sprintf("%s must be length one.", from))
}
if (length(to) != 1) {
stop(sprintf("%s must be length one.", to))
if (base::length(to) != 1) {
base::stop(base::sprintf("%s must be length one.", to))
}
if (from > to) {
integer(0)
base::integer(0)
}
else {
seq.int(from, to)
base::seq.int(from, to)
}
}


block_append = function(desc, value, path,
block_start = "# <<<",
block_end = "# >>>",
block_prefix = NULL,
block_suffix = NULL,< 10000 /span>
sort = FALSE) {
block_start = "# <<<",
block_end = "# >>>",
block_prefix = NULL,
block_suffix = NULL,
sort = FALSE) {

if (!is.null(path) && file.exists(path)) {
if (!base::is.null(path) && base::file.exists(path)) {
lines = read_utf8(path)
if (all(value %in% lines)) {
if (base::all(value %in% lines)) {
return(FALSE)
}

Expand All @@ -68,9 +68,9 @@ block_append = function(desc, value, path,
block_lines = NULL
}

message("Adding ", desc, " to ", path)
base::message("Adding ", desc, " to ", path)

if (is.null(block_lines)) {
if (base::is.null(block_lines)) {
# changed as we have a cold start and want to enforce a block being present
write_utf8(path, block_create(value, block_start, block_end), append = TRUE)
return(TRUE)
Expand All @@ -81,51 +81,51 @@ block_append = function(desc, value, path,
end = block_lines[[2]]
block = lines[seq2(start, end)]

new_lines = union(block, value)
new_lines = base::union(block, value)
if (sort) {
new_lines = sort(new_lines)
new_lines = base::sort(new_lines)
}

lines = c(
lines = base::c(
lines[seq2(1, start - 1L)],
new_lines,
lines[seq2(end + 1L, length(lines))]
lines[seq2(end + 1L, base::length(lines))]
)
write_utf8(path, lines)

TRUE
}

block_replace = function(desc, value, path,
block_start = "# <<<",
block_end = "# >>>") {
if (!is.null(path) && file.exists(path)) {
block_start = "# <<<",
block_end = "# >>>") {
if (!base::is.null(path) && base::file.exists(path)) {
lines = read_utf8(path)
block_lines = block_find(lines, block_start, block_end)
} else {
block_lines = NULL
}

if (is.null(block_lines)) {
message("Copy and paste the following lines into ", path, ":")
paste0(c(block_start, value, block_end), collapse = "\n")
return(invisible(FALSE))
if (base::is.null(block_lines)) {
base::message("Copy and paste the following lines into ", path, ":")
base::paste0(base::c(block_start, value, block_end), collapse = "\n")
return(base::invisible(FALSE))
}

start = block_lines[[1]]
end = block_lines[[2]]
block = lines[seq2(start, end)]

if (identical(value, block)) {
return(invisible(FALSE))
if (base::identical(value, block)) {
return(base::invisible(FALSE))
}

message("Replacing ", desc, " in ", path)
base::message("Replacing ", desc, " in ", path)

lines = c(
lines = base::c(
lines[seq2(1, start - 1L)],
value,
lines[seq2(end + 1L, length(lines))]
lines[seq2(end + 1L, base::length(lines))]
)
write_utf8(path, lines)
}
Expand All @@ -139,25 +139,25 @@ block_show = function(path, block_start = "# <<<", block_end = "# >>>") {

block_find = function(lines, block_start = "# <<<", block_end = "# >>>") {
# No file
if (is.null(lines)) {
if (base::is.null(lines)) {
return(NULL)
}

start = which(lines == block_start)
end = which(lines == block_end)
start = base::which(lines == block_start)
end = base::which(lines == block_end)

# No block
if (length(start) == 0 && length(end) == 0) {
if (base::length(start) == 0 && base::length(end) == 0) {
return(NULL)
}

if (!(length(start) == 1 && length(end) == 1 && start < end)) {
stop("Invalid block specification.")
if (!(base::length(start) == 1 && base::length(end) == 1 && start < end)) {
base::stop("Invalid block specification.")
}

c(start + 1L, end - 1L)
base::c(start + 1L, end - 1L)
}

block_create = function(lines = character(), block_start = "# <<<", block_end = "# >>>") {
c("\n", block_start, unique(lines), block_end)
base::c("\n", block_start, base::unique(lines), block_end)
}
Loading
Loading
0