Skip to content
Open
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
1 change: 0 additions & 1 deletion .github/workflows/check-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-python
- run: |
uv run dev.py setup
uv run dev.py lint

check-generated-code:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ repos:
name: golangci-lint
language: system
files: \.go$
entry: bin/golangci-lint run --fix
entry: uv run dev.py lint
5 changes: 3 additions & 2 deletions dev/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import click

from . import commands
from . import tools
from . import setup


@click.command()
Expand All @@ -27,7 +27,8 @@ def lint() -> None:
Runs the linter.
"""
logging.info("Running linter")
setup.install_golangci_lint()
commands.run(
args=[tools.GOLANGCI_LINT.name, "run"],
args=["golangci-lint", "run"],
check=True,
)
54 changes: 32 additions & 22 deletions dev/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,38 @@ def install_golangci_lint() -> None:

def is_installed(tool: tools.Tool) -> bool:
"""
Checks if the given tool is already installed.
Checks if the given tool is already installed. It first looks in the project's bin directory,
then falls back to the system PATH.
"""
installed_path = shutil.which(tool.name)
if installed_path is not None:
tool_code, tool_out = commands.eval(args=tool.version_command)
if tool_code != 0:
raise Exception(f"Failed to find version of installed '{tool.name}'")
version_match = re.search(
pattern=tool.version_pattern,
string=tool_out,
flags=re.MULTILINE,
)
if version_match is None:
raise Exception(f"Failed to find version of installed '{tool.name}'")
installed_version = version_match.group("version")
if installed_version == tool.version:
logging.info(
f"Version {tool.version} of '{tool.name}' is already installed at '{installed_path}'"
)
return True
# Check the project bin directory first, then the system path:
bin_path = dirs.bin() / tool.name
if bin_path.exists():
installed_path = str(bin_path)
else:
installed_path = shutil.which(tool.name)
if installed_path is None:
return False

# Build the version command using the resolved path so we check the right binary:
version_command = [installed_path] + tool.version_command[1:]
tool_code, tool_out = commands.eval(args=version_command)
if tool_code != 0:
raise Exception(f"Failed to find version of installed '{tool.name}'")
version_match = re.search(
pattern=tool.version_pattern,
string=tool_out,
flags=re.MULTILINE,
)
if version_match is None:
raise Exception(f"Failed to find version of installed '{tool.name}'")
installed_version = version_match.group("version")
if installed_version == tool.version:
logging.info(
f"Found '{tool.name}' already installed at '{installed_path}', but version is '{installed_version}' "
f"instead of '{tool.version}'"
f"Version {tool.version} of '{tool.name}' is already installed at '{installed_path}'"
)
return False
return True
logging.info(
f"Found '{tool.name}' already installed at '{installed_path}', but version is '{installed_version}' "
f"instead of '{tool.version}'"
)
return False
Loading