Skip to content

Commit 5b1cdce

Browse files
author
Chad Smith
authored
remove existing files in PIPX_BIN_DIR if --force is passed (#206)
* remove existing files in PIPX_BIN_DIR if --force is passed * add force arg for other commands * animation improvements; lint fixes * update docs
1 parent 82514a2 commit 5b1cdce

File tree

12 files changed

+205
-111
lines changed

12 files changed

+205
-111
lines changed

README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ See Contributing for how to update this file.
2121
<a href="https://travis-ci.org/pipxproject/pipx"><img src="https://travis-ci.org/pipxproject/pipx.svg?branch=master" /></a>
2222

2323
<a href="https://pypi.python.org/pypi/pipx/">
24-
<img src="https://img.shields.io/badge/pypi-0.14.0.0rc0-blue.svg" /></a>
24+
<img src="https://img.shields.io/badge/pypi-0.14.0.0rc1-blue.svg" /></a>
2525
<a href="https://github.com/ambv/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
2626
</p>
2727

@@ -38,20 +38,25 @@ python3 -m pip install --user pipx
3838
python3 -m pipx ensurepath
3939
```
4040

41-
For more details, [installation](installation).
41+
Upgrade pipx with `python3 -m pip install -U pipx`.
4242

43-
To add shell completions, see instructions with
43+
Shell completions are available by following the instructions printed with this command:
4444
```
4545
pipx completions
4646
```
4747

48+
For more details, see the [installation instructions](https://pipxproject.github.io/pipx/installation/).
49+
50+
4851
## Overview: What is `pipx`?
4952

50-
pipx is a tool to help you install and run end-user applications written in Python. pipx **is not** a tool for development or publishing of your code. It's kind of like macOS's `brew` (if you are familiar with that), but for Python applications.
53+
pipx is a tool to help you install and run end-user applications written in Python. pipx **is not** a tool for development or publishing of your code -- it's only for consuming already published packages.
54+
55+
If you are familiar macOS's `brew`, it's kind of like that but for Python applications. If you are familiar with JavaScript's [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b), it's kind of like that but also allows you to install packages. If you are familiar with `pip`, it's kind of like that but is only focused on installing packages that have entry points.
5156

52-
Python and PyPI allow developers to distribute code with "console script entry points". These scripts let users call into Python code from the command line, effectively acting like standalone applications.
57+
pipx does not ship with pip, but installing it is often an important part of bootstrapping your system.
5358

54-
`pipx` is a tool to install and run any of the thousands of Python applications available on PyPI in a safe, convenient, and reliable way. **In a way, it turns Python Package Index (PyPI) into a big app store for Python applications.** Not all Python packages have entry points, but many do.
59+
Python and PyPI allow developers to distribute code with "console script entry points". These scripts let users call into Python code from the command line, effectively acting like standalone applications. `pipx` is a tool to install and run any of these thousands of Python applications available on PyPI in a safe, convenient, and reliable way. **In a way, it turns Python Package Index (PyPI) into a big app store for Python applications.** Not all Python packages have entry points, but many do. `pipx` is **not** a tool to install a library and `import` it in your Python code.
5560

5661
`pipx` enables you to:
5762

@@ -61,9 +66,8 @@ Python and PyPI allow developers to distribute code with "console script entry p
6166

6267
Best of all, pipx runs with regular user permissions, never calling `sudo pip install` (you aren't doing that, are you? 😄).
6368

64-
pipx is similar to JavaScript's [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) - which ships with npm, but also allows you to install instead of just run. pipx does not ship with pip but installing it is often an important part of bootstrapping your system.
6569

66-
### Safely installing to isolated environments
70+
### Walkthrough: Installing a Package and its Applications With `pipx`
6771

6872
You can globally install an application by running
6973

@@ -90,6 +94,7 @@ apps are exposed on your $PATH at /home/user/.local/bin
9094
- pycowsay
9195
9296
97+
# Now you can run pycowsay from anywhere
9398
>> pycowsay mooo
9499
____
95100
< mooo >
@@ -102,12 +107,17 @@ apps are exposed on your $PATH at /home/user/.local/bin
102107
||----w |
103108
|| ||
104109
105-
106110
```
107111

108-
### Running in temporary, sandboxed environments
112+
### Walkthrough: Running an Application in a Temporary, Sandboxed Environment
113+
114+
I find this handy when I occasionally run an app and want to use the latest version of it, but don't necessarily need it installed on my computer. You may want to do this when you are initializing a new project and want to set up the right directory structure, when you want to view the help text of an application, or if you simply want to run an app in a one-off case.
109115

110-
pipx makes running the latest version of a program in a temporary environment as easy as
116+
For example, the blog post [How to set up a perfect Python project](https://sourcery.ai/blog/python-best-practices/) uses `pipx run` to kickstart a new project with[cookiecutter](https://github.com/cookiecutter/cookiecutter).
117+
118+
A nice side benefit is that you don't have to remember to upgrade the app it since `pipx run` will automatically run a recent version for you.
119+
120+
Okay, let's see what this looks like in practice!
111121

112122
```
113123
pipx run APP [ARGS...]
@@ -121,9 +131,7 @@ pipx run pycowsay moo
121131

122132
Notice that you **don't need to execute any install commands to run the app**.
123133

124-
Re-running the same app is quick because pipx caches Virtual Environments on a per-app basis. These caches last two days.
125-
126-
I find this handy when I want to quickly see the help text of an application, or when I occasionally run an app but don't necessarily want it hanging around on my system. A nice side benefit is that you don't have to remember to upgrade it since `pipx run` will automatically run a recent version for you.
134+
Re-running the same app is quick because pipx caches Virtual Environments on a per-app basis. The caches only last a few days, and when they expire, pipx will again use the latest version of the package. This way you can be sure you're always running a new version of the package without having to manually upgrade.
127135

128136
You can run .py files directly, too.
129137

@@ -167,4 +175,6 @@ Contributors
167175
- [Paul Moore](https://github.com/pfmoore)
168176
- [tkossak](https://github.com/tkossak)
169177
- [Tzu-ping Chung](https://github.com/uranusjr)
170-
- [Shawn Hensley](https://github.com/sahensley)
178+
- [Shawn Hensley](https://github.com/sahensley)
179+
180+
Logo by [@IrishMorales](https://github.com/IrishMorales).

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- Breaking change: for the `inject` command, change `--include-binaries` to `--include-apps`
55
- Change all terminology from `binary` to `app` or `application`
66
- Improve argument parsing for `pipx run` and `pipx runpip`
7+
- If `--force` is passed, remove existing files in PIPX_BIN_DIR
8+
- Move animation to start of line, hide cursor when animating
79

810
0.13.2.3
911

docs/docs.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ optional arguments:
100100
git+https://github.com/user/repo.git@branch`
101101
--include-deps Include apps of dependent packages
102102
--verbose
103-
--force Install even when the package has already been
104-
installed
103+
--force, -f Modify existing virtual environment and files in
104+
PIPX_BIN_DIR
105105
--python PYTHON The Python executable used to create the Virtual
106106
Environment and run the associated app/apps. Must be
107107
v3.3+.
@@ -169,7 +169,7 @@ optional arguments:
169169

170170
```
171171
pipx upgrade --help
172-
usage: pipx upgrade [-h] [--spec SPEC] [--include-deps]
172+
usage: pipx upgrade [-h] [--spec SPEC] [--force] [--include-deps]
173173
[--system-site-packages] [--index-url INDEX_URL]
174174
[--editable] [--pip-args PIP_ARGS] [--verbose]
175175
package
@@ -186,6 +186,8 @@ optional arguments:
186186
passed to pip. Runs `pip install -U SPEC`. For example
187187
`--spec mypackage==2.0.0` or `--spec
188188
git+https://github.com/user/repo.git@branch`
189+
--force, -f Modify existing virtual environment and files in
190+
PIPX_BIN_DIR
189191
--include-deps Include apps of dependent packages
190192
--system-site-packages
191193
Give the virtual environment access to the system
@@ -207,7 +209,7 @@ pipx upgrade-all --help
207209
usage: pipx upgrade-all [-h] [--include-deps] [--system-site-packages]
208210
[--index-url INDEX_URL] [--editable]
209211
[--pip-args PIP_ARGS] [--skip SKIP [SKIP ...]]
210-
[--verbose]
212+
[--force] [--verbose]
211213
212214
Upgrades all packages within their virtual environments by running 'pip
213215
install --upgrade PACKAGE'
@@ -225,6 +227,8 @@ optional arguments:
225227
install/upgrade commands
226228
--skip SKIP [SKIP ...]
227229
skip these packages
230+
--force, -f Modify existing virtual environment and files in
231+
PIPX_BIN_DIR
228232
--verbose
229233
230234
```
@@ -236,7 +240,7 @@ optional arguments:
236240
pipx inject --help
237241
usage: pipx inject [-h] [--include-apps] [--include-deps]
238242
[--system-site-packages] [--index-url INDEX_URL]
239-
[--editable] [--pip-args PIP_ARGS] [--verbose]
243+
[--editable] [--pip-args PIP_ARGS] [--force] [--verbose]
240244
package dependencies [dependencies ...]
241245
242246
Installs packages to an existing pipx-managed virtual environment.
@@ -258,6 +262,8 @@ optional arguments:
258262
--editable, -e Install a project in editable mode
259263
--pip-args PIP_ARGS Arbitrary pip arguments to pass directly to pip
260264
install/upgrade commands
265+
--force, -f Modify existing virtual environment and files in
266+
PIPX_BIN_DIR
261267
--verbose
262268
263269
```

docs/index.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ See Contributing for how to update this file.
2121
<a href="https://travis-ci.org/pipxproject/pipx"><img src="https://travis-ci.org/pipxproject/pipx.svg?branch=master" /></a>
2222

2323
<a href="https://pypi.python.org/pypi/pipx/">
24-
<img src="https://img.shields.io/badge/pypi-0.14.0.0rc0-blue.svg" /></a>
24+
<img src="https://img.shields.io/badge/pypi-0.14.0.0rc1-blue.svg" /></a>
2525
<a href="https://github.com/ambv/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
2626
</p>
2727

@@ -38,20 +38,25 @@ python3 -m pip install --user pipx
3838
python3 -m pipx ensurepath
3939
```
4040

41-
For more details, [installation](installation).
41+
Upgrade pipx with `python3 -m pip install -U pipx`.
4242

43-
To add shell completions, see instructions with
43+
Shell completions are available by following the instructions printed with this command:
4444
```
4545
pipx completions
4646
```
4747

48+
For more details, see the [installation instructions](https://pipxproject.github.io/pipx/installation/).
49+
50+
4851
## Overview: What is `pipx`?
4952

50-
pipx is a tool to help you install and run end-user applications written in Python. pipx **is not** a tool for development or publishing of your code. It's kind of like macOS's `brew` (if you are familiar with that), but for Python applications.
53+
pipx is a tool to help you install and run end-user applications written in Python. pipx **is not** a tool for development or publishing of your code -- it's only for consuming already published packages.
54+
55+
If you are familiar macOS's `brew`, it's kind of like that but for Python applications. If you are familiar with JavaScript's [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b), it's kind of like that but also allows you to install packages. If you are familiar with `pip`, it's kind of like that but is only focused on installing packages that have entry points.
5156

52-
Python and PyPI allow developers to distribute code with "console script entry points". These scripts let users call into Python code from the command line, effectively acting like standalone applications.
57+
pipx does not ship with pip, but installing it is often an important part of bootstrapping your system.
5358

54-
`pipx` is a tool to install and run any of the thousands of Python applications available on PyPI in a safe, convenient, and reliable way. **In a way, it turns Python Package Index (PyPI) into a big app store for Python applications.** Not all Python packages have entry points, but many do.
59+
Python and PyPI allow developers to distribute code with "console script entry points". These scripts let users call into Python code from the command line, effectively acting like standalone applications. `pipx` is a tool to install and run any of these thousands of Python applications available on PyPI in a safe, convenient, and reliable way. **In a way, it turns Python Package Index (PyPI) into a big app store for Python applications.** Not all Python packages have entry points, but many do. `pipx` is **not** a tool to install a library and `import` it in your Python code.
5560

5661
`pipx` enables you to:
5762

@@ -61,9 +66,8 @@ Python and PyPI allow developers to distribute code with "console script entry p
6166

6267
Best of all, pipx runs with regular user permissions, never calling `sudo pip install` (you aren't doing that, are you? 😄).
6368

64-
pipx is similar to JavaScript's [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) - which ships with npm, but also allows you to install instead of just run. pipx does not ship with pip but installing it is often an important part of bootstrapping your system.
6569

66-
### Safely installing to isolated environments
70+
### Walkthrough: Installing a Package and its Applications With `pipx`
6771

6872
You can globally install an application by running
6973

@@ -90,6 +94,7 @@ apps are exposed on your $PATH at /home/user/.local/bin
9094
- pycowsay
9195
9296
97+
# Now you can run pycowsay from anywhere
9398
>> pycowsay mooo
9499
____
95100
< mooo >
@@ -102,12 +107,17 @@ apps are exposed on your $PATH at /home/user/.local/bin
102107
||----w |
103108
|| ||
104109
105-
106110
```
107111

108-
### Running in temporary, sandboxed environments
112+
### Walkthrough: Running an Application in a Temporary, Sandboxed Environment
113+
114+
I find this handy when I occasionally run an app and want to use the latest version of it, but don't necessarily need it installed on my computer. You may want to do this when you are initializing a new project and want to set up the right directory structure, when you want to view the help text of an application, or if you simply want to run an app in a one-off case.
109115

110-
pipx makes running the latest version of a program in a temporary environment as easy as
116+
For example, the blog post [How to set up a perfect Python project](https://sourcery.ai/blog/python-best-practices/) uses `pipx run` to kickstart a new project with[cookiecutter](https://github.com/cookiecutter/cookiecutter).
117+
118+
A nice side benefit is that you don't have to remember to upgrade the app it since `pipx run` will automatically run a recent version for you.
119+
120+
Okay, let's see what this looks like in practice!
111121

112122
```
113123
pipx run APP [ARGS...]
@@ -121,9 +131,7 @@ pipx run pycowsay moo
121131

122132
Notice that you **don't need to execute any install commands to run the app**.
123133

124-
Re-running the same app is quick because pipx caches Virtual Environments on a per-app basis. These caches last two days.
125-
126-
I find this handy when I want to quickly see the help text of an application, or when I occasionally run an app but don't necessarily want it hanging around on my system. A nice side benefit is that you don't have to remember to upgrade it since `pipx run` will automatically run a recent version for you.
134+
Re-running the same app is quick because pipx caches Virtual Environments on a per-app basis. The caches only last a few days, and when they expire, pipx will again use the latest version of the package. This way you can be sure you're always running a new version of the package without having to manually upgrade.
127135

128136
You can run .py files directly, too.
129137

@@ -167,4 +175,6 @@ Contributors
167175
- [Paul Moore](https://github.com/pfmoore)
168176
- [tkossak](https://github.com/tkossak)
169177
- [Tzu-ping Chung](https://github.com/uranusjr)
170-
- [Shawn Hensley](https://github.com/sahensley)
178+
- [Shawn Hensley](https://github.com/sahensley)
179+
180+
Logo by [@IrishMorales](https://github.com/IrishMorales).

docs/installation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ pipx's default binary location is `~/.local/bin`. This can be overriden with the
2323

2424
pipx's default virtual environment location is `~/.local/pipx`. This can be overridden with the environment variable `PIPX_HOME`.
2525

26+
## Shell Completion
27+
You can easily get your shell's tab completions working by following instructions printed with this command:
28+
```
29+
pipx completions
30+
```
31+
2632
## Install pipx Development Versions
2733
New versions of pipx are published as beta or release candidates. These versions look something like `0.13.0b1`, where `b1` signifies the first beta release of version 0.13. These releases can be tested with
2834
```

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ publish:
1212
pipx run nox -s publish-3.7
1313

1414
docs:
15-
pipx run nox --session docs -s docs-3.7
15+
pipx run nox -s docs-3.7 -r
1616

1717
watch_docs:
18-
pipx run nox -s watch_docs-3.7
18+
pipx run nox -s watch_docs-3.7 -r
1919

2020
publish_docs:
21-
pipx run nox -s publish_docs-3.7
21+
pipx run nox -s publish_docs-3.7 -r

pipx/Venv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ def run_app(self, app: str, app_args: List[str]):
194194
pass
195195

196196
def upgrade_package(self, package_or_url: str, pip_args: List[str]):
197-
self._run_pip(["install"] + pip_args + ["--upgrade", package_or_url])
197+
with animate(f"upgrading package {package_or_url!r}", self.do_animation):
198+
self._run_pip(["install"] + pip_args + ["--upgrade", package_or_url])
198199

199200
def _run_pip(self, cmd):
200201
cmd = [self.python_path, "-m", "pip"] + cmd

0 commit comments

Comments
 (0)