Skip to content

Commit 116402a

Browse files
committed
Add frozen stubs for v1.26.1
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
1 parent defb1d9 commit 116402a

File tree

2,500 files changed

+217725
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,500 files changed

+217725
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys, os, alif
2+
3+
4+
bdev = alif.Flash()
5+
if hasattr(alif, "usb_msc"):
6+
try:
7+
# This may fail on VfsFat construction, or mount.
8+
os.mount(os.VfsFat(bdev), "/flash")
9+
except:
10+
os.VfsFat.mkfs(bdev)
11+
os.mount(os.VfsFat(bdev), "/flash")
12+
else:
13+
try:
14+
os.mount(os.VfsLfs2(bdev, progsize=256), "/flash")
15+
except:
16+
os.VfsLfs2.mkfs(bdev, progsize=256)
17+
os.mount(os.VfsLfs2(bdev, progsize=256), "/flash")
18+
19+
sys.path.append("/flash")
20+
sys.path.append("/flash/lib")
21+
os.chdir("/flash")
22+
23+
del sys, os, alif, bdev
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from _typeshed import Incomplete
2+
3+
bdev: Incomplete
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# DHT11/DHT22 driver for MicroPython on ESP8266
2+
# MIT license; Copyright (c) 2016 Damien P. George
3+
4+
import sys
5+
import machine
6+
7+
if hasattr(machine, "dht_readinto"):
8+
from machine import dht_readinto
9+
elif sys.platform.startswith("esp"):
10+
from esp import dht_readinto
11+
elif sys.platform == "pyboard":
12+
from pyb import dht_readinto
13+
else:
14+
dht_readinto = __import__(sys.platform).dht_readinto
15+
16+
del machine
17+
18+
19+
class DHTBase:
20+
def __init__(self, pin):
21+
self.pin = pin
22+
self.buf = bytearray(5)
23+
24+
def measure(self):
25+
buf = self.buf
26+
dht_readinto(self.pin, buf)
27+
if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF != buf[4]:
28+
raise Exception("checksum error")
29+
30+
31+
class DHT11(DHTBase):
32+
def humidity(self):
33+
return self.buf[0]
34+
35+
def temperature(self):
36+
return self.buf[2]
37+
38+
39+
class DHT22(DHTBase):
40+
def humidity(self):
41+
return (self.buf[0] << 8 | self.buf[1]) * 0.1
42+
43+
def temperature(self):
44+
t = ((self.buf[2] & 0x7F) << 8 | self.buf[3]) * 0.1
45+
if self.buf[2] & 0x80:
46+
t = -t
47+
return t
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from _typeshed import Incomplete
2+
3+
class DHTBase:
4+
pin: Incomplete
5+
buf: Incomplete
6+
def __init__(self, pin) -> None: ...
7+
def measure(self) -> None: ...
8+
9+
class DHT11(DHTBase):
10+
def humidity(self): ...
11+
def temperature(self): ...
12+
13+
class DHT22(DHTBase):
14+
def humidity(self): ...
15+
def temperature(self): ...
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# MicroPython package installer
2+
# MIT license; Copyright (c) 2022 Jim Mussared
3+
4+
from micropython import const
5+
import requests
6+
import sys
7+
8+
9+
_PACKAGE_INDEX = "https://micropython.org/pi/v2"
10+
_CHUNK_SIZE = 128
11+
12+
allowed_mip_url_prefixes = ("http://", "https://", "github:", "gitlab:")
13+
14+
15+
# This implements os.makedirs(os.dirname(path))
16+
def _ensure_path_exists(path):
17+
import os
18+
19+
split = path.split("/")
20+
21+
# Handle paths starting with "/".
22+
if not split[0]:
23+
split.pop(0)
24+
split[0] = "/" + split[0]
25+
26+
prefix = ""
27+
for i in range(len(split) - 1):
28+
prefix += split[i]
29+
try:
30+
os.stat(prefix)
31+
except:
32+
os.mkdir(prefix)
33+
prefix += "/"
34+
35+
36+
# Copy from src (stream) to dest (function-taking-bytes)
37+
def _chunk(src, dest):
38+
buf = memoryview(bytearray(_CHUNK_SIZE))
39+
while True:
40+
n = src.readinto(buf)
41+
if n == 0:
42+
break
43+
dest(buf if n == _CHUNK_SIZE else buf[:n])
44+
45+
46+
# Check if the specified path exists and matches the hash.
47+
def _check_exists(path, short_hash):
48+
pass
49+
50+
try:
51+
import binascii
52+
import hashlib
53+
54+
with open(path, "rb") as f:
55+
hs256 = hashlib.sha256()
56+
_chunk(f, hs256.update)
57+
existing_hash = str(binascii.hexlify(hs256.digest())[: len(short_hash)], "utf-8")
58+
return existing_hash == short_hash
59+
except:
60+
return False
61+
62+
63+
def _rewrite_url(url, branch=None):
64+
if not branch:
65+
branch = "HEAD"
66+
if url.startswith("github:"):
67+
url = url[7:].split("/")
68+
url = (
69+
"https://raw.githubusercontent.com/"
70+
+ url[0]
71+
+ "/"
72+
+ url[1]
73+
+ "/"
74+
+ branch
75+
+ "/"
76+
+ "/".join(url[2:])
77+
)
78+
elif url.startswith("gitlab:"):
79+
url = url[7:].split("/")
80+
url = (
81+
"https://gitlab.com/"
82+
+ url[0]
83+
+ "/"
84+
+ url[1]
85+
+ "/-/raw/"
86+
+ branch
87+
+ "/"
88+
+ "/".join(url[2:])
89+
)
90+
return url
91+
92+
93+
def _download_file(url, dest):
94+
response = requests.get(url)
95+
try:
96+
if response.status_code != 200:
97+
print("Error", response.status_code, "requesting", url)
98+
return False
99+
100+
print("Copying:", dest)
101+
_ensure_path_exists(dest)
102+
with open(dest, "wb") as f:
103+
_chunk(response.raw, f.write)
104+
105+
return True
106+
finally:
107+
response.close()
108+
109+
110+
def _install_json(package_json_url, index, target, version, mpy):
111+
response = requests.get(_rewrite_url(package_json_url, version))
112+
try:
113+
if response.status_code != 200:
114+
print("Package not found:", package_json_url)
115+
return False
116+
117+
package_json = response.json()
118+
finally:
119+
response.close()
120+
for target_path, short_hash in package_json.get("hashes", ()):
121+
fs_target_path = target + "/" + target_path
122+
if _check_exists(fs_target_path, short_hash):
123+
print("Exists:", fs_target_path)
124+
else:
125+
file_url = "{}/file/{}/{}".format(index, short_hash[:2], short_hash)
126+
if not _download_file(file_url, fs_target_path):
127+
print("File not found: {} {}".format(target_path, short_hash))
128+
return False
129+
base_url = package_json_url.rpartition("/")[0]
130+
for target_path, url in package_json.get("urls", ()):
131+
fs_target_path = target + "/" + target_path
132+
is_full_url = any(url.startswith(p) for p in allowed_mip_url_prefixes)
133+
if base_url and not is_full_url:
134+
url = f"{base_url}/{url}" # Relative URLs
135+
if not _download_file(_rewrite_url(url, version), fs_target_path):
136+
print("File not found: {} {}".format(target_path, url))
137+
return False
138+
for dep, dep_version in package_json.get("deps", ()):
139+
if not _install_package(dep, index, target, dep_version, mpy):
140+
return False
141+
return True
142+
143+
144+
def _install_package(package, index, target, version, mpy):
145+
if any(package.startswith(p) for p in allowed_mip_url_prefixes):
146+
if package.endswith(".py") or package.endswith(".mpy"):
147+
print("Downloading {} to {}".format(package, target))
148+
return _download_file(
149+
_rewrite_url(package, version), target + "/" + package.rsplit("/")[-1]
150+
)
151+
else:
152+
if not package.endswith(".json"):
153+
if not package.endswith("/"):
154+
package += "/"
155+
package += "package.json"
156+
print("Installing {} to {}".format(package, target))
157+
else:
158+
if not version:
159+
version = "latest"
160+
print("Installing {} ({}) from {} to {}".format(package, version, index, target))
161+
162+
mpy_version = (
163+
sys.implementation._mpy & 0xFF if mpy and hasattr(sys.implementation, "_mpy") else "py"
164+
)
165+
166+
package = "{}/package/{}/{}/{}.json".format(index, mpy_version, package, version)
167+
168+
return _install_json(package, index, target, version, mpy)
169+
170+
171+
def install(package, index=None, target=None, version=None, mpy=True):
172+
if not target:
173+
for p in sys.path:
174+
if not p.startswith("/rom") and p.endswith("/lib"):
175+
target = p
176+
break
177+
else:
178+
print("Unable to find lib dir in sys.path")
179+
return
180+
181+
if not index:
182+
index = _PACKAGE_INDEX
183+
184+
if _install_package(package, index.rstrip("/"), target, version, mpy):
185+
print("Done")
186+
else:
187+
print("Package may be partially installed")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from _typeshed import Incomplete
2+
from micropython import const as const
3+
4+
_PACKAGE_INDEX: str
5+
_CHUNK_SIZE: int
6+
allowed_mip_url_prefixes: Incomplete
7+
8+
def _ensure_path_exists(path) -> None: ...
9+
def _chunk(src, dest) -> None: ...
10+
def _check_exists(path, short_hash): ...
11+
def _rewrite_url(url, branch=None): ...
12+
def _download_file(url, dest): ...
13+
def _install_json(package_json_url, index, target, version, mpy): ...
14+
def _install_package(package, index, target, version, mpy): ...
15+
def install(package, index=None, target=None, version=None, mpy: bool = True) -> None: ...
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/Josverl/micropython-stubber/main/data/schema/stubber-v1_4_0.json",
3+
"firmware": {
4+
"family": "micropython",
5+
"port": "alif",
6+
"platform": "alif",
7+
"machine": "GENERIC",
8+
"firmware": "micropython-alif-v1_26_1",
9+
"nodename": "micropython",
10+
"version": "v1.26.1",
11+
"release": "v1.26.1",
12+
"sysname": "micropython"
13+
},
14+
"stubber": {
15+
"version": "1.26.3",
16+
"stubtype": "frozen"
17+
},
18+
"modules": [
19+
{
20+
"file": "_boot.py",
21+
"module": "_boot"
22+
},
23+
{
24+
"file": "dht.py",
25+
"module": "dht"
26+
},
27+
{
28+
"file": "mip/__init__.py",
29+
"module": "__init__"
30+
},
31+
{
32+
"file": "neopixel.py",
33+
"module": "neopixel"
34+
},
35+
{
36+
"file": "ntptime.py",
37+
"module": "ntptime"
38+
},
39+
{
40+
"file": "onewire.py",
41+
"module": "onewire"
42+
},
43+
{
44+
"file": "requests/__init__.py",
45+
"module": "__init__"
46+
},
47+
{
48+
"file": "ssl.py",
49+
"module": "ssl"
50+
},
51+
{
52+
"file": "urequests.py",
53+
"module": "urequests"
54+
},
55+
{
56+
"file": "webrepl.py",
57+
"module": "webrepl"
58+
},
59+
{
60+
"file": "webrepl_setup.py",
61+
"module": "webrepl_setup"
62+
}
63+
]
64+
}

0 commit comments

Comments
 (0)