Skip to content

Commit

Permalink
feat: R lang packages version, remove .Rprofile from rlang detection (#…
Browse files Browse the repository at this point in the history
…5588)

* do not detect R for .Rprofile files, closes #2817

* get R package version, #5586

* update schema

* fix and simplify regex for rlang package version

* attempt to fix regex

* proper detect R packages, closes #5590

* reduce diff vs master branch
  • Loading branch information
jangorecki committed Nov 29, 2023
1 parent bc3eb03 commit 5267c46
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/config-schema.json
Expand Up @@ -1397,7 +1397,7 @@
"Rsx"
],
"detect_files": [
".Rprofile"
"DESCRIPTION"
],
"detect_folders": [
".Rproj.user"
Expand Down Expand Up @@ -5100,7 +5100,7 @@
},
"detect_files": {
"default": [
".Rprofile"
"DESCRIPTION"
],
"type": "array",
"items": {
Expand Down
2 changes: 1 addition & 1 deletion src/configs/rlang.rs
Expand Up @@ -27,7 +27,7 @@ impl<'a> Default for RLangConfig<'a> {
symbol: "📐 ",
disabled: false,
detect_extensions: vec!["R", "Rd", "Rmd", "Rproj", "Rsx"],
detect_files: vec![".Rprofile"],
detect_files: vec!["DESCRIPTION"],
detect_folders: vec![".Rproj.user"],
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/modules/package.rs
Expand Up @@ -310,6 +310,13 @@ fn get_dart_pub_version(context: &Context, config: &PackageConfig) -> Option<Str
format_version(raw_version, config.version_format)
}

fn get_rlang_version(context: &Context, config: &PackageConfig) -> Option<String> {
let file_contents = context.read_file_from_pwd("DESCRIPTION")?;
let re = Regex::new(r"(?m)^Version:\s*(?P<version>.*$)").unwrap();
let caps = re.captures(&file_contents)?;
format_version(&caps["version"], config.version_format)
}

fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
let package_version_fn: Vec<fn(&Context, &PackageConfig) -> Option<String>> = vec![
get_cargo_version,
Expand All @@ -330,6 +337,7 @@ fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
get_sbt_version,
get_daml_project_version,
get_dart_pub_version,
get_rlang_version,
];

package_version_fn.iter().find_map(|f| f(context, config))
Expand Down Expand Up @@ -1402,6 +1410,19 @@ environment:
project_dir.close()
}

#[test]
fn test_extract_rlang_version() -> io::Result<()> {
let config_name = "DESCRIPTION";
let config_content = "
Package: starship
Version: 1.0.0
Title: Starship
";
let project_dir = create_project_dir()?;
fill_config(&project_dir, config_name, Some(config_content))?;
expect_output(&project_dir, Some("v1.0.0"), None);
project_dir.close()
}
fn create_project_dir() -> io::Result<TempDir> {
tempfile::tempdir()
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/rlang.rs
Expand Up @@ -133,9 +133,9 @@ https://www.gnu.org/licenses/."#;
}

#[test]
fn folder_with_rprofile_files() -> io::Result<()> {
fn folder_with_description_files() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join(".Rprofile"))?.sync_all()?;
File::create(dir.path().join("DESCRIPTION"))?.sync_all()?;
check_r_render(&dir);
dir.close()
}
Expand Down

0 comments on commit 5267c46

Please sign in to comment.