def test_check_available_binary_implicit_dep_skipped() -> None: """Test case where skip binary lists an implicit dep which is ignored.""" assert (check_available_binary( TEST_INDEX_URL, "aiohttp,grpcio", packages=[ "aiohttp==3.7.4", "google_cloud_pubsub==2.1.0", ], constraints=[], ) == ":none:")
def test_check_available_binary_version_missing() -> None: """Test to skip a binary where the package version is not in the index.""" assert (check_available_binary( TEST_INDEX_URL, "aiohttp", packages=[ "aiohttp==3.7.5", # Not in the index "google_cloud_pubsub==2.1.0", ], constraints=[], ) == "aiohttp")
def test_check_available_binary_version_present() -> None: """Test to skip a binary where the package version is already in the index.""" assert (check_available_binary( TEST_INDEX_URL, "aiohttp", packages=[ "aiohttp==3.7.4", "google_cloud_pubsub==2.1.0", ], constraints=[], ) == ":none:")
def test_check_available_binary_all() -> None: """This tool does not allow skipping all binaries.""" assert (check_available_binary( TEST_INDEX_URL, ":all:", packages=[ "aiohttp==3.7.4", "google_cloud_pubsub==2.1.0", ], constraints=[], ) == ":none:")
def test_check_available_binary_none() -> None: """No-op when no binaries specified to skip.""" assert (check_available_binary( TEST_INDEX_URL, ":none:", packages=[ "aiohttp==3.7.4", "google_cloud_pubsub==2.1.0", ], constraints=[], ) == ":none:")
def test_check_available_binary_skip_constraint() -> None: """Test case where skip binary is for constraint in the index.""" assert (check_available_binary( TEST_INDEX_URL, "aiohttp,grpcio", packages=[ "aiohttp==3.7.4", "google_cloud_pubsub==2.1.0", ], constraints=[ "grpcio==1.31.0", # Already exists in index ], ) == ":none:")
def test_check_available_binary_for_missing_constraint() -> None: """Test case where skip binary is for constraint notin the index.""" assert (check_available_binary( TEST_INDEX_URL, "aiohttp,grpcio", packages=[ "aiohttp==3.7.4", "google_cloud_pubsub==2.1.0", ], constraints=[ "grpcio==1.43.0", # Not in index ], ) == "grpcio")
def builder( apk: str, pip: str, index: str, skip_binary: str, requirement: Optional[Path], requirement_diff: Optional[Path], constraint: Optional[Path], prebuild_dir: Optional[Path], single: bool, auditwheel: bool, local: bool, upload: str, remote: str, timeout: int, ): """Build wheels precompiled for Home Assistant container.""" install_apks(apk) check_url(index) exit_code = 0 with TemporaryDirectory() as temp_dir: output = Path(temp_dir) wheels_dir = create_wheels_folder(output) wheels_index = create_wheels_index(index) # Setup build helper install_pips(wheels_index, pip) timeout = timeout * 60 if local: # Build wheels in a local folder/src build_wheels_local(wheels_index, wheels_dir) elif prebuild_dir: # Prepare allready builded wheels for upload for whl_file in prebuild_dir.glob("*.whl"): shutil.copy(whl_file, Path(wheels_dir, whl_file.name)) elif single: # Build every wheel like a single installation packages = extract_packages(requirement, requirement_diff) skip_binary = check_available_binary(wheels_index, skip_binary, packages) for package in packages: print(f"Process package: {package}", flush=True) try: build_wheels_package( package, wheels_index, wheels_dir, skip_binary, timeout, constraint, ) except CalledProcessError: exit_code = 109 except TimeoutExpired: exit_code = 80 copy_wheels_from_cache(Path("/root/.cache/pip/wheels"), wheels_dir) else: # Build all needed wheels at once packages = extract_packages(requirement, requirement_diff) temp_requirement = Path("/tmp/wheels_requirement.txt") write_requirement(temp_requirement, packages) skip_binary = check_available_binary(wheels_index, skip_binary, packages) try: build_wheels_requirement( temp_requirement, wheels_index, wheels_dir, skip_binary, timeout, constraint, ) except CalledProcessError: exit_code = 109 except TimeoutExpired: exit_code = 80 copy_wheels_from_cache(Path("/root/.cache/pip/wheels"), wheels_dir) if auditwheel: run_auditwheel(wheels_dir) fix_wheels_name(wheels_dir) run_upload(upload, output, remote) sys.exit(exit_code)