You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,20 @@
1
1
# Changelog
2
2
3
3
## Unreleased
4
+
4
5
* The project is now following the [Github Flow](https://docs.github.com/en/get-started/using-github/github-flow) branching model. The `main` branch is now the default branch, and the `develop` branch has been removed. Future development should create a new branch directly from `main`, and when done, creating a pull request back into `main`. Releases should be tagged directly on `main` as well.
*`venv install` can now be used to install individual packages: `venv install <package>`. [#37](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/37)
10
12
11
13
To enable this feature, installing from a requirements file now requires the use of the new `-r | --requirement` flags: `venv install -r requirements.txt`. Packages installed using `venv install <package>` are first added to the requirements file before reinstalling the entire environment to ensure reproducibility. To uninstall packages, use the new `venv uninstall` subcommand, e.g. `venv uninstall <package>`.
12
14
*`venv sync` has been removed. Use `venv install -r <requirements>.lock` instead. [#17](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/17)
13
15
14
16
### Major changes
17
+
15
18
* Added `venv uninstall` subcommand to complement the new functionality of `venv install <package>`. [#37](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/37)
16
19
17
20
Running `venv uninstall <package>` will first remove the package from `requirements.txt`, then use `venv install -r requirements.txt` to reinstall the environment without `<package>`.
@@ -20,17 +23,20 @@
20
23
* Loosened the file name requirements for `requirements` files. Requirements files can now be any valid file name with the extension `.txt` (`.lock` for lock files). [#35](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/35)
21
24
22
25
### Minor changes
26
+
23
27
* The `install.sh` script now supports specifying for which shell to install `venv-cli`, e.g. `./install.sh zsh`. [#29](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/29)
24
28
* Updated virtual environment activation instructions in `README.md` and when running `venv activate -h`[#37](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/37)
25
29
* Refactored bash completion script to enable better handling of arguments for subcommands. [8ac4daf](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/32/commits/8ac4daf89314f0ac2c1daf56bee9f4ac489f5004)
26
30
27
31
### Bug fixes
32
+
28
33
* Running the uninstall script now correctly removes the sourcing line from the user's `rc`-file. [#29](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/29)
29
34
* Running the installation script now adds the sourcing line to the user's `rc`-file only if it is not there already. [#29](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/29)
30
35
* Running `venv <subcommand>` now correctly returns the exit code from that subcommand. [8b7a54d](https://github.com/SallingGroup-AI-and-ML/venv-cli/commit/8b7a54db77e075760847dba8c12489e7fc4dbd4d)
31
36
* Removed a unit test that was failing sporadically when running tests multiprocessed using `pytest-xdist`. [30c501c](https://github.com/SallingGroup-AI-and-ML/venv-cli/commit/30c501ce1ef43d151ceb22718de80dc9ea9c30ac)
32
37
33
38
### Internal changes
39
+
34
40
* Added several new test cases to cover loosened requirements file name check. [#35](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/35)
35
41
* Removed unused test files. [8be87d9](https://github.com/SallingGroup-AI-and-ML/venv-cli/commit/8be87d95a75f5b532eaf1fd062796674ce7a764c)
36
42
* Updated test cases for `venv clear` and `venv lock` that use the `venv install` command. [6985681](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/32/commits/6985681a3b3ac8ae783406e1b76401b7075ea260)
*`venv install` now fails early and with a more descriptve error message when run outside of a virtual environment. [#31](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/31)
43
50
44
51
### Bug fixes
52
+
45
53
*`venv clear` is now able to clear virtual environments that contain editable installs. [#31](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/31)
*`venv install` now runs `venv clear` before installation. This ensures that the enrivonment doesn't end up with orphaned packages after making changes to `requirements.txt`. [#9](https://github.com/SallingGroup-AI-and-ML/venv-cli/issues/9)
69
82
70
83
## Minor changes
84
+
71
85
*`venv sync` command marked as deprecated with removal planned for `v2.0`. Use `venv install <requirements>.lock` instead. [#14](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/14)
*`venv lock` no longer tries to fill in credentials for packages installed via VCS. This behavior was undocumented and difficult to maintain and ultimately tried to alleviate a shortcoming of the way `pip` handles these credentials. [#11](https://github.com/SallingGroup-AI-and-ML/venv-cli/pull/11)
77
-
For users who have credentials as part of URLs in their `requirements.txt` files, there are other ways to handle credentials, e.g. filling them in `requirements.lock` manually, using a `.netrc` file to store the credetials or using a keyring. See https://pip.pypa.io/en/stable/topics/authentication/ for more info.
92
+
For users who have credentials as part of URLs in their `requirements.txt` files, there are other ways to handle credentials, e.g. filling them in `requirements.lock` manually, using a `.netrc` file to store the credetials or using a keyring. See [https://pip.pypa.io/en/stable/topics/authentication](https://pip.pypa.io/en/stable/topics/authentication) for more info.
78
93
79
94
### Minor changes
95
+
80
96
*`venv create` now prints the full python version used for creating the environment. [bb62c21](https://github.com/SallingGroup-AI-and-ML/venv-cli/commit/bb62c216cbad2fcec06bfb1cde8b875dbfc237d3)
81
97
82
98
### Internal changes
99
+
83
100
* Added `pytest-cases` to development dependencies.
From this release forward, this project follows the `Git Flow` branching model. To reflect this, the default development branch have been renamed `develop`, and the `main` branch is now only for tagged releases.
88
-
To read more about Git Flow, see (https://nvie.com/posts/a-successful-git-branching-model/). Also see [README](https://github.com/SallingGroup-AI-and-ML/venv-cli/blob/v1.2.0/README.md#git-flow) for branch naming conventions.
105
+
To read more about Git Flow, see [https://nvie.com/posts/a-successful-git-branching-model](https://nvie.com/posts/a-successful-git-branching-model). Also see [README](https://github.com/SallingGroup-AI-and-ML/venv-cli/blob/v1.2.0/README.md#git-flow) for branch naming conventions.
89
106
90
107
* Changed github test workflow to reflect new branch naming conventions.
Copy file name to clipboardExpand all lines: README.md
+44-3Lines changed: 44 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
[](https://github.com/SallingGroup-AI-and-ML/venv-cli/actions/workflows/run_tests.yml)
# venv-cli - A CLI tool to create and manage virtual python environments.
4
+
# venv-cli - A CLI tool to create and manage virtual python environments
5
5
6
6
## Overview
7
+
7
8
`venv-cli` is a CLI tool to help create and manage virtual python environments.
8
9
It is built on `pip` and `python -m venv`, and so only requires packages that are already part of the core python installation; no third-party python packages required. 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.
9
10
@@ -12,40 +13,52 @@ You also don't need `conda`, `pyenv`, `pythonz` etc. to manage your python versi
12
13
## Installation
13
14
14
15
Clone this repository, then run the `install.sh` script:
16
+
15
17
```console
16
18
$ ./install.sh
17
19
```
20
+
18
21
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.
19
22
20
23
The default shell is `bash`. To install for a different shell, specify the shell name, e.g.
24
+
21
25
```console
22
26
$ ./install.sh zsh
23
27
```
24
28
25
29
The installation makes the `venv` command available in your terminal. To check if it works, restart the terminal and run
30
+
26
31
```console
27
32
$ venv --version
28
33
venv-cli 1.0.0
29
34
```
30
35
31
36
# Uninstall
37
+
32
38
To uninstall `venv` and remove all files, run the uninstall script placed at `/usr/local/share/venv/`:
39
+
33
40
```console
34
41
$ bash /usr/local/share/venv/uninstall.sh
35
42
```
43
+
36
44
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.
37
45
38
46
## Usage
39
47
40
48
To see the help menu, along with a list of available commands, run `venv -h/--help`.
41
49
42
50
**In the following sections it is assumed that the working directory is the folder `~/project`.**
51
+
43
52
### Create virtual environment
53
+
44
54
To create a virtual environment, use the command
55
+
45
56
```console
46
57
$ venv create <python-version>
47
58
```
59
+
48
60
e.g.
61
+
49
62
```console
50
63
$ venv create 3.9
51
64
```
@@ -57,28 +70,37 @@ $ venv create 3.9 venv-name
57
70
```
58
71
59
72
If you don't have the specific version of python installed yet, you can get it by running
73
+
60
74
```console
61
75
$ sudo apt install python<version>
62
76
```
77
+
63
78
e.g.
79
+
64
80
```console
65
81
$ sudo apt install python3.10
66
82
```
83
+
67
84
(or in the case of Debian-based distributions, like Ubuntu, `sudo apt install python3.10-venv`. The `-venv` part is necessary to be able to use the system python to create virtual environments.)
68
85
69
86
## Activating and deactivating the virtual environment
87
+
70
88
To activate the virtual environment, place yourself _in the folder containing_ the `.venv` folder, then run
89
+
71
90
```console
72
91
$ venv activate
73
92
```
74
93
75
94
To deactivate it again, run
95
+
76
96
```console
77
97
$ venv deactivate
78
98
```
79
99
80
100
## Install/uninstall packages and requirements
101
+
81
102
To install a single package, simply run
103
+
82
104
```console
83
105
$ venv install <package>
84
106
```
@@ -93,23 +115,31 @@ Unlike `pip install <package>`, which leaves no trace, this ensures that the `re
93
115
In the same spirit, `venv uninstall <package>` first removes the package from `requirements.txt`, then runs `venv install -r requirements.txt` to reinstall the environment from scratch. Unlike `pip uninstall <package>`, this ensures that the uninstall does not leave any "orphaned" packages in the current environment (packages that were installed as secondary dependencies, but are no longer needed since the primary dependency has been uninstalled).
94
116
95
117
### Requirements files
118
+
96
119
To specify a different requirements file to install to/uninstall from, use `-r <requirements>` :
120
+
97
121
```console
98
122
$ venv install numpy 'pandas >= 2.0' -r core.txt
99
123
```
124
+
100
125
This will add `numpy` and `pandas >= 2.0` as requirements in `core.txt`, then install from that file. Similarly,
126
+
101
127
```console
102
128
$ venv uninstall pandas -r core.txt
103
129
```
130
+
104
131
will remove the `pandas >= 2.0` requirement from `core.txt` again, then reinstall the environment using the updated `core.txt`.
105
132
106
133
### Lock files
134
+
107
135
When installing or uninstalling packages, the resulting environment is _locked_ into a corresponding `.lock`-file, e.g. running `venv install -r requirements.txt` will lock the installed packages into `requirements.lock`[^1].
108
136
109
137
This file is useful if a reproducible install is needed, e.g. when deploying a project to a different machine, or when running a colleagues project. Where `requrements.txt` is used to specify the packages and version your project _needs_ (and nothing more), installing from `requirements.lock` makes sure that you get the exact version of every package.
110
138
111
139
### Additional requirements
140
+
112
141
If you have both production and development package requirements, keep them in separate requirements-files, e.g. `requirements.txt` for production requirements and `test.txt` for requirements needed when running tests. An example of these could be:
142
+
113
143
```bash
114
144
# requirements.txt
115
145
numpy
@@ -123,19 +153,23 @@ pytest-cov
123
153
```
124
154
125
155
You can then use either
156
+
126
157
```console
127
158
$ venv install -r requirements.txt
128
159
```
129
160
130
161
To install production requirements only, or
162
+
131
163
```console
132
164
$ venv install -r test.txt
133
165
```
134
166
135
167
to install both production and test requirements. The `-r requirements.txt` in `test.txt` is what makes sure that installing test requirements also installs the requirements from `requirements.txt`.
136
168
137
169
## Clearing the environment
170
+
138
171
If you want to manually clear the environment, you can run
To completely delete the virtual environment and everything in it, run
190
+
155
191
```console
156
192
$ venv delete
157
193
```
158
194
159
195
(this will not delete any requirement or .lock-files). This will ask for confirmation before deleting the virtual environment. To give immediate confirmation, pass the `-y` flag:
196
+
160
197
```console
161
198
$ venv delete -y
162
199
```
163
200
164
201
## Contributing
202
+
165
203
Before creating a pull request, please open an issue first to discuss what you would like to change.
166
204
167
205
To contribute, clone the repo and create a branch, create a virtual environment and install `dev-requirements.txt`. When you are done with your changes, run the test suite with
206
+
168
207
```console
169
208
$ pytest .
170
209
```
210
+
171
211
then create a pull request for the `main` branch.
172
212
173
213
Every (public) subcommand has its own test file `tests/test_venv_<command>.py` Please make sure to add/update tests as appropriate.
174
214
175
215
### Branches
216
+
176
217
When creating a new branch, please prefix them with one of the following:
177
218
178
219
```
@@ -199,5 +240,5 @@ Then commit the changes, push to `main`, and create a new release on GitHub with
199
240
200
241
[MIT](https://choosealicense.com/licenses/mit/)
201
242
202
-
[^1]: A current limitation of using `pip freeze` under the hood is that installing packages from a version control system (VCS) URL that requires authentication, e.g. `private_package @ git+https://USERNAME:PASSWORD@github.com/my-user/private-package`, the authentication is not locked (see https://github.com/pypa/pip/issues/12365).
203
-
These credentials can either be inserted manually into the generated `.lock`-file, or the credentials can instead be stored in a `.netrc` file, which `pip install` will then reference when running `pip install`: https://pip.pypa.io/en/stable/topics/authentication/#netrc-support
243
+
[^1]: A current limitation of using `pip freeze` under the hood is that installing packages from a version control system (VCS) URL that requires authentication, e.g. `private_package @ git+https://USERNAME:PASSWORD@github.com/my-user/private-package`, the authentication is not locked (see [https://github.com/pypa/pip/issues/12365](https://github.com/pypa/pip/issues/12365)).
244
+
These credentials can either be inserted manually into the generated `.lock`-file, or the credentials can instead be stored in a `.netrc` file, which `pip install` will then reference when running `pip install`: [https://pip.pypa.io/en/stable/topics/authentication/#netrc-support](https://pip.pypa.io/en/stable/topics/authentication/#netrc-support)
0 commit comments