]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
build-integration-branch: convert to argparse
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 16 Jul 2025 17:39:27 +0000 (13:39 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 16 Jul 2025 18:36:35 +0000 (14:36 -0400)
Convert build-integration-branch to use the stdlib argparse module.

Argparse is:
* Part of the python standard library and available since 3.2
* Well documented as a stdlib component
* Widely used
* Fairly simple and direct

docopt is:
* Clever
* Not documented as a dependency of this script (so I bet most users
  are relying on the fallback behavior)
* Of questionable maintenance status with:
  - No releases since 2014
  - Only four PRs merged since 2019
  - Last merged PR was merged, recommending an alternate repo, and then
    disappeared from the commit history of the master branch, indicating
    a possible maintainership/status discrepancy
  - Only a couple of commits merged since 2018 (visible on github)
* In my opinion: not particularly ergonomic esp. wrt dictionary based
  key access

I feel pretty comfortable making this conversion as I think it will
make the script easier to maintain and extend.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/script/build-integration-branch

index 95ee5a1adca48531ad4137c46f5c500b37290f7d..c4e39fdd67a1493a5efdfbf462b9a489ba6efa46 100755 (executable)
@@ -13,17 +13,9 @@ OR adding an entry like the following to `~/.netrc`:
   machine github.com
   password ghp_E7ln0tAR34LtoK3nIsw34RyTve2moM3BvK
   ```
-
-
-Usage:
-  build-integration-branch <label> [--no-date]
-  build-integration-branch -h | --help
-
-Options:
-  -h --help   Show this screen.
-  --no-date   Don't add `{postfix}` to the branch name.
 """
 
+import argparse
 import json
 import os
 import requests
@@ -35,31 +27,52 @@ from subprocess import call, check_output
 from urllib.parse import urljoin
 
 TIME_FORMAT = '%Y-%m-%d-%H%M'
-postfix = "-" + time.strftime(TIME_FORMAT, time.localtime())
-
-current_branch = check_output('git rev-parse --abbrev-ref HEAD',
-                              shell=True).strip().decode()
-if current_branch in 'mimic nautilus octopus pacific quincy reef squid tentacle'.split():
-    postfix += '-' + current_branch
-    print(f"Adding current branch name '-{current_branch}' as a postfix")
-
-repo = "ceph/ceph"
-
-try:
-    from docopt import docopt
-    arguments = docopt(__doc__.format(postfix=postfix))
-    label = arguments['<label>']
-    branch = label
-    if not arguments['--no-date']:
-        branch += postfix
-except ImportError:
-    # Fallback without docopt.
-    label = sys.argv[1]
-    assert len(sys.argv) == 2
-    branch = label + postfix
+CODENAMES = 'mimic nautilus octopus pacific quincy reef squid tentacle'
+REPO = "ceph/ceph"
+
+
+def get_postfix():
+    postfix = "-" + time.strftime(TIME_FORMAT, time.localtime())
+    current_branch = (
+        check_output('git rev-parse --abbrev-ref HEAD', shell=True)
+        .strip()
+        .decode()
+    )
+    if current_branch in CODENAMES.split():
+        postfix += '-' + current_branch
+        print(f"Adding current branch name '-{current_branch}' as a postfix")
+    return postfix
+
+
+def parse_args():
+    parser = argparse.ArgumentParser(usage=__doc__)
+    parser.add_argument(
+        "--no-date",
+        "--no-postfix",
+        action="store_true",
+        help="Don't add `{postfix}` to the branch name.",
+    )
+    parser.add_argument(
+        "--repo",
+        default=REPO,
+        help="GitHub repository (in `<org>/<name>` form)",
+    )
+    parser.add_argument(
+        "label",
+        help="GitHub label to search for",
+    )
+    return parser.parse_args()
 
 
 def main():
+    cli = parse_args()
+    if cli.no_date:
+        branch = cli.label
+    else:
+        branch = cli.label + get_postfix()
+    label = cli.label
+    repo = cli.repo
+
     token = ''
     try:
         nrc = netrc.netrc()