From 5267c464eb5e4b23e44cdb7c56919991f4f67ae3 Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Wed, 29 Nov 2023 07:25:40 +0100 Subject: [PATCH] feat: R lang packages version, remove .Rprofile from rlang detection (#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 --- .github/config-schema.json | 4 ++-- src/configs/rlang.rs | 2 +- src/modules/package.rs | 21 +++++++++++++++++++++ src/modules/rlang.rs | 4 ++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/config-schema.json b/.github/config-schema.json index a01d83c0..22b938e0 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -1397,7 +1397,7 @@ "Rsx" ], "detect_files": [ - ".Rprofile" + "DESCRIPTION" ], "detect_folders": [ ".Rproj.user" @@ -5100,7 +5100,7 @@ }, "detect_files": { "default": [ - ".Rprofile" + "DESCRIPTION" ], "type": "array", "items": { diff --git a/src/configs/rlang.rs b/src/configs/rlang.rs index 3982b723..c759f570 100644 --- a/src/configs/rlang.rs +++ b/src/configs/rlang.rs @@ -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"], } } diff --git a/src/modules/package.rs b/src/modules/package.rs index 4c9f20b1..f72cb059 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -310,6 +310,13 @@ fn get_dart_pub_version(context: &Context, config: &PackageConfig) -> Option Option { + let file_contents = context.read_file_from_pwd("DESCRIPTION")?; + let re = Regex::new(r"(?m)^Version:\s*(?P.*$)").unwrap(); + let caps = re.captures(&file_contents)?; + format_version(&caps["version"], config.version_format) +} + fn get_version(context: &Context, config: &PackageConfig) -> Option { let package_version_fn: Vec Option> = vec![ get_cargo_version, @@ -330,6 +337,7 @@ fn get_version(context: &Context, config: &PackageConfig) -> Option { get_sbt_version, get_daml_project_version, get_dart_pub_version, + get_rlang_version, ]; package_version_fn.iter().find_map(|f| f(context, config)) @@ -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 { tempfile::tempdir() } diff --git a/src/modules/rlang.rs b/src/modules/rlang.rs index a3902497..5620e025 100644 --- a/src/modules/rlang.rs +++ b/src/modules/rlang.rs @@ -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() }