Skip to content

Commit f965a60

Browse files
authored
Find pip-compile in global path if it does not exist in venv (#114)
1 parent 598ad5d commit f965a60

File tree

1 file changed

+11
-2
lines changed
  • catkin_virtualenv/src/catkin_virtualenv

1 file changed

+11
-2
lines changed

catkin_virtualenv/src/catkin_virtualenv/venv.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def check(self, requirements, extra_pip_args):
122122
existing_requirements = f.read()
123123

124124
# Re-lock the requirements
125-
command = [self._venv_bin("pip-compile"), "--no-header", "--annotation-style", "line", requirements, "-o", "-"]
125+
command = [self._find_pip_compile(), "--no-header", "--annotation-style", "line", requirements, "-o", "-"]
126126
if extra_pip_args:
127127
command += ["--pip-args", " ".join(extra_pip_args)]
128128

@@ -156,7 +156,7 @@ def lock(self, package_name, input_requirements, no_overwrite, extra_pip_args):
156156
logger.info("Lock file already exists, not overwriting")
157157
return
158158

159-
pip_compile = self._venv_bin("pip-compile")
159+
pip_compile = self._find_pip_compile()
160160
command = [pip_compile, "--no-header", "--annotation-style", "line", input_requirements]
161161

162162
if os.path.normpath(input_requirements) == os.path.normpath(output_requirements):
@@ -194,6 +194,15 @@ def _venv_bin(self, binary_name):
194194
return os.path.abspath(os.path.join(self.path, "local", "bin", binary_name))
195195
raise RuntimeError("Binary {} not found in venv".format(binary_name))
196196

197+
def _find_pip_compile(self):
198+
try:
199+
return self._venv_bin("pip-compile")
200+
except RuntimeError as exc:
201+
global_pip_compile = shutil.which("pip-compile")
202+
if global_pip_compile is None:
203+
raise RuntimeError("pip-compile not found found in Venv or global PATH") from exc
204+
return global_pip_compile
205+
197206
def _check_module(self, python_executable, module):
198207
try:
199208
with open(os.devnull, "w") as devnull:

0 commit comments

Comments
 (0)