Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move release_tag to __init__.py #67

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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