diff --git a/lib/prepare.ts b/lib/prepare.ts index 325cbb8..4984271 100644 --- a/lib/prepare.ts +++ b/lib/prepare.ts @@ -60,8 +60,10 @@ async function installPackages(packages: string[], options?: Options) { } async function createVenv(envDir: string, options?: Options): Promise { - await spawn('python3', ['-m', 'venv', envDir], options); const envPath = path.resolve(envDir, 'bin'); + if (!fs.existsSync(envPath)) { + await spawn('python3', ['-m', 'venv', envDir], options); + } if (os.platform() == 'win32') { return { ...options, diff --git a/lib/publish.ts b/lib/publish.ts index 9216ede..fc7cc73 100644 --- a/lib/publish.ts +++ b/lib/publish.ts @@ -1,6 +1,7 @@ import { Options, ResultPromise } from 'execa'; import type { Context } from './@types/semantic-release'; import { DefaultConfig } from './default-options'; +import { createVenv } from './prepare'; import { PluginConfig } from './types'; import { pipe, spawn } from './util.js'; @@ -47,8 +48,20 @@ function publishPackage( async function publish(pluginConfig: PluginConfig, context: Context) { const { logger } = context; - const { srcDir, distDir, pypiPublish, gpgSign, gpgIdentity, repoUrl } = - new DefaultConfig(pluginConfig); + const { + srcDir, + distDir, + pypiPublish, + gpgSign, + gpgIdentity, + repoUrl, + envDir, + } = new DefaultConfig(pluginConfig); + + let options = pipe(context); + if (envDir) { + options = await createVenv(envDir, options); + } if (pypiPublish !== false) { logger.log(`Publishing package to ${repoUrl}`); @@ -58,7 +71,7 @@ async function publish(pluginConfig: PluginConfig, context: Context) { process.env['PYPI_REPO_URL'] ?? repoUrl, gpgSign, gpgIdentity, - pipe(context), + options, ); await result; } else {