@@ -90,16 +90,29 @@ def _download_file(transport, url, dest):
90
90
91
91
92
92
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 } " )
103
116
for target_path , short_hash in package_json .get ("hashes" , ()):
104
117
fs_target_path = target + "/" + target_path
105
118
file_url = f"{ index } /file/{ short_hash [:2 ]} /{ short_hash } "
@@ -129,6 +142,8 @@ def _install_package(transport, package, index, target, version, mpy):
129
142
package += "/"
130
143
package += "package.json"
131
144
print (f"Installing { package } to { target } " )
145
+ elif package .endswith (".json" ):
146
+ pass
132
147
else :
133
148
if not version :
134
149
version = "latest"
0 commit comments