Skip to content

Commit

Permalink
Minor bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Oct 19, 2024
1 parent 1980295 commit 901fff4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ViperIDE",
"version": "0.5.11",
"version": "0.5.12",
"description": "An innovative MicroPython / CircuitPython IDE for Web and Mobile",
"main": "index.js",
"scripts": {
Expand Down
27 changes: 13 additions & 14 deletions src/package_mgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ export async function rawInstallPkg(raw, name, { dev=null, version=null, index=n
}

if ('hashes' in pkg_info) {
for (const [fn, hash, ..._] of pkg_info.hashes) {
for (let [fn, hash, ..._] of pkg_info.hashes) {
const content = await fetchArrayBuffer(rewriteUrl(`${index.url}/file/${hash.slice(0,2)}/${hash}`))
const target_file = `${lib_path}/${fn}`
fn = `${lib_path}/${fn}`

// Ensure path exists
const [dirname, _] = splitPath(target_file)
const [dirname, _] = splitPath(fn)
await raw.makePath(dirname)

await raw.writeFile(target_file, content, 128, true)
await raw.writeFile(fn, content, 128, true)
}
}

Expand All @@ -191,29 +191,28 @@ export async function rawInstallPkg(raw, name, { dev=null, version=null, index=n
url = expandVars(url, vars)
let content = await fetchArrayBuffer(url)

let target_file
if (fn.startsWith('fs:')) {
target_file = fn.slice(3)
target_file = `${fs_path}/${fn}`
fn = fn.slice(3)
fn = `${fs_path}/${fn}`
} else {
if (fn.startsWith('lib:')) { target_file = fn.slice(4) }
target_file = `${lib_path}/${fn}`
if (fn.startsWith('lib:')) { fn = fn.slice(4) }
fn = `${lib_path}/${fn}`

if (!prefer_source && target_file.endsWith('.py')) {
if (!prefer_source && fn.endsWith('.py')) {
try {
content = await compilePython(target_file, content, dev)
target_file = target_file.replace(/\.py$/, '.mpy')
content = await compilePython(fn, content, dev)
fn = fn.replace(/\.py$/, '.mpy')
} catch (_err) {
// Ok, just install the source
}
}
}

// Ensure path exists
const [dirname, _] = splitPath(target_file)
const [dirname, _] = splitPath(fn)
await raw.makePath(dirname)

await raw.writeFile(target_file, content, 128, true)
await raw.writeFile(fn, content, 128, true)
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/python_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ export async function compilePython(filename, content, devInfo) {
const [_, fname] = splitPath(filename)
const wasmUrlV6 = 'https://viper-ide.org/assets/mpy-cross-v6.wasm'
let options = null
if (devInfo && devInfo.mpy_arch) {
options = [ "-march="+devInfo.mpy_arch ]

if (devInfo) {
if (devInfo.mpy_ver != 6) {
throw new Error("Only compiling mpy v6 is supported")
}
if (devInfo.mpy_arch) {
options = [ "-march="+devInfo.mpy_arch ]
}
}
const result = await compile_v6(fname, content, options, wasmUrlV6)
if (result.status !== 0) {
Expand Down

0 comments on commit 901fff4

Please sign in to comment.