Skip to content

Instantly share code, notes, and snippets.

@mfansler
Last active April 20, 2024 22:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mfansler/b7b75f73495b940948efa3c1f58827bf to your computer and use it in GitHub Desktop.
Save mfansler/b7b75f73495b940948efa3c1f58827bf to your computer and use it in GitHub Desktop.
Conda Forge `staged-recipes` utility scripts
#!/usr/bin/env bash -l
#' Usage: `bash -l new-cran-pkg.sh {r-package}`
#' Purpose: Generates a Conda Forge recipe using `conda_r_skeleton_helper` and
#' pushes this to a personal fork of `staged-recipes`.
#' Notes: Should be located in and run from a `staged-recipes` clone prefix.
#' `git remote -v` should show `origin` set to a personal fork
#' and `upstream` set to 'git@github.com:conda-forge/staged-recipes.git'.
#' CRAN package name should be prefixed with 'r-' and given in all lowercase.
set -xe -o pipefail
## validate arguments
if [[ $# -ne 1 ]]; then
echo "Requires a CRAN package name (e.g., 'r-foo')." >&2
exit 2
fi
## parameters
tmp=$(mktemp -d)
PKG_CF=$1
FILE_META="recipes/${PKG_CF}/meta.yaml"
GIT_CRSH="git@github.com:bgruening/conda_r_skeleton_helper.git"
DIR_CRSH="${tmp}/conda_r_skeleton_helper"
## update main
./sync-upstream.sh
## checkout new branch
git checkout -b $1
## clone conda_r_skeleton_helper
git clone --depth=1 ${GIT_CRSH} ${DIR_CRSH}
## generate recipe
DIR_SR=$(pwd)
pushd ${DIR_CRSH}
echo "$1" > packages.txt
conda run -n base --live-stream python run.py
## copy recipe
cp -R "$1" "${DIR_SR}/recipes/."
popd
## add files
git add recipes/$1/*
## commit
git commit -m "adds $1"
## setup remote
git push -u origin $1
## cleanup
rm -rf ${tmp}
## lint recipe
{ printf "\nLinting recipe:\n\n"; } 2> /dev/null
conda run -n base --live-stream \
conda-smithy recipe-lint recipes/${PKG_CF}
## suggest stub
PKG_CRAN=$(grep "# Package:" ${FILE_META} | awk '{print $3}')
{
printf "\nSuggested PR stub:\n\n"
printf "\tAdds [CRAN package \`%s\`](https://cran.r-project.org/package=%s) as \`%s\`. Recipe generated with \`conda_r_skeleton_helper\`.\n\n" $PKG_CRAN $PKG_CRAN $PKG_CF
} 2> /dev/null
#!/usr/bin/env bash -l
#' Usage: `bash -l new-pypi-pkg.sh {pypi-package}`
#' Purpose: Generates a Conda Forge recipe using `grayskull` and
#' pushes this to a personal fork of `staged-recipes`.
#' Notes: Should be located in and run from a `staged-recipes` clone prefix.
#' `git remote -v` should show `origin` set to a personal fork
#' and `upstream` set to 'git@github.com:conda-forge/staged-recipes.git'.
#' PyPI package name should be given in all lowercase.
set -xe -o pipefail
if [[ $# -ne 1 ]]; then
echo "Requires a PyPI package name (all lowercase)." >&2
exit 2
fi
## update main
./sync-upstream.sh
## run grayskull
conda run -n grayskull \
--live-stream \
grayskull pypi -o recipes/ $1
## checkout new branch
git checkout -b $1
## add files
git add recipes/$1/*
## commit
git commit -m "adds $1"
## setup remote
git push -u origin $1
#!/usr/bin/env bash -l
#' Usage: `bash -l sync-upstream.sh`
#' Purpose: Refreshes 'main' branch of current git repository from upstream
#' and pushes this to 'origin'.
#' Notes: Should be located in and run from a `staged-recipes` clone prefix.
#' `git remote -v` should show `origin` set to a personal fork
#' and `upstream` set to 'git@github.com:conda-forge/staged-recipes.git'.
set -xe -o pipefail
## switch back to main
git checkout main
## git fetch from upstream
git fetch upstream main
## merge upstream
git merge upstream/main
## update remote
git push
@mfansler
Copy link
Author

mfansler commented Jan 7, 2023

Purpose

These are helper scripts to automate the creation of new recipes for Conda Forge packages. It uses grayskull for PyPI packages and conda_r_skeleton_helper for CRAN packages.

Setup

  1. Create a personal fork of conda-forge/staged-recipes repository.

  2. Clone the fork locally.

    git clone git@github.com:[username]/staged-recipes.git
  3. Add a remote upstream for the original repository.

    git remote add upstream git@github.com:conda-forge/staged-recipes.git

    Result can be checked with git remote -v.

  4. Place all shell scripts from this Gist in the root of the local staged-recipes folder. Do not commit them.

  5. The new-pypi-pkg.sh assumes a Conda environment named grayskull exists and has the latest grayskull install. This can be done with

    conda create -n grayskull -c conda-forge grayskull

Usage

After setup, running the scripts will synchronize with upstream, create a new recipe, commit it to a new branch, and push this branch to the origin remote (personal fork).

CRAN Example

bash -l new-cran-pkg.sh r-future.callr

PyPI Example

bash -l new-pypi-pkg.sh twarc

Visiting the GitHub repository recently after running should show a banner prompting the user to create a Pull Request.

@mfansler
Copy link
Author

Revision 3 Changes

  • CRAN script now also runs conda-smithy linting (helps to catch aberrant SPDX license issues)
  • CRAN script suggests a stub for use in PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment