🌐 AI搜索 & 代理 主页
Skip to content

Commit efb69ec

Browse files
committed
add small docs
Signed-off-by: Jean-Yves LENHOF <jeanyves.lenhof.partner@decathlon.com>
1 parent 8f93146 commit efb69ec

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

docs/advanced-usage.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [Allow pre-releases](advanced-usage.md#allow-pre-releases)
2525
- [Using the pip-version input](advanced-usage.md#using-the-pip-version-input)
2626
- [Using the pip-install input](advanced-usage.md#using-the-pip-install-input)
27+
- [Managing pip packages with preclean and postclean](advanced-usage.md#managing-pip-packages-with-preclean-and-postclean)
2728

2829
## Using the `python-version` input
2930

@@ -600,11 +601,11 @@ One quick way to grant access is to change the user and group of the non-default
600601
### macOS
601602

602603
The Python packages for macOS that are downloaded from `actions/python-versions` are originally compiled from the source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before the use of `setup-python` on the macOS self-hosted runner:
603-
604+
604605
- Create a directory called `/Users/runner/hostedtoolcache`
605606
- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access
606607

607-
You can check the current user and group that the runner belongs to by typing `ls -l` inside the runner's root directory.
608+
You can check the current user and group that the runner belongs to by typing `ls -l` inside the runner's root directory.
608609
The runner can be granted write access to the `/Users/runner/hostedtoolcache` directory using a few techniques:
609610
- The user starting the runner is the owner, and the owner has write permission
610611
- The user starting the runner is in the owning group, and the owning group has write permission
@@ -692,3 +693,63 @@ The `pip-install` input allows you to install dependencies as part of the Python
692693
For complex workflows, or alternative package managers (e.g., poetry, pipenv), we recommend using separate steps to maintain clarity and flexibility.
693694

694695
> The `pip-install` input mirrors the flexibility of a standard pip install command and supports most of its arguments.
696+
697+
## Managing pip packages with preclean and postclean
698+
699+
The `preclean` and `postclean` inputs provide control over pip package management during the action lifecycle.
700+
701+
### Using the preclean input
702+
703+
The `preclean` input removes all existing pip packages before installing new ones. This is useful when you want to ensure a clean environment without any pre-existing packages that might conflict with your dependencies.
704+
705+
```yaml
706+
steps:
707+
- uses: actions/checkout@v5
708+
- name: Set up Python
709+
uses: actions/setup-python@v6
710+
with:
711+
python-version: '3.13'
712+
pip-install: -r requirements.txt
713+
preclean: true
714+
```
715+
716+
When `preclean` is set to `true`, all pip packages will be removed before any new packages are installed via the `pip-install` input.
717+
718+
### Using the postclean input
719+
720+
The `postclean` input removes all pip packages installed by this action after the action completes. This is useful for cleanup purposes or when you want to ensure that packages installed during setup don't persist beyond the workflow's execution.
721+
722+
```yaml
723+
steps:
724+
- uses: actions/checkout@v5
725+
- name: Set up Python
726+
uses: actions/setup-python@v6
727+
with:
728+
python-version: '3.13'
729+
pip-install: pytest requests
730+
postclean: true
731+
- name: Run tests
732+
run: pytest
733+
```
734+
735+
When `postclean` is set to `true`, packages installed during the setup will be removed after the whole workflow completes successfully.
736+
737+
### Using both preclean and postclean
738+
739+
You can combine both inputs for complete package lifecycle management:
740+
741+
```yaml
742+
steps:
743+
- uses: actions/checkout@v5
744+
- name: Set up Python
745+
uses: actions/setup-python@v6
746+
with:
747+
python-version: '3.13'
748+
pip-install: -r requirements.txt
749+
preclean: true
750+
postclean: true
751+
- name: Run your script
752+
run: python my_script.py
753+
```
754+
755+
> Note: Both `preclean` and `postclean` default to `false`. Set them to `true` only when you need explicit package management control.

0 commit comments

Comments
 (0)