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
This commit is contained in:
parent
bc3eb031c2
commit
5267c464eb
|
@ -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": {
|
||||
|
|
|
@ -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"],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -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))
|
||||
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue