Skip to content
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

Move develop_polars.R away from inst #627

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
124 changes: 43 additions & 81 deletions inst/misc/develop_polars.R → dev/develop_polars.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#' load polars with environment variables and packages
#' run rextendr::document() in a session and set envars and packages temporarily
#'
#' @param ALL_FEATURES bool, to compile with e.g. simd, only for nightly toolchain
#' @param NOT_CRAN bool, do not delete compiled target objects. Next compilation much faster.
#' @param RPOLARS_CARGO_CLEAN_DEPS bool, do clean up cargo cache. Slows down next compilation
#' @param NOT_CRAN string if "true", Do not delete compiled target objects. Speeds up next
#' compilation.
#' @param RPOLARS_CARGO_CLEAN_DEPS string if "true" clean up cargo cache. Slows down next
#' compilation.
#' @param RPOLARS_FULL_FEATURES string if "true" will compile with polars with more rust-polars
#' side feature flags enabled
#' @param RPOLARS_PROFILE string "release" (this is the preferred for development). For shipping
#' polars via release channels use "release-optimized" is which enables full link time optimization.
#' This will increase compilation time significantly, but make the final binary smaller and faster.
#'
#' @param .packages char vec naming packages to load. If packages were not already loaded, they will
#' be and then unloaded afterwards
#' @param ... other environment args to add
#'
#' @details in general Makevars check if bool-like envvars are not 'true'.
#'
#' @return no return
Expand Down Expand Up @@ -33,11 +44,19 @@ load_polars = function(

#' load polars with environment variables and packages
#'
#' @param ALL_FEATURES bool, to compile with e.g. simd, only for nightly toolchain
#' @param NOT_CRAN bool, do not delete compiled target objects. Next compilation much faster.
#' @param RPOLARS_CARGO_CLEAN_DEPS bool, do clean up cargo cache. Slows down next compilation
#' @param NOT_CRAN string if "true", Do not delete compiled target objects. Speeds up next
#' compilation.
#' @param RPOLARS_CARGO_CLEAN_DEPS string if "true" clean up cargo cache. Slows down next
#' compilation.
#' @param RPOLARS_FULL_FEATURES string if "true" will compile with polars with more rust-polars
#' side feature flags enabled
#' @param RPOLARS_PROFILE string "release" (this is the preferred for development). For shipping
#' polars via release channels use "release-optimized" is which enables full link time optimization.
#' This will increase compilation time significantly, but make the final binary smaller and faster.
#'
#' @param .packages char vec naming packages to load. If packages were not already loaded, they will
#' be and then unloaded afterwards
#' @param ... other environment args to add
#' @details in general Makevars check if bool-like envvars are not 'true'.
#'
#' @return no return
#'
Expand Down Expand Up @@ -67,10 +86,21 @@ build_polars = function(
#'
#' @param RPOLARS_RUST_SOURCE where check can find precomiled target, set to '' if not use,
#' DEFAULT is `paste0(getwd(),"/src/rust")`.
#' @param ALL_FEATURES bool, to compile with e.g. simd, only for nightly toolchain
#' @param NOT_CRAN bool, do not delete compiled target objects. Next compilation much faster.
#' @param RPOLARS_CARGO_CLEAN_DEPS bool, do clean up cargo cache. Slows down next compilation
#' @param NOT_CRAN string if "true", Do not delete compiled target objects. Speeds up next
#' compilation.
#' @param RPOLARS_CARGO_CLEAN_DEPS string if "true" clean up cargo cache. Slows down next
#' compilation.
#' @param RPOLARS_FULL_FEATURES string if "true" will compile with polars with more rust-polars
#' side feature flags enabled
#' @param RPOLARS_PROFILE string "release" (this is the preferred for development). For shipping
#' polars via release channels use "release-optimized" is which enables full link time optimization.
#' This will increase compilation time significantly, but make the final binary smaller and faster.
#' @param FILTER_CHECK_NO_FILTER # disable filtering of well known warnings and errors, see
#' ./inst/misc/filter_rcmdcheck.R
#' @param check_dir
#' @param .packages
#' @param ... other environment args to add
#'
#' @details in general Makevars check if bool-like envvars are not 'true'.
#'
#' @return no return
Expand Down Expand Up @@ -120,75 +150,6 @@ check_polars = function(
print("check polars is done")
}

#' submit polars with environment variables, filter errors, symlink precompiled target
#'
#' @param RPOLARS_RUST_SOURCE where check can find precomiled target, set to '' if not use,
#' DEFAULT is `paste0(getwd(),"/src/rust")`.
#' @param ALL_FEATURES bool, to compile with e.g. simd, only for nightly toolchain
#' @param NOT_CRAN bool, do not delete compiled target objects. Next compilation much faster.
#' @param RPOLARS_CARGO_CLEAN_DEPS bool, do clean up cargo cache. Slows down next compilation
#' @param ... other environment args to add
#' @details in general Makevars check if bool-like envvars are not 'true'.
#'
#' @return no return
#'
#' @examples load_polars(ALL_FEATURES = "", SOME_OTHER_ENVVAR = "true")
submit_polars = function(
RPOLARS_RUST_SOURCE = paste0(getwd(), "/src/rust"),
RPOLARS_FULL_FEATURES = "false",
NOT_CRAN = "true",
RPOLARS_CARGO_CLEAN_DEPS = "false",
...,
temp_dir = tempdir(check = TRUE),
.packages = character(),
unlink_temp = TRUE) {
# bundle all envvars
envvars = c(
list(
RPOLARS_RUST_SOURCE = RPOLARS_RUST_SOURCE,
RPOLARS_FULL_FEATURES = RPOLARS_FULL_FEATURES,
NOT_CRAN = NOT_CRAN,
RPOLARS_CARGO_CLEAN_DEPS = RPOLARS_CARGO_CLEAN_DEPS
),
list(...)
)
not_cran = identical(NOT_CRAN, "true")
cat("in not_cran mode:", not_cran, "\n")
with_polars(
\() {
temp_dir = paste0(temp_dir, "/polars_submission")
unlink(temp_dir, recursive = TRUE, force = TRUE)
dir.create(temp_dir)
# copy repo except target folders
all_files = list.files(path = ".", full.names = TRUE, recursive = TRUE)
non_target_files = setdiff(all_files, grep("^\\./src/rust/target", all_files, value = TRUE))
non_target_dirs = gregexpr("/", non_target_files) |>
lapply(tail, 1) |>
substr(x = non_target_files, start = 1) |>
unique() |>
(\(x){
x[order(nchar(x))][-1]
})()
for (i in paste0(temp_dir, "/", non_target_dirs)) dir.create(i)
res = file.copy(non_target_files, paste0(temp_dir, "/", non_target_files))
if (!all(res)) warning("copy incomplete")

oldwd = getwd()
setwd(temp_dir)
on.exit({
setwd(oldwd)
if (unlink_temp) unlink(temp_dir, recursive = TRUE)
})
devtools::submit_cran()
},
RPOLARS_FULL_FEATURES = RPOLARS_FULL_FEATURES,
NOT_CRAN = NOT_CRAN,
RPOLARS_CARGO_CLEAN_DEPS = RPOLARS_CARGO_CLEAN_DEPS,
RPOLARS_RUST_SOURCE = RPOLARS_RUST_SOURCE,
...
)
}

with_polars = function(
f,
...,
Expand Down Expand Up @@ -238,6 +199,7 @@ with_polars = function(


#' find compiled *.Rd files for missing return value
#' This can be used if ever submitting to cran again.
#'
#' @return char vec
#'
Expand Down Expand Up @@ -272,10 +234,10 @@ find_missing_return = function() {


#' run_all_examples collect error
#' @details reloading polars can be slow. For faster development running all
#'

#' pass return $oks to skip_these to not rerun oks again
#' @param skip_these names of doc files to skip, use for for not running non failed again
#' @param time_examples bool, time examples
#' @return list of errors: list of all captured errors + print, oks names of files with no errors
#'
#' @export
Expand Down
32 changes: 32 additions & 0 deletions dev/readme.md
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the file to README.md

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason these contents are here instead of DEVELOPMENT.md?

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Developer Scripts

This repository houses opinionated scripts to simplify the development process. For CI workflows,
it is recommended to exclusively use the `./Makefile`.

## `source(styler_utils.R)`

The `styler_utils.R` script is derived from `styler` and has been optimized for parallel execution.
It utilizes `git diff`, `git status`, and identification of untracked files to determine which new
files require styling.

- `style_files()`: Automatically formats all modified files in parallel in a few seconds.
- `style_entire_pkg()`: Restyles any file in the repository. Primarily used for chore pull requests
to reset all files.

## `source(develop_polars.R)`

The `develop_polars.R` script provides opinionated presets for building polars during development,
addressing 95% of use cases. It is unnecessary to run this script in a new R session, as all
environment variables and loaded packages are reverted upon completion.

- `load_polars()`: Invokes `extendr::document()` with preset environment variables and loaded
packages.
- `build_polars()`: Initiates `R CMD install` with preset environment variables.
- `check_polars()`: Executes `devtools::check()` with preset environment variables and loaded
packages. Additionally, it reuses the Rust cache and target files, even when the `check` command
moves the working directory. The script deletes the temporary check directory afterward.
- `run_all_examples_collect_errors()`: Calls `pkgload::run_example()` and captures all errors.
Useful for running all examples at once without the need to manage restarts in case of errors.

Feel free to modify the formatting and details according to your preferences and the specific needs
of your project.