Skip to content

fix path to whl for APIView #40095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions eng/tox/run_apistubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@

root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))

def get_package_wheel_path(pkg_root):
def get_package_wheel_path(pkg_root, out_path):
# parse setup.py to get package name and version
pkg_details = ParsedSetup.from_path(pkg_root)

# Check if wheel is already built and available for current package
prebuilt_dir = os.getenv("PREBUILT_WHEEL_DIR")
out_token_path = None
if prebuilt_dir:
prebuilt_package_path = find_whl(prebuilt_dir, pkg_details.name, pkg_details.version)
else:
return None

pkg_path = os.path.join(prebuilt_dir, find_whl(prebuilt_dir, pkg_details.name, pkg_details.version))
if not pkg_path:
raise FileNotFoundError(
"No prebuilt wheel found for package {} version {} in directory {}".format(
pkg_details.name, pkg_details.version, prebuilt_dir)
)
# If the package is a wheel and out_path is given, the token file output path should be the parent directory of the wheel
if out_path:
out_token_path = os.path.join(out_path, os.path.basename(os.path.dirname(pkg_path)))
return pkg_path, out_token_path
pkg_path = pkg_root
# 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
if out_path:
out_token_path = os.path.join(out_path, os.path.basename(pkg_path))
return pkg_path, out_token_path

if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -55,18 +67,16 @@ def get_package_wheel_path(pkg_root):
dest="out_path",
help="Output directory to generate json token file"
)

args = parser.parse_args()

# Check if a wheel is already built for current package and install from wheel when available
# If wheel is not available then install package from source
pkg_path = get_package_wheel_path(args.target_package)
if not pkg_path:
pkg_path = args.target_package
pkg_path, out_token_path = get_package_wheel_path(args.target_package, args.out_path)

cmds = ["apistubgen", "--pkg-path", pkg_path]
if args.out_path:
cmds.extend(["--out-path", os.path.join(args.out_path, os.path.basename(pkg_path))])
if out_token_path:
cmds.extend(["--out-path", out_token_path])

logging.info("Running apistubgen {}.".format(cmds))
check_call(cmds, cwd=args.work_dir)
Loading