Skip to content

Commit

Permalink
Preserve cache (#114)
Browse files Browse the repository at this point in the history
* Preserve wheels from cache

* bump version
  • Loading branch information
pvizeli authored Jul 8, 2020
1 parent 5bfd6b6 commit bcf5818
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions builder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

from builder.apk import install_apks
from builder.infra import (
check_available_binary,
create_wheels_folder,
create_wheels_index,
check_available_binary,
)
from builder.pip import (
build_wheels_local,
Expand All @@ -24,7 +24,7 @@
write_requirement,
)
from builder.upload import run_upload
from builder.utils import check_url, fix_wheels_name
from builder.utils import check_url, copy_wheels_from_cache, fix_wheels_name


@click.command("builder")
Expand Down Expand Up @@ -126,6 +126,7 @@ def builder(
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)
Expand All @@ -146,6 +147,7 @@ def builder(
exit_code = 109
except TimeoutExpired:
exit_code = 80
copy_wheels_from_cache(Path("/root/.cache/pip/wheels"), wheels_dir)

fix_wheels_name(wheels_dir)
run_upload(upload, output, remote)
Expand Down
13 changes: 11 additions & 2 deletions builder/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Some utils for builder."""
from pathlib import Path
from contextlib import suppress
import os
from pathlib import Path
import re
import shutil
import subprocess
import sys
from typing import Optional, Dict
from typing import Dict, Optional

import requests

Expand Down Expand Up @@ -38,6 +40,13 @@ def fix_wheels_name(wheels_folder: Path) -> None:
package.rename(Path(package.parent, f"{match.group('name')}none-any.whl"))


def copy_wheels_from_cache(cache_folder: Path, wheels_folder: Path) -> None:
"""Preserve wheels from cache on timeout error."""
for wheel_file in cache_folder.glob("**/*.whl"):
with suppress(OSError):
shutil.copy(wheel_file, wheels_folder)


def run_command(
cmd: str, env: Optional[Dict[str, str]] = None, timeout: Optional[int] = None
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "1.12.3"
VERSION = "1.12.4"

setup(
name="builder",
Expand Down

0 comments on commit bcf5818

Please sign in to comment.