Skip to content

Commit 169b11e

Browse files
committed
fixes hdfs
1 parent 0f989fb commit 169b11e

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

environment.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ dependencies:
1313
- pytest
1414
- pylint
1515
- flake8
16+
- pyarrow
17+
- libhdfs3
18+
- pip
19+
- pip:
20+
- hadoop-test-cluster
1621

upath/core.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,15 @@ def exists(self):
207207
"""
208208
Whether this path exists.
209209
"""
210-
try:
211-
self._accessor.stat(self)
212-
except FileNotFoundError:
213-
return False
214-
return True
210+
if not getattr(self._accessor, 'exists'):
211+
try:
212+
self._accessor.stat(self)
213+
except (FileNotFoundError):
214+
return False
215+
return True
216+
else:
217+
return self._accessor.exists(self)
218+
215219

216220
def is_dir(self):
217221
info = self._accessor.info(self)

upath/tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,19 @@ def testingdir(clear_registry):
4747
yield tempdir
4848
shutil.rmtree(tempdir)
4949

50+
@pytest.fixture()
51+
def hdfs_test_client():
52+
import os
53+
pyarrow = pytest.importorskip('pyarrow')
54+
host = os.environ.get('ARROW_HDFS_TEST_HOST', '0.0.0.0')
55+
user = os.environ.get('ARROW_HDFS_TEST_USER', 'hdfs')
56+
try:
57+
port = int(os.environ.get('ARROW_HDFS_TEST_PORT', 9000))
58+
except ValueError:
59+
raise ValueError('Env variable ARROW_HDFS_TEST_PORT was not '
60+
'an integer')
61+
62+
hdfs = pyarrow.hdfs.connect(host='0.0.0.0', port=9000, user=user, driver='libhdfs3')
63+
hdfs.mkdir('/folder1')
64+
return host, user, port
65+

upath/tests/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,9 @@ def test_write_text(self, mock_base, pathlib_base):
214214
assert pathlib_base.joinpath(fn).read_bytes() == s
215215

216216

217+
218+
def test_hdfs(hdfs_test_client):
219+
host, user, port = hdfs_test_client
220+
path = UPath('hdfs:/', host=host, user=user, port=port, driver='libhdfs3')
221+
assert path.exists()
222+

0 commit comments

Comments
 (0)