Skip to content

Commit

Permalink
fix(publish): use virtual env
Browse files Browse the repository at this point in the history
  • Loading branch information
abichinger committed Oct 20, 2024
1 parent 2f5e3d3 commit 3e5104c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ async function installPackages(packages: string[], options?: Options) {
}

async function createVenv(envDir: string, options?: Options): Promise<Options> {
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,
Expand Down
19 changes: 16 additions & 3 deletions lib/publish.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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}`);
Expand All @@ -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 {
Expand Down

0 comments on commit 3e5104c

Please sign in to comment.