Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecating conda_build.conda_interface #5222

Merged
merged 23 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions conda_build/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

from .__version__ import __version__

__all__ = ["__version__"]
Expand All @@ -15,3 +16,17 @@
"render",
"skeleton",
]

# Skip context logic for doc generation since we don't install all dependencies in the CI doc build environment,
# see .readthedocs.yml file
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue this is a bug and needs to be resolved by installing all dependencies in the Ci doc build environment. Maybe add caching there? Switch to setup-miniconda?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but that will require that we stop using the RTD pipeline and switch to a custom workflow which is out of scope for this PR

try:
import os

from conda.base.context import reset_context

# Disallow softlinks. This avoids a lot of dumb issues, at the potential cost of disk space.
os.environ["CONDA_ALLOW_SOFTLINKS"] = "false"
reset_context()

except ImportError:
pass
Copy link
Member

@jezdez jezdez Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be run on every import of conda_build and seems like an overreach to fix a documentation rendering issue.

I would suggest to either

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to run for ALL imports of conda_build, it's only for docs rendering that we don't need this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I'd appreciate if we'd not have to handle the special case for the docs here though. Ultimately it's not a huge deal though.

22 changes: 10 additions & 12 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import yaml
from bs4 import UnicodeDammit
from conda import __version__ as conda_version
from conda.base.context import context, reset_context
from conda.core.prefix_data import PrefixData
from conda.models.channel import Channel

from . import __version__ as conda_build_version
from . import environ, noarch_python, source, tarcheck, utils
Expand All @@ -36,14 +38,8 @@
PathType,
TemporaryDirectory,
UnsatisfiableError,
context,
env_path_backup_var_exists,
get_conda_channel,
get_rc_urls,
pkgs_dirs,
prefix_placeholder,
reset_context,
root_dir,
url_path,
)
from .config import Config
Expand Down Expand Up @@ -1335,7 +1331,7 @@ def record_prefix_files(m, files_with_prefix):


def sanitize_channel(channel):
return get_conda_channel(channel).urls(with_credentials=False, subdirs=[""])[0]
return Channel.from_value(channel).urls(with_credentials=False, subdirs=[""])[0]


def write_info_files_file(m, files):
Expand Down Expand Up @@ -1407,7 +1403,7 @@ def write_about_json(m):
# conda env will be in most, but not necessarily all installations.
# Don't die if we don't see it.
stripped_channels = []
for channel in get_rc_urls() + list(m.config.channel_urls):
for channel in (*context.channels, *m.config.channel_urls):
stripped_channels.append(sanitize_channel(channel))
d["channels"] = stripped_channels
evars = ["CIO_TEST"]
Expand All @@ -1425,7 +1421,7 @@ def write_about_json(m):
extra.update(m.config.extra_meta)
d["root_pkgs"] = [
f"{prec.name} {prec.version} {prec.build}"
for prec in PrefixData(root_dir).iter_records()
for prec in PrefixData(context.root_dir).iter_records()
]
# Include the extra section of the metadata in the about.json
d["extra"] = extra
Expand Down Expand Up @@ -3389,7 +3385,7 @@ def test(
and recipedir_or_package_or_metadata.endswith(CONDA_PACKAGE_EXTENSIONS)
and any(
os.path.dirname(recipedir_or_package_or_metadata) in pkgs_dir
for pkgs_dir in pkgs_dirs
for pkgs_dir in context.pkgs_dirs
)
)
if not in_pkg_cache:
Expand Down Expand Up @@ -4161,8 +4157,10 @@ def is_package_built(metadata, env, include_local=True):
_delegated_update_index(d, verbose=metadata.config.debug, warn=False, threads=1)
subdir = getattr(metadata.config, f"{env}_subdir")

urls = [url_path(metadata.config.output_folder), "local"] if include_local else []
urls += get_rc_urls()
urls = [
*([url_path(metadata.config.output_folder), "local"] if include_local else []),
*context.channels,
]
if metadata.config.channel_urls:
urls.extend(metadata.config.channel_urls)

Expand Down
7 changes: 4 additions & 3 deletions conda_build/cli/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from typing import TYPE_CHECKING

from conda.auxlib.ish import dals
from conda.base.context import context
from conda.common.io import dashlist

from .. import api, build, source, utils
from ..conda_interface import add_parser_channels, binstar_upload, cc_conda_build
from ..conda_interface import add_parser_channels, cc_conda_build
from ..config import (
get_channel_urls,
get_or_merge_config,
Expand Down Expand Up @@ -55,14 +56,14 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
action="store_false",
help="Do not ask to upload the package to anaconda.org.",
dest="anaconda_upload",
default=binstar_upload,
default=context.binstar_upload,
)
parser.add_argument(
"--no-binstar-upload",
action="store_false",
help=argparse.SUPPRESS,
dest="anaconda_upload",
default=binstar_upload,
default=context.binstar_upload,
)
parser.add_argument(
"--no-include-recipe",
Expand Down
8 changes: 5 additions & 3 deletions conda_build/cli/main_metapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import logging
from typing import TYPE_CHECKING

from conda.base.context import context

from .. import api
from ..conda_interface import ArgumentParser, add_parser_channels, binstar_upload
from ..conda_interface import ArgumentParser, add_parser_channels

if TYPE_CHECKING:
from argparse import Namespace
Expand Down Expand Up @@ -35,14 +37,14 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
action="store_false",
help="Do not ask to upload the package to anaconda.org.",
dest="anaconda_upload",
default=binstar_upload,
default=context.binstar_upload,
)
parser.add_argument(
"--no-binstar-upload",
action="store_false",
help=argparse.SUPPRESS,
dest="anaconda_upload",
default=binstar_upload,
default=context.binstar_upload,
)
parser.add_argument("--token", help="Token to pass through to anaconda upload")
parser.add_argument(
Expand Down
124 changes: 104 additions & 20 deletions conda_build/conda_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from functools import partial
from importlib import import_module # noqa: F401

from conda import __version__ as CONDA_VERSION # noqa: F401
from conda.base.context import context, determine_target_prefix, reset_context
from conda import __version__
from conda.base.context import context, determine_target_prefix
from conda.base.context import non_x86_machines as non_x86_linux_machines # noqa: F401
from conda.base.context import reset_context as _reset_context
from conda.core.package_cache import ProgressiveFetchExtract # noqa: F401
from conda.exceptions import ( # noqa: F401
CondaError,
Expand Down Expand Up @@ -65,26 +66,100 @@
from .deprecations import deprecated

deprecated.constant("24.1.0", "24.5.0", "get_index", _get_index)
# TODO: Go to references of all properties below and import them from `context` instead
binstar_upload = context.binstar_upload
default_python = context.default_python
envs_dirs = context.envs_dirs
pkgs_dirs = list(context.pkgs_dirs)
cc_platform = context.platform
root_dir = context.root_dir
root_writable = context.root_writable
subdir = context.subdir
create_default_packages = context.create_default_packages

get_rc_urls = lambda: list(context.channels)
get_prefix = partial(determine_target_prefix, context)
cc_conda_build = context.conda_build if hasattr(context, "conda_build") else {}
deprecated.constant(
"24.5",
"24.7",
"reset_context",
_reset_context,
addendum="Use `conda.base.context.reset_context` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"binstar_upload",
context.binstar_upload,
addendum="Use `conda.base.context.context.binstar_upload` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"default_python",
context.default_python,
addendum="Use `conda.base.context.context.default_python` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"envs_dirs",
context.envs_dirs,
addendum="Use `conda.base.context.context.envs_dirs` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"pkgs_dirs",
list(context.pkgs_dirs),
addendum="Use `conda.base.context.context.pkgs_dirs` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"cc_platform",
context.platform,
addendum="Use `conda.base.context.context.platform` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"root_dir",
context.root_dir,
addendum="Use `conda.base.context.context.root_dir` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"root_writable",
context.root_writable,
addendum="Use `conda.base.context.context.root_writable` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"subdir",
context.subdir,
addendum="Use `conda.base.context.context.subdir` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"create_default_packages",
context.create_default_packages,
addendum="Use `conda.base.context.context.create_default_packages` instead.",
)

get_conda_channel = Channel.from_value
deprecated.constant(
"24.5",
"24.7",
"get_rc_urls",
lambda: list(context.channels),
addendum="Use `conda.base.context.context.channels` instead.",
)
deprecated.constant(
"24.5",
"24.7",
"get_prefix",
partial(determine_target_prefix, context),
addendum="Use `conda.base.context.context.target_prefix` instead.",
)
cc_conda_build = context.conda_build if hasattr(context, "conda_build") else {}

# Disallow softlinks. This avoids a lot of dumb issues, at the potential cost of disk space.
os.environ["CONDA_ALLOW_SOFTLINKS"] = "false"
reset_context()
deprecated.constant(
"24.5",
"24.7",
"get_conda_channel",
Channel.from_value,
addendum="Use `conda.models.channel.Channel.from_value` instead.",
)

# When deactivating envs (e.g. switching from root to build/test) this env var is used,
# except the PR that removed this has been reverted (for now) and Windows doesn't need it.
Expand Down Expand Up @@ -118,6 +193,15 @@ def md5_file(path: str | os.PathLike) -> str:
return compute_sum(path, "md5")


deprecated.constant(
"24.5",
"24.7",
"CONDA_VERSION",
__version__,
addendum="Use `conda.__version__` instead.",
)


@deprecated(
"24.3",
"24.5",
Expand Down
28 changes: 11 additions & 17 deletions conda_build/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
from os.path import abspath, expanduser, expandvars, join
from typing import TYPE_CHECKING

from .conda_interface import (
binstar_upload,
cc_conda_build,
cc_platform,
root_dir,
root_writable,
subdir,
url_path,
)
from conda.base.context import context

from .conda_interface import cc_conda_build, url_path
from .utils import (
get_build_folders,
get_conda_operation_locks,
Expand Down Expand Up @@ -88,7 +82,7 @@ def set_invocation_time():
def _get_default_settings():
return [
Setting("activate", True),
Setting("anaconda_upload", binstar_upload),
Setting("anaconda_upload", context.binstar_upload),
Setting("force_upload", True),
Setting("channel_urls", []),
Setting("dirty", False),
Expand Down Expand Up @@ -322,7 +316,7 @@ def set_lang(variant, lang):
def arch(self):
"""Always the native (build system) arch, except when pretending to be some
other platform"""
return self._arch or subdir.rsplit("-", 1)[1]
return self._arch or context.subdir.rsplit("-", 1)[1]

@arch.setter
def arch(self, value):
Expand All @@ -338,7 +332,7 @@ def arch(self, value):
def platform(self):
"""Always the native (build system) OS, except when pretending to be some
other platform"""
return self._platform or subdir.rsplit("-", 1)[0]
return self._platform or context.subdir.rsplit("-", 1)[0]

@platform.setter
def platform(self, value):
Expand Down Expand Up @@ -381,8 +375,8 @@ def noarch(self):
return self.host_platform == "noarch"

def reset_platform(self):
if not self.platform == cc_platform:
self.platform = cc_platform
if not self.platform == context.platform:
self.platform = context.platform

@property
def subdir(self):
Expand Down Expand Up @@ -460,8 +454,8 @@ def croot(self) -> str:
self._croot = abspath(expanduser(_bld_root_env))
elif _bld_root_rc:
self._croot = abspath(expanduser(expandvars(_bld_root_rc)))
elif root_writable:
self._croot = join(root_dir, "conda-bld")
elif context.root_writable:
self._croot = join(context.root_dir, "conda-bld")
else:
self._croot = abspath(expanduser("~/conda-bld"))
return self._croot
Expand Down Expand Up @@ -718,7 +712,7 @@ def bldpkgs_dirs(self):
# subdir should be the native platform, while self.subdir would be the host platform.
return {
join(self.croot, self.host_subdir),
join(self.croot, subdir),
join(self.croot, context.subdir),
join(self.croot, "noarch"),
}

Expand Down
Loading
Loading