Skip to content
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

Use the current python interpreter for bootstrapping pip+venv #557

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
22 changes: 12 additions & 10 deletions var/ramble/repos/builtin/package_managers/pip/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
import re
import sys

from ramble.application import ApplicationError
from ramble.pkgmankit import *
Expand Down Expand Up @@ -223,14 +224,7 @@ class PipRunner:
install_config_name = "config:pip:install"

def __init__(self, dry_run=False):
cmds = ["python3", "python"]
# Set up python for bootstrapping
for c in cmds:
self.bs_python = which(c, required=False)
if self.bs_python:
break
if not self.bs_python:
raise RunnerError("python is not found in path")
self.bs_python = None
self.env_path = None
self.configs = []
self.dry_run = dry_run
Expand All @@ -255,7 +249,8 @@ def create_env(self, env_path):

if not self.dry_run:
if not os.path.exists(os.path.join(env_path, self._venv_name)):
self.bs_python(
bs_python = self.get_bootstrap_python()
bs_python(
"-m", "venv", os.path.join(env_path, self._venv_name)
)

Expand All @@ -264,7 +259,7 @@ def create_env(self, env_path):

def _get_venv_python(self):
if self.dry_run:
return self.bs_python.copy()
return self.get_bootstrap_python().copy()
return Executable(
os.path.join(self.env_path, self._venv_name, "bin", "python")
)
Expand Down Expand Up @@ -296,6 +291,13 @@ def install(self):
installer(*freeze_args, output=f)
self.installed = True

def get_bootstrap_python(self):
if not self.bs_python:
# Set up python for bootstrapping.
# Simply use the same interpreter as the current Ramble.
self.bs_python = which(sys.executable, required=True)
return self.bs_python

def _get_activate_script_path(self):
return os.path.join(self.env_path, self._venv_name, "bin", "activate")

Expand Down