From b230e5e20412ad86ac6a9ab113420aba3cc6cdbd Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Mon, 6 Nov 2023 01:29:36 -0500 Subject: [PATCH] Convert all absolute imports to relative (#13281) --- conda/_vendor/cpuinfo/__init__.py | 2 +- conda/base/context.py | 2 +- conda/common/io.py | 2 +- conda/common/pkg_formats/python.py | 3 +- conda/core/index.py | 2 +- conda/core/package_cache_data.py | 3 +- conda/core/solve.py | 3 +- conda/core/subdir_data.py | 25 +++++------ conda/exceptions.py | 3 +- conda/gateways/connection/adapters/ftp.py | 3 +- conda/gateways/connection/download.py | 3 +- conda/gateways/disk/create.py | 6 +-- conda/gateways/disk/delete.py | 4 +- conda/gateways/disk/lock.py | 2 +- conda/gateways/repodata/jlap/fetch.py | 7 ++- conda/gateways/repodata/jlap/interface.py | 7 ++- conda/gateways/repodata/lock.py | 2 +- conda/gateways/subprocess.py | 3 +- conda/history.py | 3 +- conda/models/match_spec.py | 3 +- .../subcommands/doctor/health_checks.py | 6 +-- conda/resolve.py | 3 +- conda/testing/__init__.py | 13 +++--- conda/testing/fixtures.py | 14 +++--- conda/testing/helpers.py | 4 +- conda/testing/integration.py | 44 +++++++++---------- conda/testing/notices/fixtures.py | 4 +- conda/testing/notices/helpers.py | 10 ++--- conda/utils.py | 2 +- 29 files changed, 87 insertions(+), 101 deletions(-) diff --git a/conda/_vendor/cpuinfo/__init__.py b/conda/_vendor/cpuinfo/__init__.py index a9c4e1f91c5..d31a43e0a10 100644 --- a/conda/_vendor/cpuinfo/__init__.py +++ b/conda/_vendor/cpuinfo/__init__.py @@ -1,5 +1,5 @@ import sys -from conda._vendor.cpuinfo.cpuinfo import * +from .cpuinfo import * diff --git a/conda/base/context.py b/conda/base/context.py index a5a33295534..872307b8835 100644 --- a/conda/base/context.py +++ b/conda/base/context.py @@ -1093,7 +1093,7 @@ def os_distribution_name_version(self): # 'Windows', '10.0.17134' platform_name = self.platform_system_release[0] if platform_name == "Linux": - from conda._vendor.distro import id, version + from .._vendor.distro import id, version try: distinfo = id(), version(best=True) diff --git a/conda/common/io.py b/conda/common/io.py index 66eaf5c9561..2f2a459a6be 100644 --- a/conda/common/io.py +++ b/conda/common/io.py @@ -148,7 +148,7 @@ def env_vars(var_map=None, callback=None, stack_callback=None): @contextmanager def env_var(name, value, callback=None, stack_callback=None): # Maybe, but in env_vars, not here: - # from conda.common.compat import ensure_fs_path_encoding + # from .compat import ensure_fs_path_encoding # d = dict({name: ensure_fs_path_encoding(value)}) d = {name: value} with env_vars(d, callback=callback, stack_callback=stack_callback) as es: diff --git a/conda/common/pkg_formats/python.py b/conda/common/pkg_formats/python.py index 409b9ccf260..c8d908ac188 100644 --- a/conda/common/pkg_formats/python.py +++ b/conda/common/pkg_formats/python.py @@ -18,12 +18,11 @@ from os.path import basename, dirname, isdir, isfile, join, lexists from posixpath import normpath as posix_normpath -from conda.common.iterators import groupby_to_dict as groupby - from ... import CondaError from ..._vendor.frozendict import frozendict from ...auxlib.decorators import memoizedproperty from ..compat import open +from ..iterators import groupby_to_dict as groupby from ..path import ( get_major_minor_version, get_python_site_packages_short_path, diff --git a/conda/core/index.py b/conda/core/index.py index 31415cf2ff5..6d907aca0e4 100644 --- a/conda/core/index.py +++ b/conda/core/index.py @@ -180,7 +180,7 @@ def _supplement_index_with_system(index): def get_archspec_name(): - from conda.base.context import _arch_names, _platform_map, non_x86_machines + from ..base.context import _arch_names, _platform_map, non_x86_machines target_plat, target_arch = context.subdir.split("-") # This has to reverse what Context.subdir is doing diff --git a/conda/core/package_cache_data.py b/conda/core/package_cache_data.py index b0a7b33f884..fae2b283ca3 100644 --- a/conda/core/package_cache_data.py +++ b/conda/core/package_cache_data.py @@ -17,8 +17,6 @@ from sys import platform from tarfile import ReadError -from conda.common.iterators import groupby_to_dict as groupby - from .. import CondaError, CondaMultiError, conda_signal_handler from ..auxlib.collection import first from ..auxlib.decorators import memoizemethod @@ -31,6 +29,7 @@ from ..base.context import context from ..common.constants import NULL from ..common.io import IS_INTERACTIVE, ProgressBar, time_recorder +from ..common.iterators import groupby_to_dict as groupby from ..common.path import expand, strip_pkg_extension, url_to_path from ..common.signals import signal_handler from ..common.url import path_to_url diff --git a/conda/core/solve.py b/conda/core/solve.py index dc23df4e43e..35482089d2c 100644 --- a/conda/core/solve.py +++ b/conda/core/solve.py @@ -15,8 +15,6 @@ except ImportError: # pragma: no cover from .._vendor.boltons.setutils import IndexedSet -from conda.common.iterators import groupby_to_dict as groupby - from .. import CondaError from .. import __version__ as CONDA_VERSION from ..auxlib.decorators import memoizedproperty @@ -25,6 +23,7 @@ from ..base.context import context from ..common.constants import NULL from ..common.io import Spinner, dashlist, time_recorder +from ..common.iterators import groupby_to_dict as groupby from ..common.path import get_major_minor_version, paths_equal from ..exceptions import ( PackagesNotFoundError, diff --git a/conda/core/subdir_data.py b/conda/core/subdir_data.py index c1116611e48..67a6bd236bd 100644 --- a/conda/core/subdir_data.py +++ b/conda/core/subdir_data.py @@ -20,7 +20,17 @@ except ImportError: # pragma: no cover from .._vendor.boltons.setutils import IndexedSet -from conda.gateways.repodata import ( +from ..auxlib.ish import dals +from ..base.constants import CONDA_PACKAGE_EXTENSION_V1, REPODATA_FN +from ..base.context import context +from ..common.io import DummyExecutor, ThreadLimitedThreadPoolExecutor, dashlist +from ..common.iterators import groupby_to_dict as groupby +from ..common.path import url_to_path +from ..common.url import join_url +from ..deprecations import deprecated +from ..exceptions import CondaUpgradeError, UnavailableInvalidChannel +from ..gateways.disk.delete import rm_rf +from ..gateways.repodata import ( CACHE_STATE_SUFFIX, CondaRepoInterface, RepodataCache, @@ -32,20 +42,9 @@ create_cache_dir, get_repo_interface, ) -from conda.gateways.repodata import ( +from ..gateways.repodata import ( get_cache_control_max_age as _get_cache_control_max_age, ) - -from ..auxlib.ish import dals -from ..base.constants import CONDA_PACKAGE_EXTENSION_V1, REPODATA_FN -from ..base.context import context -from ..common.io import DummyExecutor, ThreadLimitedThreadPoolExecutor, dashlist -from ..common.iterators import groupby_to_dict as groupby -from ..common.path import url_to_path -from ..common.url import join_url -from ..deprecations import deprecated -from ..exceptions import CondaUpgradeError, UnavailableInvalidChannel -from ..gateways.disk.delete import rm_rf from ..models.channel import Channel, all_channel_urls from ..models.match_spec import MatchSpec from ..models.records import PackageRecord diff --git a/conda/exceptions.py b/conda/exceptions.py index de465f2084c..6c0c131cec6 100644 --- a/conda/exceptions.py +++ b/conda/exceptions.py @@ -15,8 +15,6 @@ import requests from requests.exceptions import JSONDecodeError -from conda.common.iterators import groupby_to_dict as groupby - from . import CondaError, CondaExitZero, CondaMultiError from .auxlib.entity import EntityEncoder from .auxlib.ish import dals @@ -24,6 +22,7 @@ from .base.constants import COMPATIBLE_SHELLS, PathConflict, SafetyChecks from .common.compat import on_win from .common.io import dashlist +from .common.iterators import groupby_to_dict as groupby from .common.signals import get_signal_name from .common.url import join_url, maybe_unquote from .deprecations import DeprecatedError # noqa: F401 diff --git a/conda/gateways/connection/adapters/ftp.py b/conda/gateways/connection/adapters/ftp.py index 51e36afa76e..6e967337b2e 100644 --- a/conda/gateways/connection/adapters/ftp.py +++ b/conda/gateways/connection/adapters/ftp.py @@ -22,9 +22,8 @@ from io import BytesIO, StringIO from logging import getLogger -from conda.deprecations import deprecated - from ....common.url import urlparse +from ....deprecations import deprecated from ....exceptions import AuthenticationError from .. import BaseAdapter, Response, dispatch_hook diff --git a/conda/gateways/connection/download.py b/conda/gateways/connection/download.py index fabd108cbeb..3b9f6c5cfef 100644 --- a/conda/gateways/connection/download.py +++ b/conda/gateways/connection/download.py @@ -12,8 +12,6 @@ from os.path import basename, exists, join from pathlib import Path -from conda.gateways.disk.lock import lock - from ... import CondaError from ...auxlib.ish import dals from ...auxlib.logz import stringify @@ -29,6 +27,7 @@ maybe_raise, ) from ..disk.delete import rm_rf +from ..disk.lock import lock from . import ( ConnectionError, HTTPError, diff --git a/conda/gateways/disk/create.py b/conda/gateways/disk/create.py index 8cc2192c2ed..8ed79389931 100644 --- a/conda/gateways/disk/create.py +++ b/conda/gateways/disk/create.py @@ -427,11 +427,11 @@ def compile_multiple_pyc( command[0:0] = [python_exe_full_path] # command[0:0] = ['--cwd', prefix, '--dev', '-p', prefix, python_exe_full_path] log.trace(command) - from conda.gateways.subprocess import any_subprocess + from ..subprocess import any_subprocess - # from conda.common.io import env_vars + # from ...common.io import env_vars # This stack does not maintain its _argparse_args correctly? - # from conda.base.context import stack_context_default + # from ...base.context import stack_context_default # with env_vars({}, stack_context_default): # stdout, stderr, rc = run_command(Commands.RUN, *command) stdout, stderr, rc = any_subprocess(command, prefix) diff --git a/conda/gateways/disk/delete.py b/conda/gateways/disk/delete.py index 11b09385c7b..d0e10ce66be 100644 --- a/conda/gateways/disk/delete.py +++ b/conda/gateways/disk/delete.py @@ -55,8 +55,8 @@ def rmtree(path, *args, **kwargs): try: # Try to delete in Unicode name = None - from conda.auxlib.compat import Utf8NamedTemporaryFile - from conda.utils import quote_for_shell + from ...auxlib.compat import Utf8NamedTemporaryFile + from ...utils import quote_for_shell with Utf8NamedTemporaryFile( mode="w", suffix=".bat", delete=False diff --git a/conda/gateways/disk/lock.py b/conda/gateways/disk/lock.py index f8eb369d5ab..ecb0502ae18 100644 --- a/conda/gateways/disk/lock.py +++ b/conda/gateways/disk/lock.py @@ -9,7 +9,7 @@ import warnings from contextlib import contextmanager -from conda.base.context import context +from ...base.context import context LOCK_BYTE = 21 # mamba interop LOCK_ATTEMPTS = 10 diff --git a/conda/gateways/repodata/jlap/fetch.py b/conda/gateways/repodata/jlap/fetch.py index 1c718c4d604..350ee43943d 100644 --- a/conda/gateways/repodata/jlap/fetch.py +++ b/conda/gateways/repodata/jlap/fetch.py @@ -18,15 +18,14 @@ import zstandard from requests import HTTPError -from conda.base.context import context -from conda.gateways.connection import Response, Session -from conda.gateways.repodata import ( +from ....base.context import context +from ...connection import Response, Session +from .. import ( ETAG_KEY, LAST_MODIFIED_KEY, RepodataCache, RepodataState, ) - from .core import JLAP log = logging.getLogger(__name__) diff --git a/conda/gateways/repodata/jlap/interface.py b/conda/gateways/repodata/jlap/interface.py index 063e01aa869..01708b188af 100644 --- a/conda/gateways/repodata/jlap/interface.py +++ b/conda/gateways/repodata/jlap/interface.py @@ -6,10 +6,9 @@ import logging import os -from conda.base.context import context -from conda.gateways.connection.download import disable_ssl_verify_warning -from conda.gateways.connection.session import get_session - +from ....base.context import context +from ...connection.download import disable_ssl_verify_warning +from ...connection.session import get_session from .. import ( CACHE_CONTROL_KEY, ETAG_KEY, diff --git a/conda/gateways/repodata/lock.py b/conda/gateways/repodata/lock.py index 5b37349654a..31f0be92d22 100644 --- a/conda/gateways/repodata/lock.py +++ b/conda/gateways/repodata/lock.py @@ -5,4 +5,4 @@ Moved to prevent circular imports. """ -from conda.gateways.disk.lock import lock # noqa +from ..disk.lock import lock # noqa: F401 diff --git a/conda/gateways/subprocess.py b/conda/gateways/subprocess.py index 7bc8f2438d4..8b86394e9e1 100644 --- a/conda/gateways/subprocess.py +++ b/conda/gateways/subprocess.py @@ -8,9 +8,8 @@ from os.path import abspath from subprocess import PIPE, CalledProcessError, Popen -from conda.auxlib.compat import shlex_split_unicode - from .. import ACTIVE_SUBPROCESSES +from ..auxlib.compat import shlex_split_unicode from ..auxlib.ish import dals from ..base.context import context from ..common.compat import encode_arguments, encode_environment, isiterable diff --git a/conda/history.py b/conda/history.py index 2cec323a371..ead286e074f 100644 --- a/conda/history.py +++ b/conda/history.py @@ -17,13 +17,12 @@ from os.path import isdir, isfile, join from textwrap import dedent -from conda.common.iterators import groupby_to_dict as groupby - from . import __version__ as CONDA_VERSION from .auxlib.ish import dals from .base.constants import DEFAULTS_CHANNEL_NAME from .base.context import context from .common.compat import ensure_text_type, open +from .common.iterators import groupby_to_dict as groupby from .common.path import paths_equal from .core.prefix_data import PrefixData from .exceptions import CondaHistoryError, NotWritableError diff --git a/conda/models/match_spec.py b/conda/models/match_spec.py index 4a0f98ddb86..de3bba89254 100644 --- a/conda/models/match_spec.py +++ b/conda/models/match_spec.py @@ -15,14 +15,13 @@ from operator import attrgetter from os.path import basename -from conda.common.iterators import groupby_to_dict as groupby - from ..auxlib.collection import frozendict from ..auxlib.decorators import memoizedproperty from ..base.constants import CONDA_PACKAGE_EXTENSION_V1, CONDA_PACKAGE_EXTENSION_V2 from ..base.context import context from ..common.compat import isiterable from ..common.io import dashlist +from ..common.iterators import groupby_to_dict as groupby from ..common.path import expand, is_package_file, strip_pkg_extension, url_to_path from ..common.url import is_url, path_to_url, unquote from ..exceptions import CondaValueError, InvalidMatchSpec diff --git a/conda/plugins/subcommands/doctor/health_checks.py b/conda/plugins/subcommands/doctor/health_checks.py index 6774ce6f1f5..c5c48c00e30 100644 --- a/conda/plugins/subcommands/doctor/health_checks.py +++ b/conda/plugins/subcommands/doctor/health_checks.py @@ -7,9 +7,9 @@ from logging import getLogger from pathlib import Path -from conda.core.envs_manager import get_user_environments_txt_file -from conda.exceptions import CondaError -from conda.gateways.disk.read import compute_sum +from ....core.envs_manager import get_user_environments_txt_file +from ....exceptions import CondaError +from ....gateways.disk.read import compute_sum logger = getLogger(__name__) diff --git a/conda/resolve.py b/conda/resolve.py index fa775f847be..01bf4efe35c 100644 --- a/conda/resolve.py +++ b/conda/resolve.py @@ -14,14 +14,13 @@ from tqdm import tqdm -from conda.common.iterators import groupby_to_dict as groupby - from ._vendor.frozendict import FrozenOrderedDict as frozendict from .auxlib.decorators import memoizemethod from .base.constants import MAX_CHANNEL_PRIORITY, ChannelPriority, SatSolverChoice from .base.context import context from .common.compat import on_win from .common.io import dashlist, time_recorder +from .common.iterators import groupby_to_dict as groupby from .common.logic import ( TRUE, Clauses, diff --git a/conda/testing/__init__.py b/conda/testing/__init__.py index 37d41710ed2..2c5d3922b65 100644 --- a/conda/testing/__init__.py +++ b/conda/testing/__init__.py @@ -28,10 +28,9 @@ import pytest from pytest import CaptureFixture -from conda.base.context import context, reset_context -from conda.cli.main import init_loggers -from conda.common.compat import on_win - +from ..base.context import context, reset_context +from ..cli.main import init_loggers +from ..common.compat import on_win from ..deprecations import deprecated @@ -73,7 +72,7 @@ def conda_ensure_sys_python_is_base_env_python(): def conda_move_to_front_of_PATH(): if "CONDA_PREFIX" in os.environ: - from conda.activate import CmdExeActivator, PosixActivator + from ..activate import CmdExeActivator, PosixActivator if os.name == "nt": activator_cls = CmdExeActivator @@ -147,7 +146,7 @@ def conda_check_versions_aligned(): try: cmd = join(pe, git_exe) + " describe --tags --long" version_from_git = check_output(cmd).decode("utf-8").split("\n")[0] - from conda.auxlib.packaging import _get_version_from_git_tag + from ..auxlib.packaging import _get_version_from_git_tag version_from_git = _get_version_from_git_tag(version_from_git) break @@ -203,7 +202,7 @@ def __call__(self, *argv: str) -> tuple[str, str, int]: # all other subcommands else: - from conda.cli.main import main_subshell + from ..cli.main import main_subshell # run command code = main_subshell(*argv) diff --git a/conda/testing/fixtures.py b/conda/testing/fixtures.py index 4fa2dccb6b0..1f6c94526f6 100644 --- a/conda/testing/fixtures.py +++ b/conda/testing/fixtures.py @@ -6,13 +6,13 @@ import py import pytest -from conda.auxlib.ish import dals -from conda.base.context import conda_tests_ctxt_mgmt_def_pol, context, reset_context -from conda.common.configuration import YamlRawParameter -from conda.common.io import env_vars -from conda.common.serialize import yaml_round_trip_load -from conda.core.subdir_data import SubdirData -from conda.gateways.disk.create import TemporaryDirectory +from ..auxlib.ish import dals +from ..base.context import conda_tests_ctxt_mgmt_def_pol, context, reset_context +from ..common.configuration import YamlRawParameter +from ..common.io import env_vars +from ..common.serialize import yaml_round_trip_load +from ..core.subdir_data import SubdirData +from ..gateways.disk.create import TemporaryDirectory @pytest.fixture(autouse=True) diff --git a/conda/testing/helpers.py b/conda/testing/helpers.py index 69adc27fd4f..e6b11db3684 100644 --- a/conda/testing/helpers.py +++ b/conda/testing/helpers.py @@ -15,17 +15,17 @@ import pytest -from conda.auxlib.compat import shlex_split_unicode -from conda.deprecations import deprecated from conda_env.cli import main as conda_env_cli from .. import cli +from ..auxlib.compat import shlex_split_unicode from ..base.context import conda_tests_ctxt_mgmt_def_pol, context, reset_context from ..common.compat import encode_arguments from ..common.io import argv, env_var from ..common.io import captured as common_io_captured from ..core.prefix_data import PrefixData from ..core.subdir_data import SubdirData, make_feature_record +from ..deprecations import deprecated from ..gateways.disk.delete import rm_rf from ..gateways.disk.read import lexists from ..gateways.logging import initialize_logging diff --git a/conda/testing/integration.py b/conda/testing/integration.py index 3b61e00b977..7120e750a7e 100644 --- a/conda/testing/integration.py +++ b/conda/testing/integration.py @@ -21,14 +21,14 @@ import pytest -from conda.auxlib.compat import Utf8NamedTemporaryFile -from conda.auxlib.entity import EntityEncoder -from conda.base.constants import PACKAGE_CACHE_MAGIC_FILE -from conda.base.context import conda_tests_ctxt_mgmt_def_pol, context, reset_context -from conda.cli.conda_argparse import do_call, generate_parser -from conda.cli.main import init_loggers -from conda.common.compat import encode_arguments, on_win -from conda.common.io import ( +from ..auxlib.compat import Utf8NamedTemporaryFile +from ..auxlib.entity import EntityEncoder +from ..base.constants import PACKAGE_CACHE_MAGIC_FILE +from ..base.context import conda_tests_ctxt_mgmt_def_pol, context, reset_context +from ..cli.conda_argparse import do_call, generate_parser +from ..cli.main import init_loggers +from ..common.compat import encode_arguments, on_win +from ..common.io import ( argv, captured, dashlist, @@ -36,19 +36,19 @@ env_var, stderr_log_level, ) -from conda.common.url import path_to_url -from conda.core.package_cache_data import PackageCacheData -from conda.core.prefix_data import PrefixData -from conda.deprecations import deprecated -from conda.exceptions import conda_exception_handler -from conda.gateways.disk.create import mkdir_p -from conda.gateways.disk.delete import rm_rf -from conda.gateways.disk.link import link -from conda.gateways.disk.update import touch -from conda.gateways.logging import DEBUG -from conda.models.match_spec import MatchSpec -from conda.models.records import PackageRecord -from conda.utils import massage_arguments +from ..common.url import path_to_url +from ..core.package_cache_data import PackageCacheData +from ..core.prefix_data import PrefixData +from ..deprecations import deprecated +from ..exceptions import conda_exception_handler +from ..gateways.disk.create import mkdir_p +from ..gateways.disk.delete import rm_rf +from ..gateways.disk.link import link +from ..gateways.disk.update import touch +from ..gateways.logging import DEBUG +from ..models.match_spec import MatchSpec +from ..models.records import PackageRecord +from ..utils import massage_arguments TEST_LOG_LEVEL = DEBUG PYTHON_BINARY = "python.exe" if on_win else "bin/python" @@ -264,7 +264,7 @@ def run_command(command, prefix, *arguments, **kwargs): arguments.insert(1, "--debug-wrapper-scripts") # It would be nice at this point to re-use: - # from conda.cli.python_api import run_command as python_api_run_command + # from ..cli.python_api import run_command as python_api_run_command # python_api_run_command # .. but that does not support no_capture and probably more stuff. diff --git a/conda/testing/notices/fixtures.py b/conda/testing/notices/fixtures.py index 98a3108b76c..26725f04cbb 100644 --- a/conda/testing/notices/fixtures.py +++ b/conda/testing/notices/fixtures.py @@ -6,8 +6,8 @@ import pytest -from conda.base.constants import NOTICES_CACHE_SUBDIR -from conda.cli import conda_argparse +from ...base.constants import NOTICES_CACHE_SUBDIR +from ...cli import conda_argparse @pytest.fixture(scope="function") diff --git a/conda/testing/notices/helpers.py b/conda/testing/notices/helpers.py index a3d6cb1d49d..70a13b17e15 100644 --- a/conda/testing/notices/helpers.py +++ b/conda/testing/notices/helpers.py @@ -12,11 +12,11 @@ from typing import Sequence from unittest import mock -from conda.base.context import Context -from conda.models.channel import get_channel_objs -from conda.notices.cache import get_notices_cache_file -from conda.notices.core import get_channel_name_and_urls -from conda.notices.types import ChannelNoticeResponse +from ...base.context import Context +from ...models.channel import get_channel_objs +from ...notices.cache import get_notices_cache_file +from ...notices.core import get_channel_name_and_urls +from ...notices.types import ChannelNoticeResponse DEFAULT_NOTICE_MESG = "Here is an example message that will be displayed to users" diff --git a/conda/utils.py b/conda/utils.py index bc340fb1002..f06d3dc33d5 100644 --- a/conda/utils.py +++ b/conda/utils.py @@ -383,7 +383,7 @@ def wrap_subprocess_call( if on_win: comspec = get_comspec() # fail early with KeyError if undefined if dev_mode: - from conda import CONDA_PACKAGE_ROOT + from . import CONDA_PACKAGE_ROOT conda_bat = join(CONDA_PACKAGE_ROOT, "shell", "condabin", "conda.bat") else: