Ducktape for downloading LICENSE of pipdeptree

This package uses hatchling as a build backend and required special
case.
There should be a better way, but for now this works.
This commit is contained in:
Oz N Tiram
2022-09-08 15:02:58 +02:00
parent 6437584792
commit f910bc3b7c
2 changed files with 46 additions and 11 deletions
+20
View File
@@ -0,0 +1,20 @@
Copyright (c) 2015 Vineet Naik (naikvin@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+26 -11
View File
@@ -486,6 +486,7 @@ def download_licenses(
log(requirements)
tmp_dir = vendor_dir / "__tmp__"
# TODO: Fix this whenever it gets sorted out (see https://github.com/pypa/pip/issues/5739)
cmd = "pip download --no-binary :all: --only-binary requests_download --no-deps"
ctx.run("pip install flit") # needed for the next step
for req in requirements:
@@ -493,20 +494,34 @@ def download_licenses(
try:
ctx.run(exe_cmd)
except invoke.exceptions.UnexpectedExit as e:
if "Disabling PEP 517 processing is invalid" not in e.result.stderr:
if "ModuleNotFoundErr" in e.result.stderr.strip():
target = parse.parse(
"ModuleNotFoundError: No module named '{backend}'",
e.result.stderr.strip().split("\n")[-1],
)
backend = target.named.get("backend")
if backend is not None:
if "." in backend:
backend, _, _ = backend.partition(".")
ctx.run(f"pip install {backend}")
ctx.run("pip install hatch-vcs")
elif "Disabling PEP 517 processing is invalid" not in e.result.stderr:
log(f"WARNING: Failed to download license for {req}")
continue
parse_target = (
"Disabling PEP 517 processing is invalid: project specifies a build "
"backend of {backend} in pyproject.toml"
)
target = parse.parse(parse_target, e.result.stderr.strip())
backend = target.named.get("backend")
if backend is not None:
if "." in backend:
backend, _, _ = backend.partition(".")
ctx.run(f"pip install {backend}")
else:
parse_target = (
"Disabling PEP 517 processing is invalid: project specifies a build "
"backend of {backend} in pyproject.toml"
)
target = parse.parse(parse_target, e.result.stderr.strip())
backend = target.named.get("backend")
if backend is not None:
if "." in backend:
backend, _, _ = backend.partition(".")
ctx.run(f"pip install {backend}")
ctx.run(f"{cmd} --no-build-isolation -d {tmp_dir.as_posix()} {req}")
for sdist in tmp_dir.iterdir():
extract_license(vendor_dir, sdist)
drop_dir(tmp_dir)