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

If installed in /usr/local , ramalama libs cannot be found #333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 12 additions & 14 deletions bin/ramalama
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,33 @@ def add_pipx_venvs_bin_to_path():
if os.path.exists(pipx_bin_path):
os.environ["PATH"] += ":" + pipx_bin_path

def add_pipx_venvs_to_syspath():
def add_site_packages_to_syspath(base_path):
"""
Adds all available pipx virtual environments' site-packages directories to sys.path.
This function looks for any venv in ~/.local/pipx/venvs and appends their site-packages directory to sys.path.
Adds site-packages directories from a given base path to sys.path.
"""
python_version = f'{sys.version_info.major}.{sys.version_info.minor}'
pipx_venvs_path = os.path.expanduser(f'~/.local/pipx/venvs/*/lib/python{python_version}/site-packages')
matched_paths = glob.glob(pipx_venvs_path)
search_pattern = os.path.expanduser(f'{base_path}/lib/python{python_version}/site-packages')
matched_paths = glob.glob(search_pattern)
if matched_paths:
for path in matched_paths:
sys.path.insert(0, path)

return

pipx_venvs_path = os.path.expanduser('~/.local/pipx/venvs/*/lib/python*/site-packages')
matched_paths = glob.glob(pipx_venvs_path)
if not matched_paths:
return

for path in matched_paths:
sys.path.insert(0, path)
# Fallback to a more general pattern if the specific version doesn't match
search_pattern = os.path.expanduser(f'{base_path}/lib/python*/site-packages')
matched_paths = glob.glob(search_pattern)
if matched_paths:
for path in matched_paths:
sys.path.insert(0, path)

def main(args):
sharedirs = ["./", "/opt/homebrew/share/ramalama", "/usr/local/share/ramalama", "/usr/share/ramalama"]
syspath = next((d for d in sharedirs if os.path.exists(d+"/ramalama/cli.py")), None)
if syspath:
sys.path.insert(0, syspath)

add_pipx_venvs_to_syspath()
add_site_packages_to_syspath('~/.local/pipx/venvs/*')
add_site_packages_to_syspath('/usr/local')
add_pipx_venvs_bin_to_path()
try:
import ramalama
Expand Down
6 changes: 4 additions & 2 deletions container_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ build() {
local conman_build=("${conman[@]}")
if [ "$#" -lt 2 ]; then
add_build_platform
"${conman_build[@]}" 2>&1 | tee container_build.log
"${conman_build[@]}"
rm_container_image
elif [ "$2" = "-d" ]; then
add_build_platform
echo "${conman_build[@]}"
elif [ "$2" = "push" ]; then
"${conman[@]}" push "quay.io/ramalama/$image_name"
elif [ "$2" = "log" ]; then
"${conman_build[@]}" 2>&1 | tee container_build.log
else
add_build_platform
"${conman_build[@]}" 2>&1 | tee container_build.log
"${conman_build[@]}"
rm_container_image
fi

Expand Down
Loading