Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5c1b0df

Browse files
committedAug 29, 2022
test on 3.11
We don't have aiohttp support yet, due to which we have to install without cythonized extension. Similarly, there has been some changes in how dataclasses disallows some mutable arguments to be set as a class property, due to which `hydra.conf` fails to import in 3.11. See python/cpython#29867. For now, I have patched the module and avoid importing as a pytest-plugin. dvc-hdfs/pyarrow is not there yet, we'll usually see a release 2-3 months after official reelase. dvc-hdfs is skipped in 3.11 in extras_requires. `--set-params` will return a nice error message if hydra cannot be imported in 3.11. I decided to only patch that in tests.
1 parent 9e2ebe9 commit 5c1b0df

File tree

7 files changed

+58
-27
lines changed

7 files changed

+58
-27
lines changed
 

‎.github/workflows/tests.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
matrix:
4444
os: [ubuntu-20.04, windows-latest, macos-latest]
4545
pyv: ["3.8", "3.9", "3.10"]
46+
include:
47+
- {os: ubuntu-latest, pyv: "3.11-dev"}
48+
4649
steps:
4750
- uses: actions/checkout@v3
4851
with:
@@ -68,6 +71,8 @@ jobs:
6871
run: |
6972
pip install --upgrade pip setuptools wheel
7073
pip install -e ".[dev]"
74+
env:
75+
AIOHTTP_NO_EXTENSIONS: ${{ matrix.pyv == '3.11-dev' && '1' }}
7176
- name: run tests
7277
timeout-minutes: 40
7378
run: >-

‎dvc/repo/experiments/queue/base.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import sys
34
from abc import ABC, abstractmethod
45
from dataclasses import asdict, dataclass
56
from typing import (
@@ -524,7 +525,14 @@ def _update_params(self, params: Dict[str, List[str]]):
524525
"""
525526
logger.debug("Using experiment params '%s'", params)
526527

527-
from dvc.utils.hydra import apply_overrides
528+
try:
529+
from dvc.utils.hydra import apply_overrides
530+
except ValueError:
531+
if sys.version_info >= (3, 11):
532+
raise DvcException(
533+
"--set-param is not supported in Python >= 3.11"
534+
)
535+
raise
528536

529537
for path, overrides in params.items():
530538
apply_overrides(path, overrides)

‎pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ line_length = 79
3030

3131
[tool.pytest.ini_options]
3232
log_level = "debug"
33-
addopts = "-ra"
33+
addopts = "-ra -p no:hydra_pytest"
3434
markers = [
3535
"needs_internet: Might need network access for the tests",
36-
"vscode: Tests verifying contract between DVC and VSCode plugin",
37-
"studio: Tests verifying contract between DVC and Studio"
36+
"vscode: Tests verifying contract between DVC and VSCode plugin",
37+
"studio: Tests verifying contract between DVC and Studio",
3838
]
3939
xfail_strict = true
4040

‎setup.cfg

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ install_requires =
6262
rich>=10.13.0
6363
pyparsing>=2.4.7
6464
typing-extensions>=3.7.4
65-
fsspec[http]>=2021.10.1
66-
aiohttp-retry>=2.4.5
6765
scmrepo==0.0.25
6866
dvc-render==0.0.9
6967
dvc-task==0.1.2
@@ -91,7 +89,7 @@ dev =
9189
azure = dvc-azure==2.19.0
9290
gdrive = dvc-gdrive==2.19.0
9391
gs = dvc-gs==2.19.1
94-
hdfs = dvc-hdfs==2.19.0
92+
hdfs = dvc-hdfs==2.19.0; python_version < '3.11'
9593
oss = dvc-oss==2.19.0
9694
s3 = dvc-s3==2.19.0
9795
ssh = dvc-ssh==2.19.0

‎tests/conftest.py

+12
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,15 @@ def run(
250250
return stage
251251

252252
return run
253+
254+
255+
@pytest.fixture(autouse=True)
256+
def mock_hydra_conf(mocker):
257+
if sys.version_info < (3, 11):
258+
return
259+
260+
# `hydra.conf` fails to import in 3.11, it raises ValueError due to changes
261+
# in dataclasses. See https://github.com/python/cpython/pull/29867.
262+
# NOTE: using sentinel here so that any imports from `hydra.conf`
263+
# return a mock.
264+
sys.modules["hydra.conf"] = mocker.sentinel

‎tests/func/utils/test_hydra.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
from dvc.exceptions import InvalidArgumentError
4-
from dvc.utils.hydra import apply_overrides
54

65

76
@pytest.mark.parametrize("suffix", ["yaml", "toml", "json"])
@@ -90,6 +89,8 @@
9089
],
9190
)
9291
def test_apply_overrides(tmp_dir, suffix, overrides, expected):
92+
from dvc.utils.hydra import apply_overrides
93+
9394
if suffix == "toml":
9495
if overrides in [
9596
["foo=baz"],
@@ -114,6 +115,8 @@ def test_apply_overrides(tmp_dir, suffix, overrides, expected):
114115
[["foobar=2"], ["lorem=3,2"], ["+lorem=3"], ["foo[0]=bar"]],
115116
)
116117
def test_invalid_overrides(tmp_dir, overrides):
118+
from dvc.utils.hydra import apply_overrides
119+
117120
params_file = tmp_dir / "params.yaml"
118121
params_file.dump(
119122
{"foo": [{"bar": 1}, {"baz": 2}], "goo": {"bag": 3.0}, "lorem": False}

‎tests/unit/fs/test_fs.py

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
import pytest
2-
from dvc_hdfs import HDFSFileSystem
32
from dvc_http import HTTPFileSystem, HTTPSFileSystem
43
from dvc_s3 import S3FileSystem
54
from dvc_ssh import SSHFileSystem
65

76
from dvc.config import RemoteNotFoundError
87
from dvc.fs import LocalFileSystem, get_fs_cls, get_fs_config
98

9+
url_cls_pairs = [
10+
("s3://bucket/path", S3FileSystem),
11+
("ssh://example.com:/dir/path", SSHFileSystem),
12+
("http://example.com/path/to/file", HTTPFileSystem),
13+
("https://example.com/path/to/file", HTTPSFileSystem),
14+
("path/to/file", LocalFileSystem),
15+
("path\\to\\file", LocalFileSystem),
16+
("file", LocalFileSystem),
17+
("./file", LocalFileSystem),
18+
(".\\file", LocalFileSystem),
19+
("../file", LocalFileSystem),
20+
("..\\file", LocalFileSystem),
21+
("unknown://path", LocalFileSystem),
22+
]
1023

11-
@pytest.mark.parametrize(
12-
"url, cls",
13-
[
14-
("s3://bucket/path", S3FileSystem),
15-
("ssh://example.com:/dir/path", SSHFileSystem),
16-
("hdfs://example.com/dir/path", HDFSFileSystem),
17-
("http://example.com/path/to/file", HTTPFileSystem),
18-
("https://example.com/path/to/file", HTTPSFileSystem),
19-
("path/to/file", LocalFileSystem),
20-
("path\\to\\file", LocalFileSystem),
21-
("file", LocalFileSystem),
22-
("./file", LocalFileSystem),
23-
(".\\file", LocalFileSystem),
24-
("../file", LocalFileSystem),
25-
("..\\file", LocalFileSystem),
26-
("unknown://path", LocalFileSystem),
27-
],
28-
)
24+
25+
try:
26+
from dvc_hdfs import HDFSFileSystem
27+
28+
url_cls_pairs += [("hdfs://example.com/dir/path", HDFSFileSystem)]
29+
except ImportError:
30+
pass
31+
32+
33+
@pytest.mark.parametrize("url, cls", url_cls_pairs)
2934
def test_get_fs_cls(url, cls):
3035
assert get_fs_cls({"url": url}) == cls
3136

0 commit comments

Comments
 (0)
Please sign in to comment.