| library(tidyverse) |
|
|
| repos <- jsonlite::read_json("repos.json") |
|
|
| extract_licenses <- function(repo) { |
| repo_name <- as.character(repo$name) |
| path <- glue::glue("CRAN/{repo_name}.zip") |
|
|
| files <- try(zip::zip_list(path), silent = TRUE) |
|
|
| if (inherits(files, "try-error")) { |
| return(NULL) |
| } |
|
|
| files <- files[endsWith(files$filename, "DESCRIPTION"), ] |
|
|
| if (nrow(files) > 1) { |
| files <- head(files, 1) |
| } |
|
|
| if (nrow(files) == 0) { |
| return(NULL) |
| } |
|
|
| temp <- tempfile() |
| on.exit(unlink(temp), add = TRUE) |
|
|
| zip::unzip(path, files = files$filename, junkpaths = TRUE, exdir = temp) |
|
|
| desc <- try(desc::desc(file = fs::path(temp, "DESCRIPTION")), silent = TRUE) |
|
|
| if (inherits(desc, "try-error")) { |
| return(NULL) |
| } |
|
|
| tibble( |
| package = repo_name, |
| license = desc$get("License") |
| ) |
| } |
|
|
| library(future) |
| plan(multisession, workers = 8) |
|
|
| |
| licenses <- furrr::future_map( |
| repos, |
| \(repo) extract_licenses(repo), |
| .progress = TRUE |
| ) |
|
|
| licenses <- bind_rows(licenses) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| licenses_table <- readr::read_csv("licenses.csv") |
| |
| licenses_table <- licenses_table %>% distinct() |
|
|
| parse_license <- function(license) { |
| licenses <- license |> |
| stringr::str_split(pattern = stringr::fixed("|")) |
| licenses <- stringr::str_trim(licenses[[1]]) |
|
|
| license <- stringr::str_extract(licenses, "(.*?)(?=\\()|.*") |
| license <- stringr::str_trim(license) |
|
|
| version <- stringr::str_extract(licenses, "\\((.*?)\\)") |
| tibble( |
| license_code = license, |
| version = version |
| ) |
| } |
|
|
| |
| |
| license_codes <- licenses_table %>% |
| mutate( |
| parsed = map(classif, parse_license) |
| ) %>% |
| unnest(parsed) |
|
|
| |
|
|
| gh_license_table <- license_codes %>% |
| mutate( |
| license_gh = case_when( |
| classif == "GPL (>=2)" ~ "gpl-3.0", |
| classif == "GPL (>=3)" ~ "gpl-3.0", |
| classif == "GPL (==3)" ~ "gpl-3.0", |
| classif == "GPL (==2)" ~ "gpl-2.0", |
| classif == "GPL" ~ "gpl-3.0", |
| classif %in% c("GPL (==3) | LGPL (==2.1)", "GPL (>2)", "GPL (>3)", "GPL (>=1)") ~ "gpl-3.0", |
| classif %in% c("GPL (<=2)", "GPL (==2) | LGPL (==2.1) | MPL (==1.1)") ~ "gpl-2.0", |
|
|
| classif == "AGPL (>=2)" ~ "agpl-3.0", |
| classif == "AGPL (>=3)" ~ "agpl-3.0", |
| classif == "AGPL (==3)" ~ "agpl-3.0", |
| classif == "AGPL (==2)" ~ "agpl-2.0", |
| classif == "AGPL" ~ "agpl-3.0", |
|
|
| classif == "LGPL (>=2)" ~ "lgpl-3.0", |
| classif == "LGPL (>=3)" ~ "lgpl-3.0", |
| classif %in% c("LGPL (==3)", "LGPL (>2)", "LGPL (>=2.1)") ~ "lgpl-3.0", |
| classif %in% c("LGPL (==2)", "LGPL (>=2, <3)", "LGPL (>= 2.0, < 3)", "LGPL (==2.1)", "LGPL (>= 2.0, < 3) | MPL") ~ "lgpl-2.0", |
| classif == "LGPL" ~ "lgpl-3.0", |
|
|
| classif == "BSD" ~ "bsd-3-clause", |
| classif == "BSD-Clause (==2)" ~ "bsd-2-clause", |
| classif == "BSD-Clause (==3)" ~ "bsd-3-clause", |
|
|
| classif %in% c("BSL", "BSL (==1)") ~ "bsl-1.0", |
| str_detect(classif, fixed("CC-BY (==4)")) ~ "cc-by-4.0", |
| str_detect(classif, fixed("CC-BY-SA (==4)")) ~ "cc-by-sa-4.0", |
| str_detect(classif, "CC0") ~ "cc0-1.0", |
| str_detect(classif, "FreeBSD") ~ "bsd-2-clause", |
|
|
| classif %in% c("MPL (==2)", "MPL (>=2)", "MPL") ~ "mpl-2.0", |
| classif %in% c("EUPL", "EUPL (==1.1)") ~ "eupl-1.1", |
| classif %in% c("EPL", "EPL (>=1)") ~ "epl-2.0", |
|
|
| str_detect(classif, "Apache") ~ "apache-2.0", |
| str_detect(classif, "Artistic") ~ "artistic-2.0", |
| str_detect(classif, "MIT") ~ "mit", |
| str_detect(classif, fixed("BSD-Clause (==2)")) ~ "bsd-2-clause", |
| str_detect(classif, fixed("BSD-Clause (==3)")) ~ "bsd-3-clause", |
| str_detect(classif, fixed("MPL (==2)")) ~ "mpl-2.0", |
|
|
| str_detect(classif, fixed("GPL (>=2")) ~ "gpl-2.0", |
| str_detect(classif, fixed("GPL (>=3")) ~ "gpl-3.0", |
| TRUE ~ "unknown" |
| ) |
| ) |
|
|
| |
| packages <- licenses %>% |
| mutate(license = stringr::str_trim(license)) %>% |
| left_join(gh_license %>% select(license, license_gh) %>% distinct(), by = "license") %>% |
| mutate(license_gh = coalesce(license_gh, "unknown")) |
|
|
| arrow::write_parquet(packages, "packages.parquet") |
|
|
|
|