Skip to content

Commit 21bcbf0

Browse files
authored
Remove unnecessary check from pt_visual_explain() (#915)
1 parent f887257 commit 21bcbf0

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

src/django_mysql/models/query.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
StopWatch,
2525
WeightedAverageRate,
2626
format_duration,
27-
have_program,
2827
settings_to_cmd_args,
2928
)
3029

@@ -723,9 +722,6 @@ def can_approx_count(queryset: QuerySetMixin) -> bool:
723722

724723

725724
def pt_visual_explain(queryset: models.QuerySet, display: bool = True) -> str:
726-
if not have_program("pt-visual-explain"): # pragma: no cover
727-
raise OSError("pt-visual-explain doesn't appear to be installed")
728-
729725
connection = connections[queryset.db]
730726
capturer = CaptureQueriesContext(connection)
731727
with capturer, connection.cursor() as cursor:

src/django_mysql/utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import subprocess
43
import time
54
from collections import defaultdict
65
from types import TracebackType
@@ -10,8 +9,6 @@
109
from django.db.backends.base.base import BaseDatabaseWrapper
1110
from django.db.models import Model
1211

13-
from django_mysql.compat import cache
14-
1512

1613
class WeightedAverageRate:
1714
"""
@@ -128,12 +125,6 @@ def settings_to_cmd_args(settings_dict: dict[str, Any]) -> list[str]:
128125
return args
129126

130127

131-
@cache
132-
def have_program(program_name: str) -> bool:
133-
status = subprocess.call(["which", program_name], stdout=subprocess.PIPE)
134-
return status == 0
135-
136-
137128
def collapse_spaces(string: str) -> str:
138129
bits = string.replace("\n", " ").split(" ")
139130
return " ".join(filter(None, bits))

tests/testapp/test_models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import pickle
44
import re
5-
from unittest import mock, skipUnless
5+
import shutil
6+
from unittest import SkipTest, mock
67

78
import pytest
89
from django.contrib.contenttypes.models import ContentType
@@ -14,7 +15,7 @@
1415
from django.test.utils import captured_stdout, override_settings
1516

1617
from django_mysql.models import ApproximateInt, SmartIterator, add_QuerySetMixin
17-
from django_mysql.utils import have_program, index_name
18+
from django_mysql.utils import index_name
1819
from tests.testapp.models import (
1920
Author,
2021
AuthorExtra,
@@ -756,8 +757,13 @@ def test_filter_and_delete(self):
756757
assert bad_authors.count() == 0
757758

758759

759-
@skipUnless(have_program("pt-visual-explain"), "pt-visual-explain must be installed")
760760
class VisualExplainTests(TestCase):
761+
@classmethod
762+
def setUpClass(cls):
763+
if shutil.which("pt-visual-explain") is None: # pragma: no cover
764+
raise SkipTest("pt-visual-explain must be installed")
765+
super().setUpClass()
766+
761767
def test_basic(self):
762768
with captured_stdout() as capture:
763769
Author.objects.all().pt_visual_explain()

0 commit comments

Comments
 (0)