Skip to content

Commit e2b2a92

Browse files
authored
Always return pathlib.Path rather than py.path.local(). (#509)
1 parent 60ceb6e commit e2b2a92

File tree

3 files changed

+10
-75
lines changed

3 files changed

+10
-75
lines changed

dials_data/download.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import hashlib
88
import os
99
import tarfile
10-
import warnings
1110
import zipfile
1211
from pathlib import Path
1312
from typing import Any
1413
from urllib.parse import urlparse
1514

16-
import py.path
1715
import requests
1816
from requests.adapters import HTTPAdapter
1917
from urllib3.util.retry import Retry
@@ -300,36 +298,25 @@ def result_filter(self, result, **kwargs):
300298
"""
301299
return result
302300

303-
def __call__(self, test_data: str, pathlib=None, **kwargs):
301+
def __call__(self, test_data: str, **kwargs):
304302
"""
305303
Return the location of a dataset, transparently downloading it if
306304
necessary and possible.
307305
The return value can be manipulated by overriding the result_filter
308306
function.
309307
:param test_data: name of the requested dataset.
310-
:param pathlib: Whether to return the result as a Python pathlib object.
311-
The default for this setting is 'False' for now (leading
312-
to a py.path.local object being returned), but the default
313-
will change to 'True' in a future dials.data release.
314-
Set to 'True' for forward compatibility.
315308
:return: A pathlib or py.path.local object pointing to the dataset, or False
316309
if the dataset is not available.
317310
"""
311+
if "pathlib" in kwargs:
312+
raise ValueError(
313+
"The pathlib parameter has been removed. The "
314+
"DataFetcher always returns pathlib.Path() objects now."
315+
)
318316
if test_data not in self._cache:
319317
self._cache[test_data] = self._attempt_fetch(test_data)
320-
if pathlib is None:
321-
warnings.warn(
322-
"The DataFetcher currently returns py.path.local() objects. "
323-
"This will in the future change to pathlib.Path() objects. "
324-
"You can either add a pathlib=True argument to obtain a pathlib.Path() object, "
325-
"or pathlib=False to silence this warning for now.",
326-
DeprecationWarning,
327-
stacklevel=2,
328-
)
329318
if not self._cache[test_data]:
330319
return self.result_filter(result=False)
331-
elif not pathlib:
332-
return self.result_filter(result=py.path.local(self._cache[test_data]))
333320
return self.result_filter(result=self._cache[test_data])
334321

335322
def _attempt_fetch(self, test_data: str) -> Path | None:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "dials_data"
7-
version = "2.4.0"
7+
version = "3.0.0"
88
description = "DIALS Regression Data Manager"
99
authors = [
10-
{ name = "DIALS development team", email = "dials-support@lists.sourceforge.net" },
10+
{ name = "DIALS development team", email = "dials-user-group@jiscmail.ac.uk" },
1111
]
1212
license = { text = "BSD 3-Clause License" }
1313
classifiers = [

tests/test_dials_data.py

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
from __future__ import annotations
22

3-
import pathlib
43
from unittest import mock
54

6-
import py
7-
import pytest
8-
95
import dials_data
106
import dials_data.datasets
117
import dials_data.download
@@ -22,60 +18,12 @@ def test_repository_location():
2218

2319
def test_fetching_undefined_datasets_does_not_crash():
2420
df = dials_data.download.DataFetcher(read_only=True)
25-
assert df("aardvark", pathlib=True) is False
21+
assert df("aardvark") is False
2622

2723

2824
def test_requests_for_future_datasets_can_be_intercepted():
2925
df = dials_data.download.DataFetcher(read_only=True)
3026
df.result_filter = mock.Mock()
3127
df.result_filter.return_value = False
32-
assert df("aardvark", pathlib=True) is False
28+
assert df("aardvark") is False
3329
df.result_filter.assert_called_once_with(result=False)
34-
35-
36-
@mock.patch("dials_data.datasets.repository_location")
37-
@mock.patch("dials_data.download.fetch_dataset")
38-
def test_datafetcher_constructs_py_path(fetcher, root):
39-
root.return_value = pathlib.Path("/tmp/root")
40-
fetcher.return_value = True
41-
42-
df = dials_data.download.DataFetcher(read_only=True)
43-
with pytest.warns(DeprecationWarning):
44-
ds = df("dataset")
45-
assert pathlib.Path(ds).resolve() == pathlib.Path("/tmp/root/dataset").resolve()
46-
assert isinstance(ds, py.path.local)
47-
fetcher.assert_called_once_with(
48-
"dataset", pre_scan=True, read_only=False, verify=True
49-
)
50-
51-
ds = df("dataset", pathlib=False)
52-
assert pathlib.Path(ds).resolve() == pathlib.Path("/tmp/root/dataset").resolve()
53-
assert isinstance(ds, py.path.local)
54-
fetcher.assert_called_once()
55-
56-
57-
@mock.patch("dials_data.datasets.repository_location")
58-
@mock.patch("dials_data.download.fetch_dataset")
59-
def test_datafetcher_constructs_path(fetcher, root):
60-
test_path = pathlib.Path("/tmp/root")
61-
root.return_value = test_path
62-
fetcher.return_value = True
63-
64-
df = dials_data.download.DataFetcher(read_only=True)
65-
ds = df("dataset", pathlib=True)
66-
assert ds == test_path / "dataset"
67-
68-
assert isinstance(ds, pathlib.Path)
69-
fetcher.assert_called_once_with(
70-
"dataset", pre_scan=True, read_only=False, verify=True
71-
)
72-
73-
with pytest.warns(DeprecationWarning):
74-
ds = df("dataset")
75-
assert pathlib.Path(ds).resolve() == test_path.joinpath("dataset").resolve()
76-
assert not isinstance(
77-
ds, pathlib.Path
78-
) # default is currently to return py.path.local()
79-
fetcher.assert_called_once_with(
80-
"dataset", pre_scan=True, read_only=False, verify=True
81-
)

0 commit comments

Comments
 (0)