Skip to content

Conversation

@h4rvey-g
Copy link

@h4rvey-g h4rvey-g commented Sep 7, 2025

This pull request adds support for generating Conda recipes from R packages hosted on GitHub but not on CRAN (close #532, part of #615). There are also minor improvements to original cran methods.

GitHub R package support:

  • Added detection of GitHub URLs in the CLI and get_cran_metadata, routing these to the new get_github_r_metadata function for metadata extraction. [1] [2] [3]
  • Implemented get_github_r_metadata, which downloads, extracts, and parses metadata from GitHub R package archives, and builds the recipe dictionary accordingly.
  • Added helper functions for downloading GitHub archives and extracting metadata from the DESCRIPTION file.

Dependency and metadata handling:

  • Improved parsing of the Depends field to extract R version constraints and ensure r-base is always included, with version constraints if specified. [1] [2]
  • Set global Jinja2 variables for package name and version in the recipe for better templating.

CLI and output improvements:

  • Updated CLI help text to indicate GitHub URLs are supported for R packages.
  • Enhanced log messages to indicate the origin of the R package (CRAN, GitHub, or local).

Testing:

  • Added tests for GitHub URL detection, the new GitHub metadata extraction flow, and the original CRAN flow to ensure correct behavior.

General improvements:

  • Made recipe directory creation more robust by supporting nested directories and avoiding errors if the directory already exists.
  • Added missing imports and improved code organization. [1] [2]

Test

Recipe generated from CRAN stringr package

grayskull cran stringr --output /tmp/cran_recipe

{% set name = "stringr" %}
{% set version = "1.5.1" %}

package:
  name: r-{{ name }}
  version: '{{ version }}'

source:
  url: https://cran.r-project.org/src/contrib/stringr_{{ version }}.tar.gz
  sha256: a4adec51bb3f04214b1d8ef40d3a58949f21b1497cbeaf2ba552e0891eef45de

build:
  number: 0
  merge_build_host: true
  script: R CMD INSTALL --build .
  rpaths:
    - lib/R/lib/
    - lib/

requirements:
  host:
    - r-base >=3.6
    - r-cli
    - r-glue >=1.6.1
    - r-lifecycle >=1.0.3
    - r-magrittr
    - r-rlang >=1.0.0
    - r-stringi >=1.5.3
    - r-vctrs >=0.4.0
  run:
    - r-base >=3.6
    - r-cli
    - r-glue >=1.6.1
    - r-lifecycle >=1.0.3
    - r-magrittr
    - r-rlang >=1.0.0
    - r-stringi >=1.5.3
    - r-vctrs >=0.4.0

test:
  commands:
    - $R -e "library('stringr')"  # [not win]
    - "\"%R%\" -e \"library('stringr')\""  # [win]

about:
  home: https://stringr.tidyverse.org, https://github.com/tidyverse/stringr
  summary: A consistent, simple and easy to use set of wrappers around the fantastic 'stringi' package. All function and argument names (and positions) are consistent, all functions deal with "NA"'s and zero length vectors in the same way, and the output from one function is easy to feed into the input of another.
  license: MIT

extra:
  recipe-maintainers:
    - h4rvey-g

Recipe generated from GitHub stringr package

grayskull cran "https://github.com/tidyverse/stringr" --output /tmp/github_recipe

{% set name = "stringr" %}
{% set version = "1.5.1" %}

package:
  name: r-{{ name }}
  version: '{{ version }}'

source:
  url: https://github.com/tidyverse/stringr/archive/v{{ version }}.tar.gz
  sha256: 96d19d7693842acd00688860133b26fcf73d3108be7bbb8c06631a355e1acd55

build:
  number: 0
  merge_build_host: true
  script: R CMD INSTALL --build .
  rpaths:
    - lib/R/lib/
    - lib/

requirements:
  host:
    - r-base >=3.6
    - r-cli
    - r-glue >=1.6.1
    - r-lifecycle >=1.0.3
    - r-magrittr
    - r-rlang >=1.0.0
    - r-stringi >=1.5.3
    - r-vctrs >=0.4.0
  run:
    - r-base >=3.6
    - r-cli
    - r-glue >=1.6.1
    - r-lifecycle >=1.0.3
    - r-magrittr
    - r-rlang >=1.0.0
    - r-stringi >=1.5.3
    - r-vctrs >=0.4.0

test:
  commands:
    - $R -e "library('stringr')"  # [not win]
    - "\"%R%\" -e \"library('stringr')\""  # [win]

about:
  home: https://github.com/tidyverse/stringr
  summary: A consistent, simple and easy to use set of wrappers around the fantastic 'stringi' package. All function and argument names (and positions) are consistent, all functions deal with "NA"'s and zero length vectors in the same way, and the output from one function is easy to feed into the input of another.
  doc_url: https://stringr.tidyverse.org, https://github.com/tidyverse/stringr
  dev_url: https://github.com/tidyverse/stringr
  license: MIT

extra:
  recipe-maintainers:
    - h4rvey-g

@h4rvey-g h4rvey-g requested a review from a team as a code owner September 7, 2025 13:33
assert metadata["package"]["version"] == "{{ version }}"

# Verify source information
assert "github.com" in metadata["source"]["url"]

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
github.com
may be at an arbitrary position in the sanitized URL.
assert "r-base" in recipe["requirements"]["run"]

# Verify about section
assert "github.com" in recipe["about"]["home"]

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
github.com
may be at an arbitrary position in the sanitized URL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Recipes for R-based packages from Github

1 participant