Skip to content

Commit

Permalink
refactor: move release_tag to __init__.py (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenxianpeng committed Jan 18, 2024
1 parent 79f0db1 commit 8325c25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions clang_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
YELLOW = "\033[93m"
install_os = check_install_os()
suffix = ".exe" if install_os == "windows" else ""

# tag of https://github.com/cpp-linter/clang-tools-static-binaries/releases
release_tag = "master-be694ee7"
7 changes: 4 additions & 3 deletions clang_tools/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import sys
from typing import Optional
from . import release_tag

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


def clang_tools_binary_url(
tool: str, version: str, release_tag: str = "master-be694ee7"
tool: str, version: str, tag: str = release_tag
) -> str:
"""Assemble the URL to the binary.
:param tool: The name of the tool to download.
:param version: The version of the tool to download.
:param release_tag: The release tag used in the base URL.
:param tag: The release tag used in the base URL.
:returns: The URL used to download the specified tool.
"""
base_url = (
"https://github.com/cpp-linter/clang-tools-static-binaries/releases/download/"
+ release_tag
+ tag
)
download_url = f"{base_url}/{tool}-{version}_{install_os}-amd64{suffix}"
return download_url.replace(" ", "")
Expand Down
7 changes: 4 additions & 3 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from clang_tools import install_os
from clang_tools.install import clang_tools_binary_url
from clang_tools.util import check_install_os, download_file, get_sha_checksum
from clang_tools import release_tag


def test_check_install_os():
Expand All @@ -13,12 +14,12 @@ def test_check_install_os():


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

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

0 comments on commit 8325c25

Please sign in to comment.