Skip to content

Commit

Permalink
Merge pull request #9 from cidrblock/feature_require_venv
Browse files Browse the repository at this point in the history
Require a virtual env
  • Loading branch information
cidrblock authored Aug 22, 2023
2 parents 4bb2471 + e490bd3 commit 8223691
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pip4a/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
8 changes: 8 additions & 0 deletions src/pip4a/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
import site

from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -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 environment"
)
errors.append(err)

if errors:
err = (
"The development environment is not isolated,"
Expand Down

0 comments on commit 8223691

Please sign in to comment.