Skip to content

Commit cc2aae6

Browse files
committed
enable local paths for experimental_index_url
1 parent 87906f0 commit cc2aae6

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

python/private/pypi/simpleapi_download.bzl

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,35 @@ def _read_simpleapi(ctx, url, attr, cache, get_auth = None, **download_kwargs):
217217

218218
get_auth = get_auth or _get_auth
219219

220-
# NOTE: this may have block = True or block = False in the download_kwargs
221-
download = ctx.download(
222-
url = [real_url],
223-
output = output,
224-
auth = get_auth(ctx, [real_url], ctx_attr = attr),
225-
allow_fail = True,
226-
**download_kwargs
227-
)
220+
if not real_url.startswith("https://"):
221+
normalized_url = real_url
222+
local_path = ctx.path(normalized_url)
223+
224+
def local_read_index_result():
225+
if local_path.is_dir:
226+
ctx.file(output, ctx.read(normalized_url + "index.html"))
227+
return struct(
228+
output = output,
229+
success = True,
230+
)
231+
else:
232+
ctx.file(output, ctx.read(normalized_url))
233+
return struct(
234+
output = output,
235+
success = True,
236+
)
237+
238+
download = struct(wait = lambda: local_read_index_result())
239+
240+
else:
241+
# NOTE: this may have block = True or block = False in the download_kwargs
242+
download = ctx.download(
243+
url = [real_url],
244+
output = output,
245+
auth = get_auth(ctx, [real_url], ctx_attr = attr),
246+
allow_fail = False,
247+
**download_kwargs
248+
)
228249

229250
if download_kwargs.get("block") == False:
230251
# Simulate the same API as ctx.download has

python/private/pypi/whl_library.bzl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,29 @@ def _whl_library_impl(rctx):
295295
elif rctx.attr.urls and rctx.attr.filename:
296296
filename = rctx.attr.filename
297297
urls = rctx.attr.urls
298-
result = rctx.download(
299-
url = urls,
300-
output = filename,
301-
sha256 = rctx.attr.sha256,
302-
auth = get_auth(rctx, urls),
303-
)
298+
if len(urls) == 1 and not urls[0].startswith("https://"):
299+
local_url = urls[0]
300+
local_path = rctx.path(local_url)
301+
302+
if local_path.is_dir:
303+
rctx.file(filename, rctx.read(local_url + "index.html"))
304+
result = struct(
305+
output = filename,
306+
success = True,
307+
)
308+
else:
309+
rctx.file(filename, rctx.read(local_url))
310+
result = struct(
311+
output = filename,
312+
success = True,
313+
)
314+
else:
315+
result = rctx.download(
316+
url = urls,
317+
output = filename,
318+
sha256 = rctx.attr.sha256,
319+
auth = get_auth(rctx, urls),
320+
)
304321
if not rctx.attr.sha256:
305322
# this is only seen when there is a direct URL reference without sha256
306323
logger.warn("Please update the requirement line to include the hash:\n{} \\\n --hash=sha256:{}".format(

0 commit comments

Comments
 (0)