|
16 | 16 |
|
17 | 17 | root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..")) |
18 | 18 |
|
19 | | -def get_package_wheel_path(pkg_root): |
| 19 | +def get_package_wheel_path(pkg_root, out_path): |
20 | 20 | # parse setup.py to get package name and version |
21 | 21 | pkg_details = ParsedSetup.from_path(pkg_root) |
22 | 22 |
|
23 | 23 | # Check if wheel is already built and available for current package |
24 | 24 | prebuilt_dir = os.getenv("PREBUILT_WHEEL_DIR") |
| 25 | + out_token_path = None |
25 | 26 | if prebuilt_dir: |
26 | | - prebuilt_package_path = find_whl(prebuilt_dir, pkg_details.name, pkg_details.version) |
27 | | - else: |
28 | | - return None |
29 | | - |
| 27 | + pkg_path = os.path.join(prebuilt_dir, find_whl(prebuilt_dir, pkg_details.name, pkg_details.version)) |
| 28 | + if not pkg_path: |
| 29 | + raise FileNotFoundError( |
| 30 | + "No prebuilt wheel found for package {} version {} in directory {}".format( |
| 31 | + pkg_details.name, pkg_details.version, prebuilt_dir) |
| 32 | + ) |
| 33 | + # If the package is a wheel and out_path is given, the token file output path should be the parent directory of the wheel |
| 34 | + if out_path: |
| 35 | + out_token_path = os.path.join(out_path, os.path.basename(os.path.dirname(pkg_path))) |
| 36 | + return pkg_path, out_token_path |
| 37 | + pkg_path = pkg_root |
| 38 | + # If the package is not a wheel and out_path is given, the token file output path should be the same as the target package path |
| 39 | + if out_path: |
| 40 | + out_token_path = os.path.join(out_path, os.path.basename(pkg_path)) |
| 41 | + return pkg_path, out_token_path |
30 | 42 |
|
31 | 43 | if __name__ == "__main__": |
32 | 44 | parser = argparse.ArgumentParser( |
@@ -55,18 +67,16 @@ def get_package_wheel_path(pkg_root): |
55 | 67 | dest="out_path", |
56 | 68 | help="Output directory to generate json token file" |
57 | 69 | ) |
58 | | - |
| 70 | + |
59 | 71 | args = parser.parse_args() |
60 | 72 |
|
61 | 73 | # Check if a wheel is already built for current package and install from wheel when available |
62 | 74 | # If wheel is not available then install package from source |
63 | | - pkg_path = get_package_wheel_path(args.target_package) |
64 | | - if not pkg_path: |
65 | | - pkg_path = args.target_package |
| 75 | + pkg_path, out_token_path = get_package_wheel_path(args.target_package, args.out_path) |
66 | 76 |
|
67 | 77 | cmds = ["apistubgen", "--pkg-path", pkg_path] |
68 | | - if args.out_path: |
69 | | - cmds.extend(["--out-path", os.path.join(args.out_path, os.path.basename(pkg_path))]) |
| 78 | + if out_token_path: |
| 79 | + cmds.extend(["--out-path", out_token_path]) |
70 | 80 |
|
71 | 81 | logging.info("Running apistubgen {}.".format(cmds)) |
72 | 82 | check_call(cmds, cwd=args.work_dir) |
0 commit comments