Skip to content

Commit 55e09cd

Browse files
authored
fix: always pull versions from metadata (#782)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent c248a76 commit 55e09cd

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

nox/tox_to_nox.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@
2020
import os
2121
import pkgutil
2222
import re
23+
import sys
2324
from configparser import ConfigParser
2425
from pathlib import Path
2526
from subprocess import check_output
2627
from typing import Any, Iterable
2728

2829
import jinja2
2930
import tox.config
30-
from tox import __version__ as TOX_VERSION
3131

32-
TOX4 = TOX_VERSION[0] == "4"
32+
if sys.version_info < (3, 8):
33+
import importlib_metadata as metadata
34+
else:
35+
from importlib import metadata
36+
37+
TOX_VERSION = metadata.version("tox")
38+
39+
TOX4 = int(TOX_VERSION.split(".")[0]) >= 4
3340

3441
if TOX4:
3542
_TEMPLATE = jinja2.Template(

tests/test_tox_to_nox.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
import textwrap
1919

2020
import pytest
21-
from tox import __version__ as TOX_VERSION
2221

2322
tox_to_nox = pytest.importorskip("nox.tox_to_nox")
2423

25-
TOX4 = TOX_VERSION[0] == "4"
24+
TOX4 = tox_to_nox.TOX4
2625
PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}"
2726
PYTHON_VERSION_NODOT = PYTHON_VERSION.replace(".", "")
2827

tests/test_virtualenv.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@
2424
from unittest import mock
2525

2626
import pytest
27-
import virtualenv
2827
from packaging import version
2928

3029
import nox.virtualenv
3130

31+
if sys.version_info < (3, 8):
32+
import importlib_metadata as metadata
33+
else:
34+
from importlib import metadata
35+
3236
IS_WINDOWS = nox.virtualenv._SYSTEM == "Windows"
3337
HAS_CONDA = shutil.which("conda") is not None
3438
HAS_UV = shutil.which("uv") is not None
3539
RAISE_ERROR = "RAISE_ERROR"
36-
VIRTUALENV_VERSION = virtualenv.__version__
40+
VIRTUALENV_VERSION = metadata.version("virtualenv")
3741

3842

3943
class TextProcessResult(NamedTuple):

0 commit comments

Comments
 (0)