Skip to content

Commit

Permalink
Older MicroPython versions support
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Jun 14, 2024
1 parent 00516a3 commit 2bfbf06
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ async function removeFile(path) {
await execRawRepl(`
import os
try:
os.unlink('${path}')
os.remove('${path}')
except OSError as e:
if e.args[0] == 39:
raise Exception('Directory not empty')
Expand Down Expand Up @@ -884,7 +884,7 @@ def w(d):
}

await execCmd(`f.close()
try: os.unlink('${fn}')
try: os.remove('${fn}')
except: pass
os.rename('.viper.tmp','${fn}')
`)
Expand Down Expand Up @@ -1093,11 +1093,12 @@ async function installPkg(index_url, pkg, version='latest', pkg_info=null) {
try {
const sys = JSON.parse(await execRawRepl(`
import sys,json
pj=lambda x:print(json.dumps(x,separators=(',',':')))
mpy=getattr(sys.implementation, '_mpy', 0) & 0xFF
pj({'mpy':mpy,'path':sys.path})
print(json.dumps({'mpy':mpy,'path':sys.path}))
`))

if (!sys.mpy) { sys.mpy = "py" }

// Find `lib` filder in sys.path
const lib_path = sys.path.find(x => x.endsWith('/lib'))
if (!lib_path) {
Expand Down Expand Up @@ -1129,6 +1130,11 @@ pj({'mpy':mpy,'path':sys.path})
const file_rsp = await fetch(rewriteUrl(url))
const content = await file_rsp.arrayBuffer()
const target_file = `${lib_path}/${fn}`

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

await writeFile(target_file, content)
}
}
Expand Down Expand Up @@ -1446,6 +1452,7 @@ for i, char in enumerate(text):
print(reset)
print("=" * 32)
# Count 1 to 10
for i in range(10):
time.sleep(1)
print(i + 1, "", end="")
Expand Down

0 comments on commit 2bfbf06

Please sign in to comment.