Skip to content

Commit

Permalink
Add Python example using 'pip cache dir' to get cache location (#285)
Browse files Browse the repository at this point in the history
* Fix existing example

* Add Python example using 'pip cache dir' to get cache location

* Let users decide how they install pip 20.1+
  • Loading branch information
Hugo van Kemenade authored and GitHub committed Apr 29, 2020
1 parent 9f07ee1 commit ccf9619
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [Python - pip](#python---pip)
- [Simple example](#simple-example)
- [Multiple OS's in a workflow](#multiple-oss-in-a-workflow)
- [Using pip to get cache location](#using-pip-to-get-cache-location)
- [Using a script to get cache location](#using-a-script-to-get-cache-location)
- [R - renv](#r---renv)
- [Simple example](#simple-example-1)
Expand Down Expand Up @@ -290,14 +291,32 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
${{ runner.os }}-pip-
```

### Using pip to get cache location

> Note: This requires pip 20.1+
```yaml
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v1
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
```

### Using a script to get cache location

> Note: This uses an internal pip API and may not always work
```yaml
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- name: Get pip cache dir
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- uses: actions/cache@v1
with:
Expand Down

0 comments on commit ccf9619

Please sign in to comment.