Skip to content

Find pip-compile in global path if it does not exist in venv #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions catkin_virtualenv/src/catkin_virtualenv/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def check(self, requirements, extra_pip_args):
existing_requirements = f.read()

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

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

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

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

def _find_pip_compile(self):
try:
return self._venv_bin("pip-compile")
except RuntimeError as exc:
global_pip_compile = shutil.which("pip-compile")
if global_pip_compile is None:
raise RuntimeError("pip-compile not found found in Venv or global PATH") from exc
return global_pip_compile

def _check_module(self, python_executable, module):
try:
with open(os.devnull, "w") as devnull:
Expand Down