Skip to content

Commit 4ecbf11

Browse files
committed
mpremote: Support mip install from package.json on local fs.
Add support for: - mpremote mip install package.json where package.json is a json file on the local filesystem. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
1 parent 00930b2 commit 4ecbf11

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

tools/mpremote/mpremote/mip.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,29 @@ def _download_file(transport, url, dest):
9090

9191

9292
def _install_json(transport, package_json_url, index, target, version, mpy):
93-
try:
94-
with urllib.request.urlopen(_rewrite_url(package_json_url, version)) as response:
95-
package_json = json.load(response)
96-
except urllib.error.HTTPError as e:
97-
if e.status == 404:
98-
raise CommandError(f"Package not found: {package_json_url}")
99-
else:
100-
raise CommandError(f"Error {e.status} requesting {package_json_url}")
101-
except urllib.error.URLError as e:
102-
raise CommandError(f"{e.reason} requesting {package_json_url}")
93+
if (
94+
package_json_url.startswith("http://")
95+
or package_json_url.startswith("https://")
96+
or package_json_url.startswith("github:")
97+
):
98+
try:
99+
with urllib.request.urlopen(_rewrite_url(package_json_url, version)) as response:
100+
package_json = json.load(response)
101+
except urllib.error.HTTPError as e:
102+
if e.status == 404:
103+
raise CommandError(f"Package not found: {package_json_url}")
104+
else:
105+
raise CommandError(f"Error {e.status} requesting {package_json_url}")
106+
except urllib.error.URLError as e:
107+
raise CommandError(f"{e.reason} requesting {package_json_url}")
108+
elif package_json_url.endswith(".json"):
109+
try:
110+
with open(package_json_url, "r") as f:
111+
package_json = json.load(f)
112+
except OSError:
113+
raise CommandError(f"Error opening {package_json_url}")
114+
else:
115+
raise CommandError(f"Invalid url for package: {package_json_url}")
103116
for target_path, short_hash in package_json.get("hashes", ()):
104117
fs_target_path = target + "/" + target_path
105118
file_url = f"{index}/file/{short_hash[:2]}/{short_hash}"
@@ -129,6 +142,8 @@ def _install_package(transport, package, index, target, version, mpy):
129142
package += "/"
130143
package += "package.json"
131144
print(f"Installing {package} to {target}")
145+
elif package.endswith(".json"):
146+
pass
132147
else:
133148
if not version:
134149
version = "latest"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy