You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ede5178
Browse filesBrowse the repository at this point in the historyBrowse files
_=subprocess.run( # noqa: S603 # this is trusted input, it's our own arguments being passed in
38
-
["git", "ls-remote", "--exit-code", "--tags", remote, f"refs/tags/{tag}"], # noqa: S607 # if `git` isn't in PATH already, then there are bigger problems to solve
39
-
check=True,
40
-
stdout=subprocess.DEVNULL,
41
-
stderr=subprocess.DEVNULL,
42
-
)
13
+
no_matching_refs_return_code=2
14
+
result=subprocess.run( # noqa: S603 # this is trusted input, it's our own arguments being passed in
15
+
["git", "ls-remote", "--exit-code", "--tags", remote, f"refs/tags/{tag}"], # noqa: S607 # if `git` isn't in PATH already, then there are bigger problems to solve
16
+
stdout=subprocess.DEVNULL,
17
+
check=False,
18
+
)
19
+
ifresult.returncode==0:
43
20
raiseException(f"Error: tag '{tag}' exists on remote '{remote}'") # noqa: TRY002 # not worth a custom exception
44
-
exceptsubprocess.CalledProcessError:
45
-
# tag not present, continue
46
-
return
21
+
if (
22
+
result.returncode!=no_matching_refs_return_code
23
+
): # anything else is a real error (bad remote, auth failure, network)
24
+
raiseException(f"git ls-remote exited with code {result.returncode} (remote={remote!r})") # noqa: TRY002 # not worth a custom exception
47
25
48
26
49
-
defmain():
27
+
defmain()->None:
50
28
parser=argparse.ArgumentParser(
51
-
description=(
52
-
"Extract the version from a pyproject.toml file, "
53
-
"confirm that git tag v<version> is not present, or "
54
-
"create and push the tag to a remote."
55
-
)
29
+
description=("Confirm that git tag v<version> is not present on a remote, or create and push the tag.")
56
30
)
57
31
_=parser.add_argument(
58
-
"file",
59
-
nargs="?",
60
-
default="pyproject.toml",
61
-
help="Path to pyproject.toml (default: pyproject.toml)",
32
+
"--version",
33
+
required=True,
34
+
help="Version string (e.g. 1.0.6 or v1.0.6); the tag will always be v<version>",
_=subprocess.run(["git", "tag", tag], check=True) # noqa: S603,S607 # this is trusted input, it's our own pyproject.toml file. and if `git` isn't in PATH, then there are larger problems anyway
90
-
_=subprocess.run(["git", "push", args.remote, tag], check=True) # noqa: S603,S607 # this is trusted input, it's our own pyproject.toml file. and if `git` isn't in PATH, then there are larger problems anyway
58
+
_=subprocess.run(["git", "tag", tag], check=True) # noqa: S603,S607 # this is trusted input, it's our own version string. and if `git` isn't in PATH, then there are larger problems anyway
59
+
_=subprocess.run(["git", "push", args.remote, tag], check=True) # noqa: S603,S607 # this is trusted input, it's our own version string. and if `git` isn't in PATH, then there are larger problems anyway
91
60
return
92
61
93
62
ifargs.confirm_tag_not_present:
94
63
ensure_tag_not_present(tag, args.remote)
95
-
return
96
-
97
-
# Default behavior: just print the version
98
-
print(ver) # noqa: T201 # specifically printing this out so CI pipelines can read the value from stdout
0 commit comments