mirror of
				https://gitea.com/actions/setup-python.git
				synced 2025-10-31 11:48:56 +08:00 
			
		
		
		
	Implementation of python's caching (#266)
This commit is contained in:
		
							
								
								
									
										72
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								README.md
									
									
									
									
									
								
							| @@ -9,6 +9,7 @@ This action sets up a Python environment for use in actions by: | ||||
| - optionally installing and adding to PATH a version of Python that is already installed in the tools cache. | ||||
| - downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the tools cache. | ||||
| - failing if a specific version of Python is not preinstalled or available for download. | ||||
| - optionally caching dependencies for pip and pipenv. | ||||
| - registering problem matchers for error output. | ||||
|  | ||||
| # What's new | ||||
| @@ -18,6 +19,7 @@ This action sets up a Python environment for use in actions by: | ||||
| - Automatic setup and download of Python packages if using a self-hosted runner. | ||||
| - Support for pre-release versions of Python. | ||||
| - Support for installing any version of PyPy on-flight | ||||
| - Support for built-in caching of pip and pipenv dependencies | ||||
|  | ||||
| # Usage | ||||
|  | ||||
| @@ -205,6 +207,76 @@ pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy | ||||
| pypy-3.7-nightly # Python 3.7 and nightly PyPy | ||||
| ``` | ||||
|  | ||||
| # Caching packages dependencies | ||||
|  | ||||
| The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip` and `pipenv`. The `cache` input is optional, and caching is turned off by default. | ||||
|  | ||||
| The action defaults to searching for a dependency file (`requirements.txt` for pip or `Pipfile.lock` for pipenv) in the repository, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases where multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used. | ||||
|  | ||||
|  - For pip, the action will cache global cache directory | ||||
|  - For pipenv, the action will cache virtualenv directory | ||||
|  | ||||
| **Please Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time. | ||||
|  | ||||
| The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary. | ||||
|  | ||||
| **Caching pip dependencies:**   | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
| - uses: actions/checkout@v2 | ||||
| - uses: actions/setup-python@v2 | ||||
|   with: | ||||
|     python-version: '3.9' | ||||
|     cache: 'pip' | ||||
| - run: pip install -r requirements.txt | ||||
| - run: pip test | ||||
| ``` | ||||
|  | ||||
| **Caching pipenv dependencies:** | ||||
| ```yaml | ||||
| steps: | ||||
| - uses: actions/checkout@v2 | ||||
| - name: Install pipenv | ||||
|   run: pipx install pipenv | ||||
| - uses: actions/setup-python@v2 | ||||
|   with: | ||||
|     python-version: '3.9' | ||||
|     cache: 'pipenv' | ||||
| - run: pipenv install | ||||
| - run: pipenv test | ||||
| ``` | ||||
|  | ||||
| **Using wildcard patterns to cache dependencies** | ||||
| ```yaml | ||||
| steps: | ||||
| - uses: actions/checkout@v2 | ||||
| - uses: actions/setup-python@v2 | ||||
|   with: | ||||
|     python-version: '3.9' | ||||
|     cache: 'pip' | ||||
|     cache-dependency-path: '**/requirements-dev.txt' | ||||
| - run: pip install -r subdirectory/requirements-dev.txt | ||||
| - run: pip test | ||||
| ``` | ||||
|  | ||||
| **Using a list of file paths to cache dependencies** | ||||
| ```yaml | ||||
| steps: | ||||
| - uses: actions/checkout@v2 | ||||
| - name: Install pipenv | ||||
|   run: pipx install pipenv | ||||
| - uses: actions/setup-python@v2 | ||||
|   with: | ||||
|     python-version: '3.9' | ||||
|     cache: 'pipenv' | ||||
|     cache-dependency-path: | | ||||
|       server/app/Pipfile.lock | ||||
|       __test__/app/Pipfile.lock | ||||
| - run: pipenv install | ||||
| - run: pipenv test | ||||
| ``` | ||||
|  | ||||
| # Using `setup-python` with a self hosted runner | ||||
|  | ||||
| Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` will not work. If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Dmitry Shibanov
					Dmitry Shibanov