Skip to content

Commit 3f7b92f

Browse files
committed
mip: Allow accessing index from local filesystem
Just set the index to `file://relative/path` or `file:///absolute/path` Signed-off-by: Dominik Heidler <[email protected]>
1 parent 7337e08 commit 3f7b92f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

micropython/mip/mip/__init__.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def _rewrite_url(url, branch=None):
9191

9292

9393
def _download_file(url, dest):
94+
if url.startswith('file://'):
95+
print("Copying:", dest)
96+
src = url[7:]
97+
_ensure_path_exists(dest)
98+
with open(src, "b") as sf:
99+
with open(dest, "wb") as f:
100+
_chunk(sf, f.write)
101+
return True
94102
response = requests.get(url)
95103
try:
96104
if response.status_code != 200:
@@ -108,15 +116,19 @@ def _download_file(url, dest):
108116

109117

110118
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
119+
if package_json_url.startswith('file://'):
120+
import json
121+
package_json = json.load(open(package_json_url[7:]))
122+
else:
123+
response = requests.get(_rewrite_url(package_json_url, version))
124+
try:
125+
if response.status_code != 200:
126+
print("Package not found:", package_json_url)
127+
return False
116128

117-
package_json = response.json()
118-
finally:
119-
response.close()
129+
package_json = response.json()
130+
finally:
131+
response.close()
120132
for target_path, short_hash in package_json.get("hashes", ()):
121133
fs_target_path = target + "/" + target_path
122134
if _check_exists(fs_target_path, short_hash):

0 commit comments

Comments
 (0)