Skip to content

Commit b42ef8a

Browse files
authored
v1.1.0 (#2)
2 parents f7807b3 + 16c47b8 commit b42ef8a

23 files changed

+739
-191
lines changed

.github/workflows/run_tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ permissions:
1313

1414
jobs:
1515
build:
16-
1716
runs-on: ubuntu-latest
18-
1917
steps:
2018
- uses: actions/checkout@v3
19+
2120
- name: Set up Python 3.10
2221
uses: actions/setup-python@v3
2322
with:
@@ -28,7 +27,7 @@ jobs:
2827

2928
- name: Install dependencies
3029
run: |
31-
python3.10 -m venv .venv --prompt="venv-cli"
30+
python3.10 -m venv .venv
3231
. .venv/bin/activate
3332
python -m pip install --require-virtualenv --upgrade pip
3433
python -m pip install --require-virtualenv -r dev-requirements.txt

CHANGELOG.md

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

3+
## [v1.1.0](https://github.com/SallingGroup-AI-and-ML/venv-cli/releases/tag/v1.1.0) (2023-08-02)
4+
5+
### New install script
6+
This release adds an `install.sh` script for easier installation of `venv-cli`. Now it can be installed by simply running
7+
```console
8+
$ bash install.sh
9+
```
10+
11+
For more information on installing and uninstalling, see the updated [README](https://github.com/SallingGroup-AI-and-ML/venv-cli/blob/v1.1.0/README.md)
12+
13+
### Internal changes
14+
15+
* Added functionality to `venv lock`: Since `pip freeze` (which `venv lock` is using under the hood) does not output the `auth`-part of VCS URLs, `venv lock` now includes a fix that tries to read them from a reference `requirements`-file, but **only if they are specified as environment variables** so as not to accidentally expose secrets in version-controlled `.lock`-files.
16+
17+
For more info on this, see `venv lock --help`.
18+
319
## [v1.0.2](https://github.com/SallingGroup-AI-and-ML/venv-cli/releases/tag/v1.0.2) (2023-08-02)
420

521
* Fixed test that checks the version number follows the required pattern.

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@
44

55
## Overview
66
`venv-cli` is a CLI tool to help create and manage virtual python environments.
7-
It uses `pip` and `python -m venv` underneath, and so only requires core python. This alleviates the bootstrapping problem of needing to install a python package using your system python and pip before you are able to create virtual environments.
7+
It uses `pip` and `python -m venv` underneath, and so only requires core python. This alleviates the bootstrapping problem of needing to install a python package using your system `python` and `pip` before you are able to create virtual environments.
88

9-
You also don't need `conda`, `pyenv`, `pythonz` etc. to manage your python versions. Just make sure the correct version of python is installed on your system, then reference that specific version when creating the virtual environment, and everything just works. No shims, no path hacks, just the _official_ `python` build.
9+
You also don't need `conda`, `pyenv`, `pythonz` etc. to manage your python versions. Just make sure the correct version of python is installed on your system, then reference that specific version when creating the virtual environment, and everything just works. No shims, no path hacks, just the official `python` build.
1010

1111
## Installation
1212

13-
Clone this repository, then add a line to your `~/.bashrc` (or `~/.zshrc`, etc) that sources the `src/venv-cli/venv.sh` file:
14-
15-
```bash
16-
if [ -f ~/venv-cli/src/venv-cli/venv.sh ]; then
17-
. ~/venv-cli/src/venv-cli/venv.sh
18-
fi
13+
Clone this repository, then run the `install.sh` script from your favourite shell:
14+
```console
15+
$ bash install.sh
1916
```
17+
This will install the `venv` source file, along with an uninstall script, in `/usr/local/share/venv/`, and add a line in the appropriate shell `rc`-file (e.g. `~/.bashrc`) sourcing the `venv` source script.
2018

2119
This makes the `venv` command avaiable in your terminal. To check if it works, restart the terminal and run
2220
```console
2321
$ venv --version
2422
venv-cli 1.0.0
2523
```
2624

25+
The install script also adds command completions for the invoked shell.
26+
27+
# Uninstall
28+
To uninstall `venv` and remove all files, run the uninstall script at `/usr/local/share/venv/`:
29+
```console
30+
$ bash /usr/local/share/venv/uninstall.sh
31+
```
32+
The script should be run by the user that ran the install script to correctly remove the sourcing lines from the `rc`-file of that user. However, since it also cleans up the files in `/usr/share/local/venv/`, it will ask for `sudo` access.
33+
2734
## Usage
2835

2936
To see the help menu, along with a list of available commands, run `venv -h/--help`.
@@ -100,7 +107,7 @@ are equivalent.
100107

101108
The installed packages are then _locked_ into the corresponding `.lock`-file, e.g. running `venv install dev-requirements.txt` will lock those installed packages into `dev-requirements.lock`.
102109

103-
Installing packages this way makes sure that they are "tracked", since installing them with `pip install` will keep no record of which packages have been installed in the environment, making it difficult to reproduce later on.
110+
Installing packages this way makes sure that they are tracked, since installing them with `pip install` will keep no record of which packages have been installed in the environment, making it difficult to reproduce later on.
104111

105112
### Development packages
106113
If you have both production and development package requirements, keep them in separate requirements-files, e.g. `requirements.txt` for production and `dev-requirements.txt` for development. An example of these could be:

install.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
_src_dir="${PWD}/src/venv-cli"
2+
_install_dir="/usr/local/share/venv"
3+
4+
set -e
5+
6+
install_common() {
7+
local rcfile="$1"
8+
local completion_file="$2"
9+
local completion_target="$3"
10+
11+
set -x
12+
sudo mkdir -p /usr/local/share/venv
13+
sudo cp "${_src_dir}/venv.sh" "${_install_dir}/venv"
14+
sudo cp "${_src_dir}/uninstall.sh" "${_install_dir}/uninstall.sh"
15+
16+
if [ -n "${completion_file}" ]; then
17+
sudo cp "${completion_file}" "${completion_target}"
18+
fi
19+
20+
# Append line to the shell config file to source the script
21+
echo -e "\n# Source function script for 'venv' command" >> "${rcfile}"
22+
echo ". ${_install_dir}/venv" >> "${rcfile}"
23+
{ set +x; } 2>/dev/null
24+
}
25+
26+
install_bash() {
27+
local rcfile="${HOME}/.bashrc"
28+
local completion_file="${_src_dir}/completions/bash/venv_completion.sh"
29+
local completion_target="/usr/share/bash-completion/completions/venv"
30+
PS4="\000" # Remove '++' from beginning of lines while printing commands
31+
32+
install_common "${rcfile}" "${completion_file}" "${completion_target}"
33+
}
34+
35+
install_zsh() {
36+
local rcfile="${HOME}/.zshrc"
37+
# local completion_file="${_src_dir}/completions/zsh/venv_completion.sh"
38+
# local completion_target="/usr/local/share/zsh/site-functions/_venv"
39+
echo "Command completions currently not supported for zsh"
40+
41+
install_common "${rcfile}"
42+
echo "fpath+=( ${_install_dir} )" >> "${rcfile}"
43+
echo "autoload -Uz venv" >> "${rcfile}"
44+
}
45+
46+
main() {
47+
if [ -n "${ZSH_VERSION}" ]; then
48+
install_zsh
49+
elif [ "${SHELL}" = "/bin/bash" ]; then
50+
install_bash
51+
else
52+
echo "Current shell is not supported, aborting..."
53+
return 1
54+
fi
55+
56+
echo "venv installed"
57+
}
58+
59+
main
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# bash completion for venv -*- shell-script -*-
2+
3+
_venv() {
4+
local cur_word prev_word subcommands fill_list
5+
cur_word="${COMP_WORDS[COMP_CWORD]}"
6+
prev_word="${COMP_WORDS[COMP_CWORD-1]}"
7+
subcommands="create activate install lock clear sync deactivate -V --version"
8+
command_options="-h --help"
9+
10+
if [ "${prev_word}" == "venv" ]; then
11+
fill_list="${subcommands} ${command_options}"
12+
else
13+
fill_list="${command_options}"
14+
fi
15+
COMPREPLY=($(compgen -W "${fill_list}" -- "${cur_word}"))
16+
}
17+
18+
complete -F _venv venv
19+
20+
# ex: filetype=sh
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#compdef venv
2+
3+
local curcontext="${curcontext}" state line
4+
typeset -A opt_args
5+
6+
# List of available options
7+
local -a subcommands=("create" "activate" "install" "lock" "clear" "sync" "deactivate" "-V" "--version")
8+
local -a command_options=("-h" "--help")
9+
local -a all=("${subcommands[@]} ${command_options[@]}")
10+
11+
case "${words}[2]" in
12+
"${subcommands}")
13+
# Complete the options if the second word matches any of the available options
14+
_describe "option" command_options
15+
;;
16+
*)
17+
case "${words}[1]" in
18+
venv)
19+
# Complete the base command options if the first word is "venv"
20+
_describe "option" all
21+
;;
22+
# *)
23+
# # If none of the above matches, complete file paths
24+
# _files
25+
# ;;
26+
esac
27+
;;
28+
esac

src/venv-cli/uninstall.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
_venv_dir="/usr/local/share/venv"
2+
3+
set -e
4+
PS4="\000"
5+
6+
post() {
7+
sudo rm ${_venv_dir}/* || true
8+
sudo rm -r "${_venv_dir}" || true
9+
}
10+
11+
uninstall_common() {
12+
local rcfile="$1"
13+
local completion_target="$2"
14+
15+
# Remove the line from shell config that sources the script
16+
sed -i "\|.*Source autocompletions for 'venv' command|d" "${HOME}/.bashrc"
17+
sed -i "\|\. ${_venv_dir}/venv|d" "${HOME}/.bashrc"
18+
19+
if [ -f "${completion_target}" ]; then
20+
sudo rm "${completion_target}"
21+
fi
22+
}
23+
24+
uninstall_bash() {
25+
local rcfile="${HOME}/.bashrc"
26+
local completion_target="/usr/share/bash-completion/completions/venv"
27+
28+
uninstall_common "${rcfile}" "${completion_target}"
29+
}
30+
31+
uninstall_zsh() {
32+
local rcfile="${HOME}/.zshrc"
33+
local completion_target="/usr/local/share/zsh/site-functions/_venv"
34+
35+
uninstall_common "${rcfile}" "${completion_target}"
36+
sed -i "\|fpath+=( ${_install_dir} )|d" "${HOME}/.zshrc"
37+
sed -i "\|autoload -Uz venv|d" "${HOME}/.zshrc"
38+
}
39+
40+
main() {
41+
if [ -f "${HOME}/.bashrc" ]; then
42+
uninstall_bash
43+
fi
44+
45+
if [ -f "${HOME}/.zshrc" ]; then
46+
uninstall_zsh
47+
fi
48+
49+
post
50+
echo "venv uninstalled"
51+
}
52+
53+
main

0 commit comments

Comments
 (0)