From 55e09cdeb8bdaa51f5bf4079926f47fbde5f8a07 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sat, 24 Feb 2024 10:08:29 -0500 Subject: [PATCH] fix: always pull versions from metadata (#782) Signed-off-by: Henry Schreiner --- nox/tox_to_nox.py | 11 +++++++++-- tests/test_tox_to_nox.py | 3 +-- tests/test_virtualenv.py | 8 ++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/nox/tox_to_nox.py b/nox/tox_to_nox.py index 37e184f2..36df7ed7 100644 --- a/nox/tox_to_nox.py +++ b/nox/tox_to_nox.py @@ -20,6 +20,7 @@ import os import pkgutil import re +import sys from configparser import ConfigParser from pathlib import Path from subprocess import check_output @@ -27,9 +28,15 @@ import jinja2 import tox.config -from tox import __version__ as TOX_VERSION -TOX4 = TOX_VERSION[0] == "4" +if sys.version_info < (3, 8): + import importlib_metadata as metadata +else: + from importlib import metadata + +TOX_VERSION = metadata.version("tox") + +TOX4 = int(TOX_VERSION.split(".")[0]) >= 4 if TOX4: _TEMPLATE = jinja2.Template( diff --git a/tests/test_tox_to_nox.py b/tests/test_tox_to_nox.py index 11815b79..50ab4f25 100644 --- a/tests/test_tox_to_nox.py +++ b/tests/test_tox_to_nox.py @@ -18,11 +18,10 @@ import textwrap import pytest -from tox import __version__ as TOX_VERSION tox_to_nox = pytest.importorskip("nox.tox_to_nox") -TOX4 = TOX_VERSION[0] == "4" +TOX4 = tox_to_nox.TOX4 PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}" PYTHON_VERSION_NODOT = PYTHON_VERSION.replace(".", "") diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index b5cf49a9..d3973b2a 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -24,16 +24,20 @@ from unittest import mock import pytest -import virtualenv from packaging import version import nox.virtualenv +if sys.version_info < (3, 8): + import importlib_metadata as metadata +else: + from importlib import metadata + IS_WINDOWS = nox.virtualenv._SYSTEM == "Windows" HAS_CONDA = shutil.which("conda") is not None HAS_UV = shutil.which("uv") is not None RAISE_ERROR = "RAISE_ERROR" -VIRTUALENV_VERSION = virtualenv.__version__ +VIRTUALENV_VERSION = metadata.version("virtualenv") class TextProcessResult(NamedTuple):