From 36d14b6d93d6ca30db8abc30e8f1d5f27d1bfbcd Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Tue, 24 Sep 2024 10:56:12 -0400 Subject: [PATCH 1/3] Support pre-release on conda-forge release --- cf_release.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/cf_release.py b/cf_release.py index 1389214..e544c6c 100644 --- a/cf_release.py +++ b/cf_release.py @@ -2,7 +2,8 @@ import requests import subprocess from os.path import join, exists, dirname -from click import prompt, confirm +import click +from click import prompt, confirm, Choice """ This script streamlines the process of updating Python package versions and @@ -111,7 +112,7 @@ def update_meta_yaml(meta_file_path, new_version, new_sha256): file.write(line) -def run_gh_shell_command(cwd, meta_file_path, version, SHA256, username, package_name): +def run_gh_shell_command(cwd, meta_file_path, version, SHA256, username, package_name, release_type): """ Create a PR from a branch name of to the main branch of the feedstock repository. @@ -135,9 +136,10 @@ def run_gh_shell_command(cwd, meta_file_path, version, SHA256, username, package # Push the new branch to your origin repository run_command(f"git push origin {version}", cwd=cwd) - # Explicit set --feedstock as the default repo - # for GitHub CLI - run_command(f"gh repo set-default conda-forge/{package_name}-feedstock", cwd=cwd) + # Set the branch + branch = "main" if release_type == "release" else "rc" + + run_command(f"gh repo set-default conda-forge/{package_name}-feedstock --branch {branch}", cwd=cwd) # Create a pull request using GitHub CLI pr_command = ( @@ -182,9 +184,7 @@ def print_available_package_info(package_name, pypi_version_info): def get_github_username(): """Get the GitHub username using the GitHub CLI.""" try: - username = subprocess.check_output( - ["gh", "api", "user", "--jq", ".login"], text=True - ).strip() + username = subprocess.check_output(["gh", "api", "user", "--jq", ".login"], text=True).strip() return username except subprocess.CalledProcessError: raise RuntimeError( @@ -193,16 +193,26 @@ def get_github_username(): ) +@click.command() +@click.option( + "--version", + type=click.Choice(["1", "2"]), + prompt="\nQ. Would you like to (1) release or (2) pre-release on conda-forge?", +) +def prompt_release_type(version): + release_type = "release" if version == "1" else "pre-release" + print("You've selected:", release_type) + return release_type + + """ Main Entry Point """ def main(): - # Q1 Ask the package name from the user - package_name = prompt( - "Q1. Please enter the PyPI package name Ex) diffpy.pdfgui", type=str - ) + release_type = prompt_release_type() + package_name = prompt("Q1. Please enter the PyPI package name Ex) diffpy.pdfgui", type=str) # Get path to feedstock directory and meta.yaml file fd_stock_dir_path, meta_file_path = get_feedstock_and_meta_file_path(package_name) @@ -222,8 +232,7 @@ def main(): new_version = prompt("Please enter the version you would like to use", type=str) while new_version not in pypi_version_info: new_version = prompt( - f"ERROR: {new_version} is not available in the list of versions. " - "Please re-enter", + f"ERROR: {new_version} is not available in the list of versions. " "Please re-enter", type=str, ) @@ -240,7 +249,7 @@ def main(): # Run the shell command to update the .yml file and create a PR run_gh_shell_command( - fd_stock_dir_path, meta_file_path, new_version, SHA256, username, package_name + fd_stock_dir_path, meta_file_path, new_version, SHA256, username, package_name, release_type ) From 9f40900d10fa84de47158b60545e3649bdffc03f Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Tue, 24 Sep 2024 10:57:21 -0400 Subject: [PATCH 2/3] Apply black --- cf_release.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/cf_release.py b/cf_release.py index e544c6c..23c0abc 100644 --- a/cf_release.py +++ b/cf_release.py @@ -112,7 +112,9 @@ def update_meta_yaml(meta_file_path, new_version, new_sha256): file.write(line) -def run_gh_shell_command(cwd, meta_file_path, version, SHA256, username, package_name, release_type): +def run_gh_shell_command( + cwd, meta_file_path, version, SHA256, username, package_name, release_type +): """ Create a PR from a branch name of to the main branch of the feedstock repository. @@ -139,7 +141,10 @@ def run_gh_shell_command(cwd, meta_file_path, version, SHA256, username, package # Set the branch branch = "main" if release_type == "release" else "rc" - run_command(f"gh repo set-default conda-forge/{package_name}-feedstock --branch {branch}", cwd=cwd) + run_command( + f"gh repo set-default conda-forge/{package_name}-feedstock --branch {branch}", + cwd=cwd, + ) # Create a pull request using GitHub CLI pr_command = ( @@ -184,7 +189,9 @@ def print_available_package_info(package_name, pypi_version_info): def get_github_username(): """Get the GitHub username using the GitHub CLI.""" try: - username = subprocess.check_output(["gh", "api", "user", "--jq", ".login"], text=True).strip() + username = subprocess.check_output( + ["gh", "api", "user", "--jq", ".login"], text=True + ).strip() return username except subprocess.CalledProcessError: raise RuntimeError( @@ -212,7 +219,9 @@ def prompt_release_type(version): def main(): release_type = prompt_release_type() - package_name = prompt("Q1. Please enter the PyPI package name Ex) diffpy.pdfgui", type=str) + package_name = prompt( + "Q1. Please enter the PyPI package name Ex) diffpy.pdfgui", type=str + ) # Get path to feedstock directory and meta.yaml file fd_stock_dir_path, meta_file_path = get_feedstock_and_meta_file_path(package_name) @@ -232,7 +241,8 @@ def main(): new_version = prompt("Please enter the version you would like to use", type=str) while new_version not in pypi_version_info: new_version = prompt( - f"ERROR: {new_version} is not available in the list of versions. " "Please re-enter", + f"ERROR: {new_version} is not available in the list of versions. " + "Please re-enter", type=str, ) @@ -249,7 +259,13 @@ def main(): # Run the shell command to update the .yml file and create a PR run_gh_shell_command( - fd_stock_dir_path, meta_file_path, new_version, SHA256, username, package_name, release_type + fd_stock_dir_path, + meta_file_path, + new_version, + SHA256, + username, + package_name, + release_type, ) From 99d1027420c3cc775a4a995bdce4475b17c46b88 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Tue, 24 Sep 2024 10:59:42 -0400 Subject: [PATCH 3/3] Modify from version to choice for release type --- cf_release.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cf_release.py b/cf_release.py index 23c0abc..c38b507 100644 --- a/cf_release.py +++ b/cf_release.py @@ -202,12 +202,12 @@ def get_github_username(): @click.command() @click.option( - "--version", + "--choice", type=click.Choice(["1", "2"]), prompt="\nQ. Would you like to (1) release or (2) pre-release on conda-forge?", ) -def prompt_release_type(version): - release_type = "release" if version == "1" else "pre-release" +def prompt_release_type(choice): + release_type = "release" if choice == "1" else "pre-release" print("You've selected:", release_type) return release_type