Skip to content
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

JobCommand: reimplement urlretrieve with requests #209

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions ampel/cli/JobCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

import tarfile, tempfile, ujson, yaml, io, os, signal, sys, \
subprocess, platform, shutil, filecmp, psutil, pkg_resources
import requests
from time import time, sleep
from multiprocessing import Queue, Process
from argparse import ArgumentParser
from importlib import import_module
from typing import Any
from collections.abc import Sequence
from urllib.request import urlretrieve
from ampel.abstract.AbsEventUnit import AbsEventUnit
from ampel.abstract.AbsProcessorTemplate import AbsProcessorTemplate
from ampel.model.UnitModel import UnitModel
Expand Down Expand Up @@ -701,7 +701,11 @@ def _fetch_inputs(
)
os.makedirs(resolved_artifact.path.parent, exist_ok=True)
with tempfile.NamedTemporaryFile(delete=False) as tf:
urlretrieve(resolved_artifact.http.url, tf.name)
r = requests.get(resolved_artifact.http.url, stream=True)
r.raise_for_status()
for chunk in r.iter_content(chunk_size=1<<13):
tf.write(chunk)
tf.flush()
try:
with tarfile.open(tf.name) as archive:
logger.info(f'{resolved_artifact.name} is a tarball; extracting')
Expand Down
35 changes: 31 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ prometheus-client = ">=0.16,<0.17"
xxhash = "^3.0.0"
psutil = "^5.8.0"
appdirs = "^1.4.4"
requests = "^2.0"
fastapi = {version = ">=0.92,<0.93", optional = true}
uvicorn = {version = ">=0.20.0,<0.21.0", optional = true, extras = ["standard"]}
Sphinx = {version = ">=6.1.2,<6.2.0", optional = true}
Expand All @@ -79,6 +80,9 @@ server = ["fastapi", "uvicorn"]
docs = ["Sphinx", "sphinx-press-theme", "sphinx-autodoc-typehints", "tomlkit"]
slack = ["slack_sdk"]

[tool.poetry.group.dev.dependencies]
types-requests = "^2.28.11.15"

[tool.isort]
profile = "black"

Expand Down