Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
add virtual env parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-t authored and syphar committed Aug 9, 2021
1 parent c745341 commit 41b6469
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('get python version', async () => {
})

test('get virtualenv directory', async () => {
expect(await utils.virtualenv_directory()).toContain('.venv')
expect(await utils.virtualenv_directory('venv-custom')).toContain('venv-custom')
})

test('get hash for file glob', async () => {
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ inputs:
**/Pipfile.lock
**/poetry.lock
custom_virtualenv_dir:
required: false
description: "custom directory for the virtual environment"
default: ".venv"

outputs:
cache-hit:
description: "A boolean value to indicate if a cache was restored"
Expand Down
5 changes: 4 additions & 1 deletion src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ async function run(): Promise<void> {
const custom_cache_key = core.getInput('custom_cache_key_element', {
required: true
})
const custom_virtualenv_dir = core.getInput('custom_virtualenv_dir', {
required: true
})

const virtualenv_dir = await utils.virtualenv_directory()
const virtualenv_dir = await utils.virtualenv_directory(custom_virtualenv_dir)
core.saveState('VIRTUALENV_DIRECTORY', virtualenv_dir)
core.setOutput('virtualenv-directory', virtualenv_dir)

Expand Down
6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export async function cache_key(
return `${base}-${hash}`
}

export async function virtualenv_directory(): Promise<string> {
export async function virtualenv_directory(
custom_virtualenv_dir: string
): Promise<string> {
let home = ''
if (process.platform === 'win32') {
home = `${process.env['HOMEDRIVE']}${process.env['HOMEPATH']}`
Expand All @@ -49,7 +51,7 @@ export async function virtualenv_directory(): Promise<string> {
const virtualenv_base = `${home}${path.sep}.virtualenvs`
await io.mkdirP(virtualenv_base)

return `${virtualenv_base}${path.sep}.venv`
return `${virtualenv_base}${path.sep}${custom_virtualenv_dir}`
}

export function logWarning(message: string): void {
Expand Down

0 comments on commit 41b6469

Please sign in to comment.