Skip to content

Commit 1f1f758

Browse files
committed
Add proxy support to dataset file retrieval
Introduces an optional proxy parameter to dataset file retrieval functions and methods in dvuploader.py and utils.py, allowing HTTP requests to be routed through a specified proxy. This enhances flexibility for users operating behind network proxies.
1 parent d0890ed commit 1f1f758

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

dvuploader/dvuploader.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def upload(
105105
persistent_id=persistent_id,
106106
api_token=api_token,
107107
replace_existing=replace_existing,
108+
proxy=proxy,
108109
)
109110

110111
# Sort files by size
@@ -198,7 +199,8 @@ def _check_duplicates(
198199
persistent_id: str,
199200
api_token: str,
200201
replace_existing: bool,
201-
):
202+
proxy: Optional[str] = None,
203+
) -> None:
202204
"""
203205
Checks for duplicate files in the dataset by comparing paths and filenames.
204206
@@ -207,7 +209,7 @@ def _check_duplicates(
207209
persistent_id (str): The persistent ID of the dataset.
208210
api_token (str): The API token for accessing the Dataverse repository.
209211
replace_existing (bool): Whether to replace files that already exist.
210-
212+
proxy (Optional[str]): The proxy to use for the request.
211213
Returns:
212214
None
213215
"""
@@ -216,6 +218,7 @@ def _check_duplicates(
216218
dataverse_url=dataverse_url,
217219
persistent_id=persistent_id,
218220
api_token=api_token,
221+
proxy=proxy,
219222
)
220223

221224
table = Table(
@@ -241,14 +244,14 @@ def _check_duplicates(
241244
to_skip.append(file.file_id)
242245

243246
if replace_existing:
244-
ds_file = self._get_dsfile_by_id(file.file_id, ds_files)
245-
if not self._check_size(file, ds_file):
247+
ds_file = self._get_dsfile_by_id(file.file_id, ds_files) # type: ignore
248+
if not self._check_size(file, ds_file): # type: ignore
246249
file._unchanged_data = False
247250
else:
248251
# calculate checksum
249252
file.update_checksum_chunked()
250253
file.apply_checksum()
251-
file._unchanged_data = self._check_hashes(file, ds_file)
254+
file._unchanged_data = self._check_hashes(file, ds_file) # type: ignore
252255
if file._unchanged_data:
253256
table.add_row(
254257
file.file_name,

dvuploader/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22
import pathlib
33
import re
4-
from typing import List
4+
from typing import List, Optional
55
from urllib.parse import urljoin
6+
67
import httpx
78
from rich.progress import Progress
89

@@ -40,6 +41,7 @@ def retrieve_dataset_files(
4041
dataverse_url: str,
4142
persistent_id: str,
4243
api_token: str,
44+
proxy: Optional[str] = None,
4345
):
4446
"""
4547
Retrieve the files of a specific dataset from a Dataverse repository.
@@ -48,6 +50,7 @@ def retrieve_dataset_files(
4850
dataverse_url (str): The base URL of the Dataverse repository.
4951
persistent_id (str): The persistent identifier (PID) of the dataset.
5052
api_token (str): API token for authentication.
53+
proxy (Optional[str]): The proxy to use for the request.
5154
5255
Returns:
5356
list: A list of files in the dataset.
@@ -61,6 +64,7 @@ def retrieve_dataset_files(
6164
response = httpx.get(
6265
urljoin(dataverse_url, DATASET_ENDPOINT),
6366
headers={"X-Dataverse-key": api_token},
67+
proxy=proxy,
6468
)
6569

6670
response.raise_for_status()

0 commit comments

Comments
 (0)