Skip to content

Commit

Permalink
Fix ensurepath
Browse files Browse the repository at this point in the history
  • Loading branch information
Jendker committed Mar 13, 2024
1 parent 0c0a6fb commit fe24c8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pipx/commands/ensure_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ def ensure_path(location: Path, *, force: bool) -> Tuple[bool, bool]:
def ensure_pipx_paths(force: bool) -> ExitCode:
"""Returns pipx exit code."""
bin_paths = {paths.ctx.bin_dir}
if paths.ctx.is_global:
paths.ctx.make_local()
another_path = paths.ctx.bin_dir
paths.ctx.make_global()
else:
paths.ctx.make_global()
another_path = paths.ctx.bin_dir
paths.ctx.make_local()
bin_paths.add(another_path)

pipx_user_bin_path = get_pipx_user_bin_path()
if pipx_user_bin_path is not None:
Expand Down
3 changes: 3 additions & 0 deletions src/pipx/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class _PathContext:
_base_shared_libs: Optional[Union[Path, str]] = get_expanded_environ("PIPX_SHARED_LIBS")
_fallback_home: Path = Path.home() / ".local/pipx"
_home_exists: bool = _base_home is not None or _fallback_home.exists()
is_global: bool = False
log_file: Optional[Path] = None

@property
Expand Down Expand Up @@ -78,12 +79,14 @@ def make_local(self) -> None:
self._base_bin = get_expanded_environ("PIPX_BIN_DIR")
self._base_man = get_expanded_environ("PIPX_MAN_DIR")
self._home_exists = self._base_home is not None or self._fallback_home.exists()
self.is_global = False

def make_global(self) -> None:
self._base_home = get_expanded_environ("PIPX_GLOBAL_HOME") or DEFAULT_PIPX_GLOBAL_HOME
self._base_bin = get_expanded_environ("PIPX_GLOBAL_BIN_DIR") or DEFAULT_PIPX_GLOBAL_BIN_DIR
self._base_man = get_expanded_environ("PIPX_GLOBAL_MAN_DIR") or DEFAULT_PIPX_GLOBAL_MAN_DIR
self._home_exists = self._base_home is not None or self._fallback_home.exists()
self.is_global = True

@property
def standalone_python_cachedir(self) -> Path:
Expand Down

0 comments on commit fe24c8f

Please sign in to comment.