Skip to content

Commit

Permalink
Treat deprecation warnings as errors (#5244)
Browse files Browse the repository at this point in the history
* Treat deprecation warnings as errors
* Fix package_cache import
* Use root_prefix instead of root_dir
* Ignore numpy.distutils warning
  • Loading branch information
kenodegard authored Mar 26, 2024
1 parent 054309a commit 9267dae
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,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(context.root_dir).iter_records()
for prec in PrefixData(context.root_prefix).iter_records()
]
# Include the extra section of the metadata in the about.json
d["extra"] = extra
Expand Down
6 changes: 3 additions & 3 deletions conda_build/conda_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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.core.package_cache_data import ProgressiveFetchExtract # noqa: F401
from conda.exceptions import ( # noqa: F401
CondaError,
CondaHTTPError,
Expand Down Expand Up @@ -112,8 +112,8 @@
"24.5",
"24.7",
"root_dir",
context.root_dir,
addendum="Use `conda.base.context.context.root_dir` instead.",
context.root_prefix,
addendum="Use `conda.base.context.context.root_prefix` instead.",
)
deprecated.constant(
"24.5",
Expand Down
2 changes: 1 addition & 1 deletion conda_build/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def croot(self) -> str:
elif _bld_root_rc:
self._croot = abspath(expanduser(expandvars(_bld_root_rc)))
elif context.root_writable:
self._croot = join(context.root_dir, "conda-bld")
self._croot = join(context.root_prefix, "conda-bld")
else:
self._croot = abspath(expanduser("~/conda-bld"))
return self._croot
Expand Down
2 changes: 1 addition & 1 deletion conda_build/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def conda_build_vars(prefix, config):
"HTTP_PROXY": os.getenv("HTTP_PROXY", ""),
"REQUESTS_CA_BUNDLE": os.getenv("REQUESTS_CA_BUNDLE", ""),
"DIRTY": "1" if config.dirty else "",
"ROOT": context.root_dir,
"ROOT": context.root_prefix,
}


Expand Down
10 changes: 5 additions & 5 deletions conda_build/os_utils/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def find_executable(executable, prefix=None, all_matches=False):
result = None
if on_win:
dir_paths = [
join(context.root_dir, "Scripts"),
join(context.root_dir, "Library\\mingw-w64\\bin"),
join(context.root_dir, "Library\\usr\\bin"),
join(context.root_dir, "Library\\bin"),
join(context.root_prefix, "Scripts"),
join(context.root_prefix, "Library\\mingw-w64\\bin"),
join(context.root_prefix, "Library\\usr\\bin"),
join(context.root_prefix, "Library\\bin"),
]
if prefix:
dir_paths[0:0] = [
Expand All @@ -31,7 +31,7 @@ def find_executable(executable, prefix=None, all_matches=False):
]
else:
dir_paths = [
join(context.root_dir, "bin"),
join(context.root_prefix, "bin"),
]
if prefix:
dir_paths.insert(0, join(prefix, "bin"))
Expand Down
6 changes: 3 additions & 3 deletions conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
on_linux = sys.platform == "linux"

codec = getpreferredencoding() or "utf-8"
root_script_dir = os.path.join(context.root_dir, "Scripts" if on_win else "bin")
root_script_dir = os.path.join(context.root_prefix, "Scripts" if on_win else "bin")
mmap_MAP_PRIVATE = 0 if on_win else mmap.MAP_PRIVATE
mmap_PROT_READ = 0 if on_win else mmap.PROT_READ
mmap_PROT_WRITE = 0 if on_win else mmap.PROT_WRITE
Expand Down Expand Up @@ -708,7 +708,7 @@ def merge_tree(
# at any time, but the lock within this process should all be tied to the same tracking
# mechanism.
_lock_folders = (
os.path.join(context.root_dir, "locks"),
os.path.join(context.root_prefix, "locks"),
os.path.expanduser(os.path.join("~", ".conda_build_locks")),
)

Expand Down Expand Up @@ -1343,7 +1343,7 @@ class LoggingContext:
"dotupdate",
"stdoutlog",
"requests",
"conda.core.package_cache",
"conda.core.package_cache_data",
"conda.plan",
"conda.gateways.disk.delete",
"conda_build",
Expand Down
2 changes: 1 addition & 1 deletion news/5222-deprecating-conda_interface
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Deprecate `conda_build.conda_interface.envs_dirs` constant. Use `conda.base.context.context.envs_dirs` instead. (#5222)
* Deprecate `conda_build.conda_interface.pkgs_dirs` constant. Use `conda.base.context.context.pkgs_dirs` instead. (#5222)
* Deprecate `conda_build.conda_interface.cc_platform` constant. Use `conda.base.context.context.platform` instead. (#5222)
* Deprecate `conda_build.conda_interface.root_dir` constant. Use `conda.base.context.context.root_dir` instead. (#5222)
* Deprecate `conda_build.conda_interface.root_dir` constant. Use `conda.base.context.context.root_prefix` instead. (#5222)
* Deprecate `conda_build.conda_interface.root_writable` constant. Use `conda.base.context.context.root_writable` instead. (#5222)
* Deprecate `conda_build.conda_interface.subdir` constant. Use `conda.base.context.context.subdir` instead. (#5222)
* Deprecate `conda_build.conda_interface.create_default_packages` constant. Use `conda.base.context.context.create_default_packages` instead. (#5222)
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,13 @@ markers = [
"no_default_testing_config: used internally to disable monkeypatching for testing_config",
"benchmark: execute the benchmark tests",
]
filterwarnings = [
# elevate conda's deprecated warning to an error
"error::PendingDeprecationWarning:conda",
"error::DeprecationWarning:conda",
# elevate conda-build's deprecated warning to an error
"error::PendingDeprecationWarning:conda_build",
"error::DeprecationWarning:conda_build",
# ignore numpy.distutils error
'ignore:\s+`numpy.distutils` is deprecated:DeprecationWarning:conda_build._load_setup_py_data',
]
14 changes: 11 additions & 3 deletions tests/test_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import os
import sys

import pytest
from conda.core.prefix_data import PrefixData
from packaging.version import parse

from conda_build import environ
import conda_build
from conda_build.environ import Environment, create_env


def test_environment_creation_preserves_PATH(testing_workdir, testing_config):
ref_path = os.environ["PATH"]
environ.create_env(
create_env(
testing_workdir,
["python"],
env="host",
Expand All @@ -22,7 +25,12 @@ def test_environment_creation_preserves_PATH(testing_workdir, testing_config):

def test_environment():
"""Asserting PrefixData can accomplish the same thing as Environment."""
assert (specs := environ.Environment(sys.prefix).package_specs())
with pytest.warns(
PendingDeprecationWarning
if parse(conda_build.__version__) < parse("24.3")
else DeprecationWarning,
):
assert (specs := Environment(sys.prefix).package_specs())
assert specs == [
f"{prec.name} {prec.version} {prec.build}"
for prec in PrefixData(sys.prefix).iter_records()
Expand Down

0 comments on commit 9267dae

Please sign in to comment.