Skip to content

Commit 8582d20

Browse files
committed
spec: wrap/override fsspec httpfs
1 parent 3dbadcd commit 8582d20

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

dvc_http/__init__.py

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import threading
22
from getpass import getpass
3-
from typing import TYPE_CHECKING, BinaryIO, Union
3+
from typing import TYPE_CHECKING, Union
44

5-
from dvc_objects.fs.base import AnyFSPath, FileSystem
6-
from dvc_objects.fs.callbacks import DEFAULT_CALLBACK, Callback
5+
from dvc_objects.fs.base import FileSystem
76
from dvc_objects.fs.errors import ConfigError
87
from funcy import cached_property, memoize, wrap_with
98

@@ -45,8 +44,8 @@ class HTTPFileSystem(FileSystem):
4544

4645
def __init__(self, fs=None, timeout=REQUEST_TIMEOUT, **kwargs):
4746
super().__init__(fs, **kwargs)
48-
self.upload_method = kwargs.get("method", "POST")
4947

48+
self.fs_args["upload_method"] = kwargs.get("method", "POST")
5049
client_kwargs = self.fs_args.setdefault("client_kwargs", {})
5150
client_kwargs.update(
5251
{
@@ -129,28 +128,16 @@ async def get_client(self, **kwargs):
129128

130129
@cached_property
131130
def fs(self):
132-
from fsspec.implementations.http import (
133-
HTTPFileSystem as _HTTPFileSystem,
134-
)
131+
from .spec import HTTPFileSystem as _HTTPFileSystem
135132

136-
return _HTTPFileSystem(get_client=self.get_client, **self.fs_args)
133+
return _HTTPFileSystem(
134+
get_client=self.get_client,
135+
**self.fs_args,
136+
)
137137

138138
def unstrip_protocol(self, path: str) -> str:
139139
return path
140140

141-
def put_file(
142-
self,
143-
from_file: Union[AnyFSPath, BinaryIO],
144-
to_info: AnyFSPath,
145-
callback: Callback = DEFAULT_CALLBACK,
146-
size: int = None,
147-
**kwargs,
148-
) -> None:
149-
kwargs.setdefault("method", self.upload_method)
150-
super().put_file(
151-
from_file, to_info, callback=callback, size=size, **kwargs
152-
)
153-
154141
# pylint: disable=arguments-differ
155142

156143
def find(self, *args, **kwargs):

dvc_http/spec.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from fsspec.implementations import http
2+
3+
4+
class HTTPFileSystem(http.HTTPFileSystem): # pylint: disable=abstract-method
5+
def __init__(self, *args, upload_method: str = "post", **kwargs):
6+
super().__init__(*args, **kwargs)
7+
self.upload_method = upload_method
8+
9+
async def _put_file(self, *args, **kwargs):
10+
kwargs.setdefault("method", self.upload_method)
11+
return await super()._put_file(*args, **kwargs)

dvc_http/tests/test_config.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ def test_http_method():
9191
}
9292

9393
fs = HTTPFileSystem(**config, method="PUT")
94-
assert fs.upload_method == "PUT"
94+
assert fs.fs_args.get("upload_method") == "PUT"
95+
assert fs.fs.upload_method == "PUT"
9596

9697
fs = HTTPFileSystem(**config, method="POST")
97-
assert fs.upload_method == "POST"
98+
assert fs.fs_args.get("upload_method") == "POST"
99+
assert fs.fs.upload_method == "POST"
98100

99101

100102
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)