Skip to content

Commit

Permalink
Merge pull request #436 from PyAr/fix-bin-path-windows
Browse files Browse the repository at this point in the history
Get the bin env path in a multiplatform way.
  • Loading branch information
facundobatista authored Jul 16, 2024
2 parents 0b6f655 + 77f2e89 commit 0e7e101
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion fades/envbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import logging
import os
import pathlib
import shutil

from datetime import datetime
Expand Down Expand Up @@ -80,7 +81,9 @@ def create_with_external_venv(self, interpreter, options):
logger.exception("Error creating virtual environment: %s", error)
raise FadesError("General error while running external venv")

self.env_bin_path = os.path.join(self.env_path, 'bin')
# XXX Facundo 2024-06-29: the helper uses pathlib; eventually everything will be
# pathlib (see #435), so these translations will be cleaned up
self.env_bin_path = str(helpers.get_env_bin_path(pathlib.Path(self.env_path)))

def create_env(self, interpreter, is_current, options):
"""Create the virtual environment and return its info."""
Expand Down
9 changes: 9 additions & 0 deletions fades/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,12 @@ def download_remote_script(url):
temp_fh.write(content)
temp_fh.close()
return temp_fh.name


def get_env_bin_path(base_env_path):
"""Find and return the environment's binary path in a multiplatformy way."""
for subdir in ("bin", "Scripts"):
binpath = base_env_path / subdir
if binpath.exists():
return binpath
raise ValueError(f"Binary subdir not found in {base_env_path!r}")
21 changes: 20 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from urllib.request import Request

import logassert

import pytest
from xdg import BaseDirectory

from fades import HTTP_STATUS_NOT_FOUND, HTTP_STATUS_OK, helpers
Expand Down Expand Up @@ -563,3 +563,22 @@ def test_downloader_raw_with_redirection(self):
self.assertEqual(content, raw_service_response.decode("utf8"))

self.assertLoggedInfo("Download redirect detect, now downloading from", final_url)


def test_getbinpath_posix(tmp_path):
realbin = tmp_path / "bin"
realbin.mkdir()
path = helpers.get_env_bin_path(tmp_path)
assert path == realbin


def test_getbinpath_windows(tmp_path):
realbin = tmp_path / "Scripts"
realbin.mkdir()
path = helpers.get_env_bin_path(tmp_path)
assert path == realbin


def test_getbinpath_missing(tmp_path):
with pytest.raises(ValueError):
helpers.get_env_bin_path(tmp_path)

0 comments on commit 0e7e101

Please sign in to comment.