From 73c9f7c7543923f77705a21541dc2d11b57f55a6 Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Tue, 22 Aug 2023 13:42:15 -0700 Subject: [PATCH 1/2] Require a virtual env --- src/pip4a/base.py | 2 +- src/pip4a/cli.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pip4a/base.py b/src/pip4a/base.py index 2d15890..d25a296 100644 --- a/src/pip4a/base.py +++ b/src/pip4a/base.py @@ -48,7 +48,7 @@ def _set_interpreter( # noqa: PLR0912 if venv: if not venv.exists(): if create: - if not venv.relative_to(Path.cwd()): + if not venv.is_relative_to(Path.cwd()): err = "Virtual environment must relative to cwd to create it." logger.critical(err) msg = f"Creating virtual environment: {venv}" diff --git a/src/pip4a/cli.py b/src/pip4a/cli.py index 6319d08..260136b 100644 --- a/src/pip4a/cli.py +++ b/src/pip4a/cli.py @@ -4,6 +4,7 @@ import logging import os +import site from pathlib import Path from typing import TYPE_CHECKING @@ -69,6 +70,13 @@ def ensure_isolated(self: Cli) -> None: err = f"Collections found in {usr_coll}" errors.append(err) + if "VIRTUAL_ENV" not in env_vars and not self.args.venv: + err = ( + "Unable to install in user site packages directory:" + f" {site.getusersitepackages()}, please activate or specify a virtual envrionment" + ) + errors.append(err) + if errors: err = ( "The development environment is not isolated," From e490bd35656c3a045ddb8d81c5587956ed6a6755 Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Tue, 22 Aug 2023 13:43:29 -0700 Subject: [PATCH 2/2] Spelling --- src/pip4a/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip4a/cli.py b/src/pip4a/cli.py index 260136b..feddbcf 100644 --- a/src/pip4a/cli.py +++ b/src/pip4a/cli.py @@ -73,7 +73,7 @@ def ensure_isolated(self: Cli) -> None: if "VIRTUAL_ENV" not in env_vars and not self.args.venv: err = ( "Unable to install in user site packages directory:" - f" {site.getusersitepackages()}, please activate or specify a virtual envrionment" + f" {site.getusersitepackages()}, please activate or specify a virtual environment" ) errors.append(err)