Skip to content

Commit 8325c25

Browse files
authored
refactor: move release_tag to __init__.py (#67)
1 parent 79f0db1 commit 8325c25

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

clang_tools/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
YELLOW = "\033[93m"
77
install_os = check_install_os()
88
suffix = ".exe" if install_os == "windows" else ""
9+
10+
# tag of https://github.com/cpp-linter/clang-tools-static-binaries/releases
11+
release_tag = "master-be694ee7"

clang_tools/install.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import subprocess
1212
import sys
1313
from typing import Optional
14+
from . import release_tag
1415

1516
from . import install_os, RESET_COLOR, suffix, YELLOW
1617
from .util import download_file, verify_sha512, get_sha_checksum
@@ -63,19 +64,19 @@ def is_installed(tool_name: str, version: str) -> Optional[Path]:
6364

6465

6566
def clang_tools_binary_url(
66-
tool: str, version: str, release_tag: str = "master-be694ee7"
67+
tool: str, version: str, tag: str = release_tag
6768
) -> str:
6869
"""Assemble the URL to the binary.
6970
7071
:param tool: The name of the tool to download.
7172
:param version: The version of the tool to download.
72-
:param release_tag: The release tag used in the base URL.
73+
:param tag: The release tag used in the base URL.
7374
7475
:returns: The URL used to download the specified tool.
7576
"""
7677
base_url = (
7778
"https://github.com/cpp-linter/clang-tools-static-binaries/releases/download/"
78-
+ release_tag
79+
+ tag
7980
)
8081
download_url = f"{base_url}/{tool}-{version}_{install_os}-amd64{suffix}"
8182
return download_url.replace(" ", "")

tests/test_util.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from clang_tools import install_os
55
from clang_tools.install import clang_tools_binary_url
66
from clang_tools.util import check_install_os, download_file, get_sha_checksum
7+
from clang_tools import release_tag
78

89

910
def test_check_install_os():
@@ -13,12 +14,12 @@ def test_check_install_os():
1314

1415

1516
@pytest.mark.parametrize(
16-
"tag", ["master-be694ee7", pytest.param("latest", marks=pytest.mark.xfail)]
17+
"tag", [release_tag, pytest.param("latest", marks=pytest.mark.xfail)]
1718
)
1819
def test_download_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, tag: str):
1920
"""Test that deliberately fails to download a file."""
2021
monkeypatch.chdir(str(tmp_path))
21-
url = clang_tools_binary_url("clang-format", "12", release_tag=tag)
22+
url = clang_tools_binary_url("clang-format", "12", tag=release_tag)
2223
file_name = download_file(url, "file.tar.gz", True)
2324
assert file_name is not None
2425

@@ -30,5 +31,5 @@ def test_get_sha(monkeypatch: pytest.MonkeyPatch):
3031
expected = Path(f"clang-format-12_{install_os}-amd64.sha512sum").read_text(
3132
encoding="utf-8"
3233
)
33-
url = clang_tools_binary_url("clang-format", "12", release_tag="master-be694ee7")
34+
url = clang_tools_binary_url("clang-format", "12", tag=release_tag)
3435
assert get_sha_checksum(url) == expected

0 commit comments

Comments
 (0)