Spaces:
Sleeping
Sleeping
Retry native downloads through the official channel
Browse filesFiles changed (2)
- paper_methods.py+17-2
- test_app.py+15
11 unmodified lines12131415161715 unmodified lines3334353637385 unmodified lines444546474849507 unmodified lines5859606162636411 unmodified linesimport subprocessimport tempfileimport tarfileimport urllib.requestimport cv215 unmodified linesIJ_SHA256 = "2e1a09961dfb41cee66ddc821b2577a41a072566ce45a49bae69267099741e20"def prepare_native_runtime():"""Install isolated R dependencies on Linux once; never alter system R."""if os.name == "nt" or os.getenv("AGROMIND_INSTALL_NATIVE", "1") != "1":5 unmodified linesif not marker.exists():if not mamba.exists():archive = folder / "micromamba-2.9.0.tar.bz2"urllib.request.urlretrieve("https://api.anaconda.org/download/conda-forge/micromamba/2.9.0/linux-64/micromamba-2.9.0-0.tar.bz2", archive)if hashlib.sha256(archive.read_bytes()).hexdigest() != "8761c382127e6363bd9e0a2451aa3ef90d071a79133f736e2f759a3bf13040dd":raise ValueError("Native runtime installer checksum mismatch")with tarfile.open(archive) as source:7 unmodified lines"r-doparallel", "r-foreach", "r-rcpparmadillo", "cxx-compiler", "make"]log = folder / "setup.log"package = folder / "pliman_2.1.0.tar.gz"urllib.request.urlretrieve("https://cloud.r-project.org/src/contrib/Archive/pliman/pliman_2.1.0.tar.gz", package)if hashlib.sha256(package.read_bytes()).hexdigest() != "e73b2aeb56e97ee54a4b0b73840d6f70c65bfd96301cd07c4064a2b3bc3afb5d":raise ValueError("pliman source checksum mismatch")with log.open("w", encoding="utf-8") as output:11 unmodified lines121314151617181915 unmodified lines353637383940414243444546474849505152535 unmodified lines596061626364657 unmodified lines7374757677787911 unmodified linesimport subprocessimport tempfileimport tarfileimport timeimport urllib.errorimport urllib.requestimport cv215 unmodified linesIJ_SHA256 = "2e1a09961dfb41cee66ddc821b2577a41a072566ce45a49bae69267099741e20"def download_native_source(url, path):"""Retry transient upstream failures; checksum validation stays with callers."""for attempt in range(3):try:with urllib.request.urlopen(url, timeout=60) as source:path.write_bytes(source.read())returnexcept urllib.error.HTTPError as exc:if exc.code not in {429, 500, 502, 503, 504} or attempt == 2:raisetime.sleep(2 ** (attempt + 1))def prepare_native_runtime():"""Install isolated R dependencies on Linux once; never alter system R."""if os.name == "nt" or os.getenv("AGROMIND_INSTALL_NATIVE", "1") != "1":5 unmodified linesif not marker.exists():if not mamba.exists():archive = folder / "micromamba-2.9.0.tar.bz2"download_native_source("https://conda.anaconda.org/conda-forge/linux-64/micromamba-2.9.0-0.tar.bz2", archive)if hashlib.sha256(archive.read_bytes()).hexdigest() != "8761c382127e6363bd9e0a2451aa3ef90d071a79133f736e2f759a3bf13040dd":raise ValueError("Native runtime installer checksum mismatch")with tarfile.open(archive) as source:7 unmodified lines"r-doparallel", "r-foreach", "r-rcpparmadillo", "cxx-compiler", "make"]log = folder / "setup.log"package = folder / "pliman_2.1.0.tar.gz"download_native_source("https://cloud.r-project.org/src/contrib/Archive/pliman/pliman_2.1.0.tar.gz", package)if hashlib.sha256(package.read_bytes()).hexdigest() != "e73b2aeb56e97ee54a4b0b73840d6f70c65bfd96301cd07c4064a2b3bc3afb5d":raise ValueError("pliman source checksum mismatch")with log.open("w", encoding="utf-8") as output:
153 unmodified lines154155156157158159153 unmodified linesframe.iloc[3:].to_csv(path, index=False)assert app.binary_evaluation(path)["status"] == "NOT_EVALUABLE"import paper_methodsassert paper_methods.seed_points(np.zeros((32, 32), bool)) == []seed_mask = np.zeros((32, 32), bool)seed_mask[4:10, 4:10] = True153 unmodified lines154155156157158159160161162163164165166167168169170171172173174153 unmodified linesframe.iloc[3:].to_csv(path, index=False)assert app.binary_evaluation(path)["status"] == "NOT_EVALUABLE"import paper_methodsimport iofrom urllib.error import HTTPErrorwith tempfile.TemporaryDirectory() as directory:path = Path(directory) / "source.tar.gz"limited = HTTPError("https://example.test/source", 429, "Rate limited", {}, None)with patch.object(paper_methods.urllib.request, "urlopen", side_effect=[limited, io.BytesIO(b"source")]) as fetch, patch.object(paper_methods.time, "sleep"):paper_methods.download_native_source(limited.url, path)assert path.read_bytes() == b"source" and fetch.call_count == 2with patch.object(paper_methods.urllib.request, "urlopen", side_effect=limited) as fetch, patch.object(paper_methods.time, "sleep"):try:paper_methods.download_native_source(limited.url, path)except HTTPError:assert fetch.call_count == 3else:raise AssertionError("Rate limit retry must be bounded")assert paper_methods.seed_points(np.zeros((32, 32), bool)) == []seed_mask = np.zeros((32, 32), bool)seed_mask[4:10, 4:10] = True
paper_methods.py+17-2
test_app.py+15