Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V dmshib/pip cache python version #9

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions .github/workflows/e2e-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,24 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', 'pypy-3.7-v7.3.5', 'pypy-3.7-v7.x']
# exclude:
# - os: windows-latest
# python-version: 'pypy-3.7-v7.3.5'
# - os: windows-latest
# python-version: 'pypy-3.7-v7.x'
steps:
- uses: actions/checkout@v2
- name: Install pipenv
run: pipx install pipenv
- name: Setup Python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'pipenv'
- name: Install pipenv
run: pipx install pipenv
- name: Install dependencies
run: pipenv install flake8
run: |
pipenv install numpy
cat Pipfile.lock

python-pip-dependencies-caching-path:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
Expand Down Expand Up @@ -79,15 +86,22 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', 'pypy-3.7-v7.3.5', 'pypy-3.7-v7.x']
# exclude:
# - os: windows-latest
# python-version: 'pypy-3.7-v7.3.5'
# - os: windows-latest
# python-version: 'pypy-3.7-v7.x'
steps:
- uses: actions/checkout@v2
- name: Install pipenv
run: pipx install pipenv
- name: Setup Python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'pipenv'
cache-dependency-path: '**/requirements-linux.txt'
- name: Install pipenv
run: pipx install pipenv
- name: Install dependencies
run: pipenv install flake8
run: |
pipenv install numpy
cat Pipfile.lock
6 changes: 1 addition & 5 deletions __tests__/cache-restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@ describe('restore-cache', () => {
dependencyFile
);
await cacheDistributor.restoreCache();
let pythonKey = '';
if (packageManager === 'pipenv') {
pythonKey = `python-${pythonVersion}-`;
}

expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${pythonKey}${packageManager}-${fileHash}`
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
);
}
);
Expand Down
9 changes: 5 additions & 4 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34467,8 +34467,9 @@ const path = __importStar(__webpack_require__(622));
const os_1 = __importDefault(__webpack_require__(87));
const cache_distributor_1 = __importDefault(__webpack_require__(435));
class PipCache extends cache_distributor_1.default {
constructor(cacheDependencyPath = '**/requirements.txt') {
constructor(pythonVersion, cacheDependencyPath = '**/requirements.txt') {
super('pip', cacheDependencyPath);
this.pythonVersion = pythonVersion;
}
getCacheGlobalDirectories() {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -34487,8 +34488,8 @@ class PipCache extends cache_distributor_1.default {
computeKeys() {
return __awaiter(this, void 0, void 0, function* () {
const hash = yield glob.hashFiles(this.cacheDependencyPath);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}-${hash}`;
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}`;
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
return {
primaryKey,
restoreKey: [restoreKey]
Expand Down Expand Up @@ -43888,7 +43889,7 @@ var PackageManagers;
function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath) {
switch (packageManager) {
case PackageManagers.Pip:
return new pip_cache_1.default(cacheDependencyPath);
return new pip_cache_1.default(pythonVersion, cacheDependencyPath);
case PackageManagers.Pipenv:
return new pipenv_cache_1.default(pythonVersion, cacheDependencyPath);
default:
Expand Down
2 changes: 1 addition & 1 deletion src/cache-distributions/cache-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getCacheDistributor(
) {
switch (packageManager) {
case PackageManagers.Pip:
return new PipCache(cacheDependencyPath);
return new PipCache(pythonVersion, cacheDependencyPath);
case PackageManagers.Pipenv:
return new PipenvCache(pythonVersion, cacheDependencyPath);
default:
Expand Down
9 changes: 6 additions & 3 deletions src/cache-distributions/pip-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import os from 'os';
import CacheDistributor from './cache-distributor';

class PipCache extends CacheDistributor {
constructor(cacheDependencyPath: string = '**/requirements.txt') {
constructor(
private pythonVersion: string,
cacheDependencyPath: string = '**/requirements.txt'
) {
super('pip', cacheDependencyPath);
}

Expand Down Expand Up @@ -36,8 +39,8 @@ class PipCache extends CacheDistributor {

protected async computeKeys() {
const hash = await glob.hashFiles(this.cacheDependencyPath);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}-${hash}`;
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}`;
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;

return {
primaryKey,
Expand Down