Skip to content

Commit 5b44deb

Browse files
authored
Release v1.5.1 (#33)
v1.5.1
2 parents 10f1b3b + fbbbdbd commit 5b44deb

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [v1.5.1](https://github.com/SallingGroup-AI-and-ML/venv-cli/releases/tag/v1.5.1) (2024-01-10)
4+
5+
### Minor changes
6+
* `venv install` now fails early and with a more descriptve error message when run outside of a virtual environment. [#30](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/30)
7+
8+
### Bug fixes
9+
* `venv clear` is now able to clear virtual environments that contain editable installs. [#30](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/30)
10+
311
## [v1.5.0](https://github.com/SallingGroup-AI-and-ML/venv-cli/releases/tag/v1.5.0) (2024-01-04)
412

513
### Major changes

src/venv-cli/venv.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ _yellow="\033[01;33m"
99
_red="\033[31m"
1010

1111
# Version number has to follow pattern "^v\d+\.\d+\.\d+.*$"
12-
_version="v1.5.0"
12+
_version="v1.5.1"
1313

1414
# Valid VCS URL environment variable pattern
1515
# https://peps.python.org/pep-0610/#specification
@@ -34,6 +34,14 @@ venv::raise() {
3434
return "${_fail}"
3535
}
3636

37+
venv::_check_venv_activated() {
38+
if [ -z "${VIRTUAL_ENV}" ]; then
39+
venv::raise "No virtual environment activated. Please activate the virtual environment first"
40+
return "${_fail}"
41+
fi
42+
return "${_success}"
43+
}
44+
3745
venv::_check_if_help_requested() {
3846
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
3947
return "${_success}"
@@ -258,7 +266,9 @@ venv::install() {
258266

259267
# Clear the environment before running pip install to avoid orphaned packages
260268
# https://github.com/SallingGroup-AI-and-ML/venv-cli/issues/9
261-
venv::clear
269+
if ! venv::clear; then
270+
return "${_fail}"
271+
fi
262272

263273
venv::color_echo "${_green}" "Installing requirements from ${requirements_file}"
264274
if ! pip install --require-virtualenv --use-pep517 -r "${requirements_file}" "$@"; then
@@ -339,9 +349,16 @@ venv::clear() {
339349
return "${_success}"
340350
fi
341351

352+
if ! venv::_check_venv_activated; then
353+
return "${_fail}"
354+
fi
355+
342356
venv::color_echo "${_yellow}" "Removing all packages from virtual environment ..."
343-
pip freeze --require-virtualenv \
344-
| cut -d "@" -f1 \
357+
pip list --format freeze \
358+
--exclude pip \
359+
--exclude setuptools \
360+
--exclude wheel \
361+
| cut -d "=" -f1 \
345362
| xargs --no-run-if-empty pip uninstall --require-virtualenv -y
346363
venv::color_echo "${_green}" "All packages removed!"
347364
}

tests/test_venv_install.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import subprocess
23
from itertools import chain
34
from pathlib import Path
45

@@ -22,6 +23,12 @@ def _check_package_was_installed(requirement: str, installed_line: str) -> None:
2223
assert package_name in installed_line, f"Package {package_name} was not installed succesfully"
2324

2425

26+
def test_venv_install_not_activated(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
27+
with pytest.raises(subprocess.CalledProcessError), monkeypatch.context() as m:
28+
m.delenv("VIRTUAL_ENV", raising=False)
29+
run_command(["venv install"], cwd=tmp_path, activated=False)
30+
31+
2532
@pytest.mark.order(after="test_venv_activate.py::test_venv_activate")
2633
@parametrize_with_cases(argnames=["files", "requirements_base"], cases=CasesVenvInstallRequirementstxt)
2734
@pytest.mark.parametrize("use_file_name", [True, False])

tests/test_venv_internals.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import subprocess
2+
from pathlib import Path
23

34
import pytest
45

56
from tests.helpers import run_command
67

78

9+
def test_check_venv_activated_no_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
10+
with pytest.raises(subprocess.CalledProcessError), monkeypatch.context() as m:
11+
m.delenv("VIRTUAL_ENV", raising=False)
12+
run_command(["venv::_check_venv_activated"], cwd=tmp_path, activated=False)
13+
14+
15+
@pytest.mark.order(after="test_venv_activate.py::test_venv_activate")
16+
def test_check_venv_activated_yes_env(tmp_path: Path):
17+
run_command("venv::_check_venv_activated", cwd=tmp_path, activated=True)
18+
19+
820
@pytest.mark.order("first")
921
@pytest.mark.parametrize(
1022
["filename", "expected"],

0 commit comments

Comments
 (0)