Skip to content

Commit 7650c2b

Browse files
committed
Suppress animation in CI contexts
Fixes #702
1 parent 1768152 commit 7650c2b

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

.github/workflows/run.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838

3939
- name: Run example
4040
working-directory: ./example
41+
env:
42+
CI: 'false'
4143
run: |
4244
dfetch update
4345
dfetch update

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Release 0.11.0 (unreleased)
2+
====================================
3+
4+
* Don't show animation when running in CI (#702)
5+
16
Release 0.10.0 (released 2025-03-12)
27
====================================
38

dfetch/project/vcs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def __init__(self, project: dfetch.manifest.project.ProjectEntry) -> None:
3535
self.__project = project
3636
self.__metadata = Metadata.from_project_entry(self.__project)
3737

38+
self._show_animations = not self._running_in_ci()
39+
40+
@staticmethod
41+
def _running_in_ci() -> bool:
42+
"""Are we running in CI."""
43+
ci_env_var = os.getenv("CI", "")
44+
return bool(ci_env_var) and ci_env_var[0].lower() in ("t", "1", "y")
45+
3846
def check_wanted_with_local(self) -> Tuple[Optional[Version], Optional[Version]]:
3947
"""Given the project entry in the manifest, get the relevant version from disk.
4048
@@ -109,6 +117,7 @@ def update(self, force: bool = False) -> None:
109117
text=f"Fetching {self.__project.name} {to_fetch}",
110118
spinner="dots",
111119
text_color="green",
120+
enabled=self._show_animations,
112121
):
113122
actually_fetched = self._fetch_impl(to_fetch)
114123
self._log_project(f"Fetched {actually_fetched}")
@@ -148,6 +157,7 @@ def check_for_update(self, reporters: Sequence[AbstractCheckReporter]) -> None:
148157
text=f"Checking {self.__project.name}",
149158
spinner="dots",
150159
text_color="green",
160+
enabled=self._show_animations,
151161
):
152162
latest_version = self._check_for_newer_version()
153163

tests/test_vcs.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# mypy: ignore-errors
44
# flake8: noqa
55

6-
from unittest.mock import MagicMock, Mock, patch
6+
from typing import Optional
7+
from unittest.mock import patch
78

89
import pytest
910

@@ -95,7 +96,11 @@ def get_default_branch(self):
9596
],
9697
)
9798
def test_check_wanted_with_local(
98-
name, given_on_disk, given_wanted, expect_wanted, expect_have
99+
name: str,
100+
given_on_disk: Version | None,
101+
given_wanted: Version,
102+
expect_wanted: Version,
103+
expect_have: Version | None,
99104
):
100105
with patch("dfetch.project.vcs.os.path.exists") as mocked_path_exists:
101106
with patch("dfetch.project.vcs.Metadata.from_file") as mocked_metadata:
@@ -120,7 +125,9 @@ def test_check_wanted_with_local(
120125
("same-hash", "1234", "1234", False),
121126
],
122127
)
123-
def test_are_there_local_changes(name, hash_in_metadata, current_hash, expectation):
128+
def test_are_there_local_changes(
129+
name: str, hash_in_metadata: str, current_hash: str, expectation: bool
130+
):
124131
with patch("dfetch.project.vcs.hash_directory") as mocked_hash_directory:
125132
with patch("dfetch.project.vcs.VCS._on_disk_hash") as mocked_on_disk_hash:
126133
vcs = ConcreteVCS(ProjectEntry({"name": "proj1"}))
@@ -129,3 +136,28 @@ def test_are_there_local_changes(name, hash_in_metadata, current_hash, expectati
129136
mocked_hash_directory.return_value = current_hash
130137

131138
assert expectation == vcs._are_there_local_changes()
139+
140+
141+
@pytest.mark.parametrize(
142+
"ci_env_value, expected_result",
143+
[
144+
("true", True),
145+
("1", True),
146+
("True", True),
147+
("yes", True),
148+
("YES", True),
149+
("false", False),
150+
(None, False),
151+
(0, False),
152+
("other", False),
153+
],
154+
)
155+
def test_ci_enabled(
156+
monkeypatch: pytest.MonkeyPatch, ci_env_value: Optional[str], expected_result: bool
157+
):
158+
if ci_env_value is None:
159+
monkeypatch.delenv("CI", raising=False)
160+
else:
161+
monkeypatch.setenv("CI", ci_env_value)
162+
163+
assert ConcreteVCS._running_in_ci() == expected_result

0 commit comments

Comments
 (0)