Skip to content

Commit

Permalink
Merge pull request #81 from multiversx/mxpy-v8
Browse files Browse the repository at this point in the history
Fix compatibility with mxpy v8
  • Loading branch information
andreibancioiu committed Sep 18, 2023
2 parents b850f6f + 5708268 commit c8cde21
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 90 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-elrond-ide",
"displayName": "MultiversX IDE",
"description": "MultiversX IDE for developing Smart Contracts",
"version": "0.18.0",
"version": "0.19.0",
"publisher": "Elrond",
"repository": {
"type": "git",
Expand Down Expand Up @@ -90,18 +90,18 @@
"category": "multiversx"
},
{
"command": "multiversx.runFreshTestnet",
"title": "Start Fresh Testnet",
"command": "multiversx.runFreshLocalnet",
"title": "Start Fresh Localnet",
"category": "multiversx"
},
{
"command": "multiversx.resumeExistingTestnet",
"title": "Resume Testnet",
"command": "multiversx.resumeExistingLocalnet",
"title": "Resume Localnet",
"category": "multiversx"
},
{
"command": "multiversx.stopTestnet",
"title": "Stop Testnet",
"command": "multiversx.stopLocalnet",
"title": "Stop Localnet",
"category": "multiversx"
}
],
Expand Down Expand Up @@ -138,19 +138,19 @@
"group": "multiversx"
},
{
"command": "multiversx.runFreshTestnet",
"when": "resourceFilename == testnet.toml",
"group": "multiversx Testnet"
"command": "multiversx.runFreshLocalnet",
"when": "resourceFilename == localnet.toml",
"group": "multiversx Localnet"
},
{
"command": "multiversx.resumeExistingTestnet",
"when": "resourceFilename == testnet.toml",
"group": "multiversx Testnet"
"command": "multiversx.resumeExistingLocalnet",
"when": "resourceFilename == localnet.toml",
"group": "multiversx Localnet"
},
{
"command": "multiversx.stopTestnet",
"when": "resourceFilename == testnet.toml",
"group": "multiversx Testnet"
"command": "multiversx.stopLocalnet",
"when": "resourceFilename == localnet.toml",
"group": "multiversx Localnet"
}
],
"commandPalette": [
Expand Down Expand Up @@ -183,15 +183,15 @@
"when": "false"
},
{
"command": "multiversx.runFreshTestnet",
"command": "multiversx.runFreshLocalnet",
"when": "false"
},
{
"command": "multiversx.resumeExistingTestnet",
"command": "multiversx.resumeExistingLocalnet",
"when": "false"
},
{
"command": "multiversx.stopTestnet",
"command": "multiversx.stopLocalnet",
"when": "false"
}
],
Expand Down
18 changes: 9 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("multiversx.gotoContract", gotoContract);
vscode.commands.registerCommand("multiversx.buildContract", buildContract);
vscode.commands.registerCommand("multiversx.runScenarios", runScenarios);
vscode.commands.registerCommand("multiversx.runFreshTestnet", runFreshTestnet);
vscode.commands.registerCommand("multiversx.resumeExistingTestnet", resumeExistingTestnet);
vscode.commands.registerCommand("multiversx.stopTestnet", stopTestnet);
vscode.commands.registerCommand("multiversx.runFreshLocalnet", runFreshLocalnet);
vscode.commands.registerCommand("multiversx.resumeExistingLocalnet", resumeExistingLocalnet);
vscode.commands.registerCommand("multiversx.stopLocalnet", stopLocalnet);

vscode.commands.registerCommand("multiversx.cleanContract", cleanContract);
vscode.commands.registerCommand("multiversx.refreshTemplates", async () => await refreshViewModel(templatesViewModel));
Expand Down Expand Up @@ -154,25 +154,25 @@ async function runScenarios(item: any) {
}
}

async function runFreshTestnet(testnetToml: Uri) {
async function runFreshLocalnet(localnetToml: Uri) {
try {
await sdk.runFreshTestnet(testnetToml);
await sdk.runFreshLocalnet(localnetToml);
} catch (error) {
errors.caughtTopLevel(error);
}
}

async function resumeExistingTestnet(testnetToml: Uri) {
async function resumeExistingLocalnet(localnetToml: Uri) {
try {
await sdk.resumeExistingTestnet(testnetToml);
await sdk.resumeExistingLocalnet(localnetToml);
} catch (error) {
errors.caughtTopLevel(error);
}
}

async function stopTestnet(testnetToml: Uri) {
async function stopLocalnet(localnetToml: Uri) {
try {
await sdk.stopTestnet(testnetToml);
await sdk.stopLocalnet(localnetToml);
} catch (error) {
errors.caughtTopLevel(error);
}
Expand Down
69 changes: 26 additions & 43 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import { FreeTextVersion, Version } from './version';
import path = require("path");
import fs = require('fs');

const Mxpy = "mxpy";
const DefaultMxpyVersion = Version.parse("5.3.2");
const DefaultMxpyVersion = Version.parse("8.1.1");
const LatestMxpyReleaseUrl = "https://api.github.com/repos/multiversx/mx-sdk-py-cli/releases/latest";

export function getPath() {
return MySettings.getSdkPath();
}

function getMxpyPath() {
return path.join(getPath(), "mxpy");
}

function getPrettyPrinterPath() {
return path.join(getPath(), "multiversx_sc_lldb_pretty_printers.py");
}
Expand Down Expand Up @@ -63,7 +66,7 @@ async function ensureMxpy() {
}

async function isMxpyInstalled(exactVersion?: Version): Promise<boolean> {
let [cliVersionString, ok] = await getOneLineStdout(Mxpy, ["--version"]);
let [cliVersionString, ok] = await getOneLineStdout(getMxpyPath(), ["--version"]);
if (!cliVersionString || !ok) {
return false;
}
Expand Down Expand Up @@ -97,10 +100,7 @@ export async function reinstallMxpy(version: Version) {
const mxpyUpUrl = getMxpyUpUrl(version);
await downloadFile(mxpyUp, mxpyUpUrl);

const isV6OrNewer = version.isNewerOrSameAs(Version.parse("6.0.0-alpha.0"));
const mxpyUpCommand = isV6OrNewer ?
`python3 "${mxpyUp}" --exact-version=${version.value} --not-interactive` :
`python3 "${mxpyUp}" --no-modify-path --exact-version=${version}`;
const mxpyUpCommand = `python3 "${mxpyUp}" --exact-version=${version.value} --not-interactive`;

await runInTerminal("installer", mxpyUpCommand);

Expand All @@ -118,25 +118,10 @@ function getMxpyUpUrl(version: Version) {
return `https://raw.githubusercontent.com/multiversx/mx-sdk-py-cli/${version.vValue}/mxpy-up.py`;
}

export async function fetchTemplates(cacheFile: string) {
try {
await ProcessFacade.execute({
program: Mxpy,
args: ["contract", "templates"],
doNotDumpStdout: true,
stdoutToFile: cacheFile
});

Feedback.debug(`Templates fetched, saved to ${cacheFile}.`);
} catch (error: any) {
throw new errors.MyError({ Message: "Could not fetch templates", Inner: error });
}
}

export async function newFromTemplate(folder: string, template: string, name: string) {
try {
await ProcessFacade.execute({
program: Mxpy,
program: getMxpyPath(),
args: ["contract", "new", "--directory", folder, "--template", template, name],
});

Expand Down Expand Up @@ -212,7 +197,7 @@ async function ensureInstalledMxpyGroup(group: string) {
}

async function isMxpyGroupInstalled(group: string): Promise<boolean> {
let [_, ok] = await getOneLineStdout(Mxpy, ["deps", "check", group]);
let [_, ok] = await getOneLineStdout(getMxpyPath(), ["deps", "check", group]);
return ok;
}

Expand All @@ -233,7 +218,7 @@ export async function reinstallModule(): Promise<void> {
async function reinstallMxpyGroup(group: string, version: FreeTextVersion) {
Feedback.info(`Installation of ${group} has been started. Please wait for installation to finish.`);
let tagArgument = version.isSpecified() ? `--tag=${version}` : "";
await runInTerminal("installer", `${Mxpy} --verbose deps install ${group} --overwrite ${tagArgument}`);
await runInTerminal("installer", `${getMxpyPath()} --verbose deps install ${group} --overwrite ${tagArgument}`);

do {
Feedback.debug("Waiting for the installer to finish.");
Expand All @@ -245,15 +230,15 @@ async function reinstallMxpyGroup(group: string, version: FreeTextVersion) {

export async function buildContract(folder: string) {
try {
await runInTerminal("build", `${Mxpy} --verbose contract build "${folder}"`);
await runInTerminal("build", `${getMxpyPath()} contract build --path "${folder}"`);
} catch (error: any) {
throw new errors.MyError({ Message: "Could not build Smart Contract", Inner: error });
}
}

export async function cleanContract(folder: string) {
try {
await runInTerminal("build", `${Mxpy} --verbose contract clean "${folder}"`);
await runInTerminal("build", `${getMxpyPath()} --verbose contract clean --path "${folder}"`);
} catch (error: any) {
throw new errors.MyError({ Message: "Could not clean Smart Contract", Inner: error });
}
Expand All @@ -268,37 +253,35 @@ export async function runScenarios(folder: string) {
}
}

export async function runFreshTestnet(testnetToml: Uri) {
export async function runFreshLocalnet(localnetToml: Uri) {
try {
let folder = path.dirname(testnetToml.fsPath);
let folder = path.dirname(localnetToml.fsPath);

await ensureInstalledMxpyGroup("golang");
await destroyTerminal("testnet");
await runInTerminal("testnet", `${Mxpy} testnet clean`, null, folder);
await runInTerminal("testnet", `${Mxpy} testnet prerequisites`);
await runInTerminal("testnet", `${Mxpy} testnet config`);
await runInTerminal("testnet", `${Mxpy} testnet start`);
await destroyTerminal("localnet");
await runInTerminal("localnet", `${getMxpyPath()} localnet setup`, null, folder);
await runInTerminal("localnet", `${getMxpyPath()} localnet start`);
} catch (error: any) {
throw new errors.MyError({ Message: "Could not start testnet.", Inner: error });
throw new errors.MyError({ Message: "Could not start localnet.", Inner: error });
}
}

export async function resumeExistingTestnet(testnetToml: Uri) {
export async function resumeExistingLocalnet(localnetToml: Uri) {
try {
let folder = path.dirname(testnetToml.fsPath);
let folder = path.dirname(localnetToml.fsPath);

await destroyTerminal("testnet");
await runInTerminal("testnet", `${Mxpy} testnet start`, null, folder);
await destroyTerminal("localnet");
await runInTerminal("localnet", `${getMxpyPath()} localnet start`, null, folder);
} catch (error: any) {
throw new errors.MyError({ Message: "Could not start testnet.", Inner: error });
throw new errors.MyError({ Message: "Could not start localnet.", Inner: error });
}
}

export async function stopTestnet(_testnetToml: Uri) {
export async function stopLocalnet(_localnetToml: Uri) {
try {
await killRunningInTerminal("testnet");
await killRunningInTerminal("localnet");
} catch (error: any) {
throw new errors.MyError({ Message: "Could not start testnet.", Inner: error });
throw new errors.MyError({ Message: "Could not start localnet.", Inner: error });
}
}

Expand Down
Loading

0 comments on commit c8cde21

Please sign in to comment.