Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:

- name: Run example
working-directory: ./example
env:
CI: 'false'
run: |
dfetch update
dfetch update
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Release 0.11.0 (unreleased)
====================================

* Don't show animation when running in CI (#702)

Release 0.10.0 (released 2025-03-12)
====================================

Expand Down
10 changes: 10 additions & 0 deletions dfetch/project/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def __init__(self, project: dfetch.manifest.project.ProjectEntry) -> None:
self.__project = project
self.__metadata = Metadata.from_project_entry(self.__project)

self._show_animations = not self._running_in_ci()

@staticmethod
def _running_in_ci() -> bool:
"""Are we running in CI."""
ci_env_var = os.getenv("CI", "")
return bool(ci_env_var) and ci_env_var[0].lower() in ("t", "1", "y")

def check_wanted_with_local(self) -> Tuple[Optional[Version], Optional[Version]]:
"""Given the project entry in the manifest, get the relevant version from disk.

Expand Down Expand Up @@ -109,6 +117,7 @@ def update(self, force: bool = False) -> None:
text=f"Fetching {self.__project.name} {to_fetch}",
spinner="dots",
text_color="green",
enabled=self._show_animations,
):
actually_fetched = self._fetch_impl(to_fetch)
self._log_project(f"Fetched {actually_fetched}")
Expand Down Expand Up @@ -148,6 +157,7 @@ def check_for_update(self, reporters: Sequence[AbstractCheckReporter]) -> None:
text=f"Checking {self.__project.name}",
spinner="dots",
text_color="green",
enabled=self._show_animations,
):
latest_version = self._check_for_newer_version()

Expand Down
38 changes: 35 additions & 3 deletions tests/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# mypy: ignore-errors
# flake8: noqa

from unittest.mock import MagicMock, Mock, patch
from typing import Optional
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -95,7 +96,11 @@ def get_default_branch(self):
],
)
def test_check_wanted_with_local(
name, given_on_disk, given_wanted, expect_wanted, expect_have
name: str,
given_on_disk: Version | None,
given_wanted: Version,
expect_wanted: Version,
expect_have: Version | None,
):
with patch("dfetch.project.vcs.os.path.exists") as mocked_path_exists:
with patch("dfetch.project.vcs.Metadata.from_file") as mocked_metadata:
Expand All @@ -120,7 +125,9 @@ def test_check_wanted_with_local(
("same-hash", "1234", "1234", False),
],
)
def test_are_there_local_changes(name, hash_in_metadata, current_hash, expectation):
def test_are_there_local_changes(
name: str, hash_in_metadata: str, current_hash: str, expectation: bool
):
with patch("dfetch.project.vcs.hash_directory") as mocked_hash_directory:
with patch("dfetch.project.vcs.VCS._on_disk_hash") as mocked_on_disk_hash:
vcs = ConcreteVCS(ProjectEntry({"name": "proj1"}))
Expand All @@ -129,3 +136,28 @@ def test_are_there_local_changes(name, hash_in_metadata, current_hash, expectati
mocked_hash_directory.return_value = current_hash

assert expectation == vcs._are_there_local_changes()


@pytest.mark.parametrize(
"ci_env_value, expected_result",
[
("true", True),
("1", True),
("True", True),
("yes", True),
("YES", True),
("false", False),
(None, False),
(0, False),
("other", False),
],
)
def test_ci_enabled(
monkeypatch: pytest.MonkeyPatch, ci_env_value: Optional[str], expected_result: bool
):
if ci_env_value is None:
monkeypatch.delenv("CI", raising=False)
else:
monkeypatch.setenv("CI", ci_env_value)

assert ConcreteVCS._running_in_ci() == expected_result
Loading