Skip to content

Commit

Permalink
merge origin-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Aug 30, 2023
2 parents 3fee09b + e4b9d3c commit aeedc6a
Show file tree
Hide file tree
Showing 34 changed files with 289 additions and 122 deletions.
19 changes: 17 additions & 2 deletions packages/cli/src/__tests__/e2e/p1/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { ProjectType, supportedLangs } from "../../../commands";
import { UrlFormat } from "../../../lib";

import { runCli } from "@polywrap/cli-js";
import fs from "fs";
import rimraf from "rimraf";
import pjson from "../../../../package.json";
import path from "path";

const HELP = `Usage: polywrap create|c [options] [command]
Expand All @@ -17,7 +19,7 @@ Commands:
wasm [options] <language> <name> Create a Polywrap wasm wrapper. langs:
assemblyscript, rust, golang, interface
app [options] <language> <name> Create a Polywrap application. langs:
typescript
typescript, python
plugin [options] <language> <name> Create a Polywrap plugin. langs:
typescript, rust, python
template [options] <url> <name> Download template from a URL. formats:
Expand All @@ -27,6 +29,12 @@ Commands:

const VERSION = pjson.version;

export const copyFailedError = (input: string): RegExpMatchArray | null => {
// This regex matches the given command structure and captures the paths
const regex = /"command": "copy (\/[\w\-\.\/@]+) (\/[\w\-\.\/@]+)"/;
return input.match(regex);
}

const urlExamples = (format: UrlFormat): string => {
if (format === UrlFormat.git) {
return "https://github.com/polywrap/logging.git";
Expand Down Expand Up @@ -137,7 +145,7 @@ describe("e2e tests for create command", () => {
it("Should successfully generate project", async () => {
rimraf.sync(`${__dirname}/test`);

const { exitCode: code, stdout: output } = await runCli({
const { exitCode: code, stdout: output, stderr: error } = await runCli({
args: [
"create",
project,
Expand All @@ -156,6 +164,13 @@ describe("e2e tests for create command", () => {
}
});

const match = copyFailedError(error);
const template = path.join(__dirname, "..", "..", "..", "..", "..", "templates", project, lang);
if (match && match.length > 1 && !fs.existsSync(match[1]) && fs.existsSync(template)) {
console.log("Skipping test because new templates can't be copied until the next release");
return;
}

expect(code).toEqual(0);
expect(clearStyle(output)).toContain(
"🔥 You are ready "
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/__tests__/e2e/p1/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,21 @@ describe("e2e tests for deploy command", () => {
expect(sanitizedErr).toContain("Environment variable not found: `NON_LOADED_VAR`");
expect(code).toEqual(1);
});

it("Should deploy an interface successfully", async () => {
const { exitCode: code, stdout: output, stderr: error } = await Commands.deploy({}, {
cwd: getTestCaseDir(5),
cli: polywrapCli,
env: process.env as Record<string, string>
});

const sanitizedOutput = clearStyle(output);
const sanitizedError = clearStyle(error);

expect(code).toEqual(0);
expect(sanitizedError).toBeFalsy();
expect(sanitizedOutput).toContain(
"Successfully executed step 'ipfs_deploy'"
);
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const urlStr = intlMsg.commands_create_options_t_url();

export const supportedLangs = {
wasm: ["assemblyscript", "rust", "golang", "interface"] as const,
app: ["typescript"] as const,
app: ["typescript", "python"] as const,
plugin: ["typescript", "rust", "python"] as const,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: '3'
services:
ganache:
build: ./eth
image: trufflesuite/ganache:latest
command: -d
ports:
- ${ETHEREUM_PORT:-8545}:8545
command: ganache -l 8000000 --networkId 1576478390085 --deterministic --hostname=0.0.0.0
ipfs:
build: ./ipfs
ports:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CodegenOverrides } from "../../../../codegen";
import { PolywrapProject } from "../../../../project";

import fs from "fs";
import path from "path";

export function getCodegenOverrides(): CodegenOverrides {
return {
getSchemaBindConfig: async (project: PolywrapProject) => {
const manifestPath = project.getManifestPath();
const manifestDir = path.dirname(manifestPath);
const pyprojectPath = path.join(manifestDir, "pyproject.toml");

const pyproject = fs.readFileSync(pyprojectPath, "utf8");
const match = pyproject.match(/name = "([A-Za-z0-9-]+)"/);
if (!match || !match[1]) {
return {};
}

const codegenDir = path.join(manifestDir, match[1], "wrap");

return {
codegenDir,
};
},
};
}
7 changes: 5 additions & 2 deletions packages/cli/src/lib/project/AppProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ export class AppProject extends Project<AppManifest> {
public async generateSchemaBindings(
abi: WrapAbi,
generationSubPath?: string,
bindgenUri?: string
bindgenUri?: string,
bindConfig?: Record<string, unknown>
): Promise<BindOutput> {
const bindLanguage = appManifestLanguageToBindLanguage(
await this.getManifestLanguage()
);
const codegenDir =
generationSubPath || (bindConfig?.codegenDir as string | undefined);
const options: BindOptions = {
bindLanguage,
wrapInfo: {
Expand All @@ -127,7 +130,7 @@ export class AppProject extends Project<AppManifest> {
type: bindLanguageToWrapInfoType(bindLanguage),
abi,
},
outputDirAbs: await this.getGenerationDirectory(generationSubPath),
outputDirAbs: await this.getGenerationDirectory(codegenDir),
};
return bindSchema(options, bindgenUri);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/lib/project/manifests/app/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BindLanguage } from "@polywrap/schema-bind";

export const appManifestLanguages = {
"app/typescript": "app/typescript",
"app/python": "app/python",
};

export type AppManifestLanguages = typeof appManifestLanguages;
Expand All @@ -22,6 +23,8 @@ export function appManifestLanguageToBindLanguage(
switch (manifestLanguage) {
case "app/typescript":
return "app-ts";
case "app/python":
return "app-py";
default:
throw Error(
intlMsg.lib_language_unsupportedManifestLanguage({
Expand Down
22 changes: 13 additions & 9 deletions packages/schema/bind/src/bindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,45 @@ export function getGenerateBindingFn(
switch (bindLanguage) {
case "wrap-as":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/wrap-assemblyscript"
"wrapscan.io/polywrap/wrap-assemblyscript-abi-bindgen@1"
);
case "wrap-rs":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/wrap-rust"
"wrapscan.io/polywrap/wrap-rust-abi-bindgen@1"
);
case "wrap-go":
return Golang.Wasm.generateBinding;
case "plugin-ts":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/plugin-typescript"
"wrapscan.io/polywrap/plugin-typescript-abi-bindgen@1"
);
case "plugin-rs":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/plugin-rust"
"wrapscan.io/polywrap/plugin-rust-abi-bindgen@1"
);
case "plugin-py":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/plugin-python"
"wrapscan.io/polywrap/plugin-python-abi-bindgen@1"
);
case "plugin-kt":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/plugin-kotlin"
"wrapscan.io/polywrap/plugin-kotlin-abi-bindgen@1"
);
case "plugin-swift":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/plugin-swift"
"wrapscan.io/polywrap/plugin-swift-abi-bindgen@1"
);
case "app-ts":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/nk/ts-app-codegen/implementations/app-typescript"
"wrapscan.io/polywrap/app-typescript-abi-bindgen@1"
);
case "app-py":
return WrapBindgen.getGenerateBindingFn(
"wrapscan.io/polywrap/app-python-abi-bindgen@1"
);
case "app-swift":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/nk/ts-app-codegen/implementations/app-swift"
"wrapscan.io/polywrap/app-swift-abi-bindgen@1"
);
default:
throw Error(`Error: Language binding unsupported - ${bindLanguage}`);
Expand Down
1 change: 1 addition & 0 deletions packages/schema/bind/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const bindLanguage = {
"plugin-kt": "plugin-kt",
"plugin-swift": "plugin-swift",
"app-ts": "app-ts",
"app-py": "app-py",
"app-swift": "app-swift",
};

Expand Down
23 changes: 23 additions & 0 deletions packages/templates/app/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
1 change: 1 addition & 0 deletions packages/templates/app/python/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.15.0
19 changes: 19 additions & 0 deletions packages/templates/app/python/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "templates-app-python",
"description": "Polywrap App Python Template",
"private": true,
"version": "0.11.1",
"scripts": {
"build": "npx polywrap codegen",
"test": "poetry run python -m sample"
},
"dependencies": {
"@polywrap/client-js": "~0.12.0"
},
"devDependencies": {
"@types/node": "18.15.0",
"polywrap": "0.11.2",
"ts-node": "10.9.1",
"typescript": "4.9.5"
}
}
1 change: 1 addition & 0 deletions packages/templates/app/python/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import * into EthersUtils from "wrapscan.io/polywrap/ethers-utils@1"
6 changes: 6 additions & 0 deletions packages/templates/app/python/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
format: 0.4.0
project:
name: Sample
type: app/python
source:
schema: ./polywrap.graphql
13 changes: 13 additions & 0 deletions packages/templates/app/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "sample"
version = "0.1.0"
description = "Polywrap Python SDK"
authors = ["Cesar <[email protected]>", "Niraj <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.10"
polywrap = "^0.1.0b7"
5 changes: 5 additions & 0 deletions packages/templates/app/python/sample/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .wrap import EthersUtils

__all__ = [
"EthersUtils",
]
14 changes: 14 additions & 0 deletions packages/templates/app/python/sample/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .wrap import EthersUtils


if __name__ == "__main__":
eth = EthersUtils()

print("Invoking: EthersUtils.encodeParams(...)")

result = eth.encode_params({
"types": ["address", "uint256"],
"values": ["0xB1B7586656116D546033e3bAFF69BFcD6592225E", "500"]
})

print(f"EthersUtils.encodeParams:\n{result}")
2 changes: 1 addition & 1 deletion packages/templates/app/typescript/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v17.9.1
v18.15.0
4 changes: 4 additions & 0 deletions packages/templates/plugin/python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "templates-plugin-python",
"private": true,
"version": "0.11.2",
"scripts": {
"build": "npx polywrap codegen",
"test": "poetry run pytest"
},
"dependencies": {
"polywrap": "0.11.2"
}
Expand Down
11 changes: 5 additions & 6 deletions packages/templates/plugin/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ include = [
]

[dependencies]
polywrap_core = { version = "~0.1.6-beta.1" }
polywrap_plugin = { version = "~0.1.6-beta.1" }
polywrap_msgpack = { version = "~0.1.6-beta.1" }
polywrap_msgpack_serde = { version = "~0.0.2-beta.5" }
wrap_manifest_schemas = { version = "~0.1.6-beta.1" }
polywrap_core = { version = "~0.1.8" }
polywrap_plugin = { version = "~0.1.8" }
polywrap_msgpack_serde = { version = "~0.0.2-beta.7" }
wrap_manifest_schemas = { version = "~0.1.8" }
serde = {version = "1.0.145", features = ["derive"]}

[dev-dependencies]
polywrap_client = { version = "~0.1.6-beta.1" }
polywrap_client = { version = "~0.1.8" }
9 changes: 5 additions & 4 deletions packages/templates/plugin/rust/tests/e2e.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use template_plugin_rs::SamplePlugin;
use template_plugin_rs::wrap::module::ArgsSampleMethod;
use polywrap_core::{
client::ClientConfig,
uri::Uri,
};
use polywrap_msgpack::{msgpack};
use polywrap_plugin::{package::PluginPackage};
use polywrap_client::{
client::PolywrapClient,
builder::{PolywrapClientConfig, PolywrapClientConfigBuilder},
};
use polywrap_msgpack_serde::to_vec;
use std::{
sync::{Arc, Mutex},
};
Expand All @@ -32,9 +33,9 @@ fn sample_method() {
.invoke::<String>(
&Uri::try_from("plugin/sample").unwrap(),
"sampleMethod",
Some(&msgpack!({
"data": "input data",
})),
Some(&to_vec(&ArgsSampleMethod {
data: "input data".to_string(),
}).unwrap()),
None,
None,
)
Expand Down
Loading

0 comments on commit aeedc6a

Please sign in to comment.