Skip to content

Commit

Permalink
Issue 9 (#18)
Browse files Browse the repository at this point in the history
* Update readme.md badges and link

* Add Google verification meta tag

* Change to YAML meta in readme

* Fix misspelling

* Do not cache pipx shared directory if it already exists

* Add missing file from last commit
  • Loading branch information
BrandonLWhite authored Feb 14, 2024
1 parent 9fc741c commit 3aed202
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# pipx-install GitHub Action
---
google-site-verification: it_88gzwFHGDUZ8iqy7dofiBHs_3KXOQ6q0FVVJNfuc
---

[![GitHub Super-Linter](https://github.com/actions/hello-world-javascript-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/actions/hello-world-javascript-action/actions/workflows/ci.yml/badge.svg)
# [pipx-install GitHub Action](https://github.com/brandonlwhite/pipx-install-action)

[![GitHub Super-Linter](https://github.com/brandonlwhite/pipx-install-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/brandonlwhite/pipx-install-action/actions/workflows/ci.yml/badge.svg)
![Test Converage](https://raw.githubusercontent.com/BrandonLWhite/pipx-install-action/main/badges/coverage.svg)

This action installs Python tools using [pipx](https://github.com/pypa/pipx).

Expand All @@ -18,7 +23,7 @@ There's also other types of tools that require or prefer a global install, such
[pothepoet](https://github.com/nat-n/poethepoet).

`pipx-install` aims to fill that gap by providing Python developers an easy and familiar way to specify tooling
prequisites needed to perform CI/CD operations on a Python project.
prerequisites needed to perform CI/CD operations on a Python project.

## Basic Usage

Expand Down
20 changes: 20 additions & 0 deletions __tests__/pipx-install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,24 @@ describe('pipx-install', () => {
})
).rejects.toThrow('The "version" field must be specified for package')
})

it('does not cache pipx shared/ if it already exists', async () => {
const statMock = jest
.spyOn(fs, 'stat')
.mockImplementation(async statPath => {
return {}
})

await pipxInstall({
installConfigFile: getPyprojectFile('pyproject.test1.toml'),
cachePackages: true
})
expect(restoreCacheMock).not.toHaveBeenCalledWith(
'PIPX_SHARED_LIBS-FAKE-VALUE'
)
expect(saveCacheMock).not.toHaveBeenCalledWith(
'PIPX_SHARED_LIBS-FAKE-VALUE'
)
expect(statMock).toHaveBeenCalledWith('PIPX_SHARED_LIBS-FAKE-VALUE')
})
})
17 changes: 15 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"package:watch": "npm run package -- --watch",
"test": "(jest && make-coverage-badge --output-path ./badges/coverage.svg) || make-coverage-badge --output-path ./badges/coverage.svg",
"all": "npm run format:write && npm run lint && npm run test && npm run package",
"act-test": "act --workflows __tests__/data/ --container-options \"-v act-toolcache:/opt/hostedtoolcache\""
"act-test": "act --workflows __tests__/data/"
},
"license": "MIT",
"eslintConfig": {
Expand Down
17 changes: 15 additions & 2 deletions src/pipx-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ async function pipxInstall(options) {
const pipxSharedCacheKey = `pipx-install-shared-${hashObject(
systemHashInput
)}`

const pipxSharedPreExists = await checkForPipxSharedPreExists(pipxSharedDir)
const cachePipxShared = cachePackages && !pipxSharedPreExists

const pipxSharedCacheHit =
cachePackages && (await restoreCache([pipxSharedDir], pipxSharedCacheKey))
cachePipxShared && (await restoreCache([pipxSharedDir], pipxSharedCacheKey))

for (const [packageName, packageValue] of Object.entries(installPackages)) {
const packageInfo = getNormalizedPackageInfo(packageName, packageValue)
Expand Down Expand Up @@ -88,7 +92,7 @@ async function pipxInstall(options) {
}
}

if (cachePackages && !pipxSharedCacheHit) {
if (cachePipxShared && !pipxSharedCacheHit) {
await saveCache([pipxSharedDir], pipxSharedCacheKey)
}
}
Expand Down Expand Up @@ -171,3 +175,12 @@ async function installPackage(packageInfo) {
`Package "${packageSpec}" installed with commands [${installedCommands}] using "${pipxMeta.python_version}" ...`
)
}

async function checkForPipxSharedPreExists(pipxSharedDir) {
try {
await fs.stat(pipxSharedDir)
return true
} catch (error) {
return false
}
}

0 comments on commit 3aed202

Please sign in to comment.