[Git][reproducible-builds/diffoscope][master] 2 commits: Refactor find_executable into an explicit method. (Re: reproducible-builds/diffoscope#283)
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Tue Oct 26 09:55:51 UTC 2021
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
d2ac5465 by Chris Lamb at 2021-10-26T10:52:10+01:00
Refactor find_executable into an explicit method. (Re: reproducible-builds/diffoscope#283)
- - - - -
e2d3abe8 by Chris Lamb at 2021-10-26T10:55:35+01:00
Try some alternative suffixes (eg. ".py") to support distributions that strip or retain them. (Closes: reproducible-builds/diffoscope#283)
- - - - -
1 changed file:
- diffoscope/tools.py
Changes:
=====================================
diffoscope/tools.py
=====================================
@@ -29,9 +29,6 @@ except ImportError:
from .profiling import profile
from .external_tools import EXTERNAL_TOOLS, REMAPPED_TOOL_NAMES, GNU_TOOL_NAMES
-# Memoize calls to ``which`` to avoid excessive stat calls
-find_executable = functools.lru_cache()(shutil.which)
-
# The output of --help and --list-tools will use the order of this dict.
# Please keep it alphabetized.
OS_NAMES = collections.OrderedDict(
@@ -44,6 +41,24 @@ OS_NAMES = collections.OrderedDict(
)
+ at functools.lru_cache()
+def find_executable(cmd):
+ """
+ Given a command name (eg. `dumppdf`), return the absolute path to that
+ command. Will also try the command with some common suffixes (eg.
+ `dumppdf.py`) to support distributions that strip or retain them.
+
+ Returns an empy string (``) if no command is found.
+ """
+
+ for suffix in ("", ".py"):
+ val = shutil.which(f"{cmd}{suffix}")
+ if val:
+ return val
+
+ return ""
+
+
def get_tools(only_missing=False):
"""Return the tool configuration in a dict"""
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/34cde92c4e6c6e473c21d660bd78624f0e688644...e2d3abe863e8a3f9760a396c57eaa07e0e394ff6
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/34cde92c4e6c6e473c21d660bd78624f0e688644...e2d3abe863e8a3f9760a396c57eaa07e0e394ff6
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20211026/429656eb/attachment.htm>
More information about the rb-commits
mailing list