From 81f43918907719ac2051ff59a473b3decfeacb5c Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Tue, 9 Jul 2024 15:17:57 -0400 Subject: [PATCH 01/11] Remove remaining sys.exit calls from build.py --- conda_build/build.py | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/conda_build/build.py b/conda_build/build.py index 9bce326305..c5b978c8ff 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -1647,27 +1647,7 @@ def post_process_files(m: MetaData, initial_prefix_files): # The post processing may have deleted some files (like easy-install.pth) current_prefix_files = utils.prefix_files(prefix=host_prefix) new_files = sorted(current_prefix_files - initial_prefix_files) - """ - if m.noarch == 'python' and m.config.subdir == 'win-32': - # Delete any PIP-created .exe launchers and fix entry_points.txt - # .. but we need to provide scripts instead here. - from .post import caseless_sepless_fnmatch - exes = caseless_sepless_fnmatch(new_files, 'Scripts/*.exe') - for ff in exes: - os.unlink(os.path.join(m.config.host_prefix, ff)) - new_files.remove(ff) - """ new_files = utils.filter_files(new_files, prefix=host_prefix) - meta_dir = m.config.meta_dir - if any(meta_dir in join(host_prefix, f) for f in new_files): - meta_files = ( - tuple(f for f in new_files if m.config.meta_dir in join(host_prefix, f)), - ) - sys.exit( - f"Error: Untracked file(s) {meta_files} found in conda-meta directory. This error usually comes " - "from using conda in the build script. Avoid doing this, as it can lead to packages " - "that include their dependencies." - ) post_build(m, new_files, build_python=python) entry_point_script_names = get_entry_point_script_names( @@ -3604,12 +3584,11 @@ def check_external(): if on_linux: patchelf = external.find_executable("patchelf") if patchelf is None: - sys.exit( - "Error:\n" - f" Did not find 'patchelf' in: {os.pathsep.join(external.dir_paths)}\n" - " 'patchelf' is necessary for building conda packages on Linux with\n" - " relocatable ELF libraries. You can install patchelf using conda install\n" - " patchelf.\n" + raise CondaBuildUserError( + f"Did not find 'patchelf' in: {os.pathsep.join(external._DIR_PATHS)} " + f"'patchelf' is necessary for building conda packages on Linux with " + f"relocatable ELF libraries. You can install patchelf using conda install " + f"patchelf." ) From 78156cf10f87cea1ab2b45881f9ed8979cf14a09 Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Tue, 9 Jul 2024 15:21:14 -0400 Subject: [PATCH 02/11] Remove sys.exit call from features.py --- conda_build/features.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conda_build/features.py b/conda_build/features.py index 414b15333f..4791f3521b 100644 --- a/conda_build/features.py +++ b/conda_build/features.py @@ -1,7 +1,8 @@ # Copyright (C) 2014 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause import os -import sys + +from .exceptions import CondaBuildUserError env_vars = [ "FEATURE_DEBUG", @@ -15,7 +16,7 @@ for key, value in os.environ.items(): if key in env_vars: if value not in ("0", "1"): - sys.exit( + raise CondaBuildUserError( f"Error: did not expect environment variable '{key}' " f"being set to '{value}' (not '0' or '1')" ) From 4843afe9448b124d854464015cf82bce8c0d2c1c Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Wed, 10 Jul 2024 15:10:33 -0400 Subject: [PATCH 03/11] Revert cleanup changes in build.py --- conda_build/build.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/conda_build/build.py b/conda_build/build.py index 78bd51a5b0..947df0ee02 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -1647,7 +1647,27 @@ def post_process_files(m: MetaData, initial_prefix_files): # The post processing may have deleted some files (like easy-install.pth) current_prefix_files = utils.prefix_files(prefix=host_prefix) new_files = sorted(current_prefix_files - initial_prefix_files) + """ + if m.noarch == 'python' and m.config.subdir == 'win-32': + # Delete any PIP-created .exe launchers and fix entry_points.txt + # .. but we need to provide scripts instead here. + from .post import caseless_sepless_fnmatch + exes = caseless_sepless_fnmatch(new_files, 'Scripts/*.exe') + for ff in exes: + os.unlink(os.path.join(m.config.host_prefix, ff)) + new_files.remove(ff) + """ new_files = utils.filter_files(new_files, prefix=host_prefix) + meta_dir = m.config.meta_dir + if any(meta_dir in join(host_prefix, f) for f in new_files): + meta_files = ( + tuple(f for f in new_files if m.config.meta_dir in join(host_prefix, f)), + ) + CondaBuildUserError( + f"Error: Untracked file(s) {meta_files} found in conda-meta directory. This error usually comes " + "from using conda in the build script. Avoid doing this, as it can lead to packages " + "that include their dependencies." + ) post_build(m, new_files, build_python=python) entry_point_script_names = get_entry_point_script_names( From ac686af0481bddc5cc4bfddccd405a84b49427b2 Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Wed, 10 Jul 2024 15:43:10 -0400 Subject: [PATCH 04/11] Remove sys.exit calls from main_build.py, update tests --- conda_build/cli/main_build.py | 4 ++-- tests/cli/test_main_build.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py index 13e129910d..993ff5bddd 100644 --- a/conda_build/cli/main_build.py +++ b/conda_build/cli/main_build.py @@ -4,7 +4,6 @@ import argparse import logging -import sys import warnings from glob import glob from itertools import chain @@ -22,6 +21,7 @@ get_or_merge_config, zstd_compression_level_default, ) +from ..exceptions import CondaBuildUserError from ..utils import LoggingContext from .actions import KeyValueAction from .main_render import get_render_parser @@ -576,7 +576,7 @@ def execute(args: Sequence[str] | None = None) -> int: if failed_recipes: print("Failed recipes:") dashlist(failed_recipes) - sys.exit(len(failed_recipes)) + raise CondaBuildUserError(len(failed_recipes)) else: print("All tests passed") elif parsed.source: diff --git a/tests/cli/test_main_build.py b/tests/cli/test_main_build.py index ed56cabceb..930af978c2 100644 --- a/tests/cli/test_main_build.py +++ b/tests/cli/test_main_build.py @@ -159,7 +159,9 @@ def test_slash_in_recipe_arg_keeps_build_id( @pytest.mark.sanity @pytest.mark.skipif(on_win, reason="prefix is always short on win.") -def test_build_long_test_prefix_default_enabled(mocker, testing_workdir): +def test_build_long_test_prefix_default_enabled( + mocker: MockerFixture, testing_workdir: str +) -> None: recipe_path = os.path.join(metadata_dir, "_test_long_test_prefix") args = [recipe_path, "--no-anaconda-upload"] main_build.execute(args) @@ -472,7 +474,7 @@ def test_relative_path_test_recipe(conda_build_test_recipe_envvar: str): main_build.execute(args) -def test_test_extra_dep(testing_metadata): +def test_test_extra_dep(testing_metadata: MetaData) -> None: testing_metadata.meta["test"]["imports"] = ["imagesize"] api.output_yaml(testing_metadata, "meta.yaml") output = api.build(testing_metadata, notest=True, anaconda_upload=False)[0] From 46701d106a39d44eeb3753765dcaf465c41e73f7 Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Thu, 11 Jul 2024 12:48:52 -0400 Subject: [PATCH 05/11] Revert changes to in order to keep the PR small in scope --- conda_build/cli/main_build.py | 4 ++-- tests/cli/test_main_build.py | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py index 993ff5bddd..13e129910d 100644 --- a/conda_build/cli/main_build.py +++ b/conda_build/cli/main_build.py @@ -4,6 +4,7 @@ import argparse import logging +import sys import warnings from glob import glob from itertools import chain @@ -21,7 +22,6 @@ get_or_merge_config, zstd_compression_level_default, ) -from ..exceptions import CondaBuildUserError from ..utils import LoggingContext from .actions import KeyValueAction from .main_render import get_render_parser @@ -576,7 +576,7 @@ def execute(args: Sequence[str] | None = None) -> int: if failed_recipes: print("Failed recipes:") dashlist(failed_recipes) - raise CondaBuildUserError(len(failed_recipes)) + sys.exit(len(failed_recipes)) else: print("All tests passed") elif parsed.source: diff --git a/tests/cli/test_main_build.py b/tests/cli/test_main_build.py index 930af978c2..ed56cabceb 100644 --- a/tests/cli/test_main_build.py +++ b/tests/cli/test_main_build.py @@ -159,9 +159,7 @@ def test_slash_in_recipe_arg_keeps_build_id( @pytest.mark.sanity @pytest.mark.skipif(on_win, reason="prefix is always short on win.") -def test_build_long_test_prefix_default_enabled( - mocker: MockerFixture, testing_workdir: str -) -> None: +def test_build_long_test_prefix_default_enabled(mocker, testing_workdir): recipe_path = os.path.join(metadata_dir, "_test_long_test_prefix") args = [recipe_path, "--no-anaconda-upload"] main_build.execute(args) @@ -474,7 +472,7 @@ def test_relative_path_test_recipe(conda_build_test_recipe_envvar: str): main_build.execute(args) -def test_test_extra_dep(testing_metadata: MetaData) -> None: +def test_test_extra_dep(testing_metadata): testing_metadata.meta["test"]["imports"] = ["imagesize"] api.output_yaml(testing_metadata, "meta.yaml") output = api.build(testing_metadata, notest=True, anaconda_upload=False)[0] From de4c1eda40d1d8889456611e92fe6e7c160dd1bb Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Thu, 11 Jul 2024 12:49:38 -0400 Subject: [PATCH 06/11] Revert changes to in order to keep the PR small in scope --- conda_build/features.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/conda_build/features.py b/conda_build/features.py index 4791f3521b..414b15333f 100644 --- a/conda_build/features.py +++ b/conda_build/features.py @@ -1,8 +1,7 @@ # Copyright (C) 2014 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause import os - -from .exceptions import CondaBuildUserError +import sys env_vars = [ "FEATURE_DEBUG", @@ -16,7 +15,7 @@ for key, value in os.environ.items(): if key in env_vars: if value not in ("0", "1"): - raise CondaBuildUserError( + sys.exit( f"Error: did not expect environment variable '{key}' " f"being set to '{value}' (not '0' or '1')" ) From f2da850053bb6ae1af532373a6d5488616b929a3 Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Thu, 11 Jul 2024 13:34:32 -0400 Subject: [PATCH 07/11] Add test for build.py, deprecate constant --- conda_build/os_utils/external.py | 21 ++++++++++++++------- tests/test_build.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/conda_build/os_utils/external.py b/conda_build/os_utils/external.py index 3ea8216a53..7131faad3f 100644 --- a/conda_build/os_utils/external.py +++ b/conda_build/os_utils/external.py @@ -1,5 +1,8 @@ # Copyright (C) 2014 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause + +from __future__ import annotations + import os import stat from glob import glob @@ -7,43 +10,47 @@ from conda.base.context import context +from ..deprecations import deprecated from ..utils import on_win +_DIR_PATHS: list[str] = [] +deprecated.constant("24.7", "24.9", "dir_paths", _DIR_PATHS) + def find_executable(executable, prefix=None, all_matches=False): # dir_paths is referenced as a module-level variable # in other code - global dir_paths + global _DIR_PATHS result = None if on_win: - dir_paths = [ + _DIR_PATHS = [ 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] = [ + _DIR_PATHS[0:0] = [ join(prefix, "Scripts"), join(prefix, "Library\\mingw-w64\\bin"), join(prefix, "Library\\usr\\bin"), join(prefix, "Library\\bin"), ] else: - dir_paths = [ + _DIR_PATHS = [ join(context.root_prefix, "bin"), ] if prefix: - dir_paths.insert(0, join(prefix, "bin")) + _DIR_PATHS.insert(0, join(prefix, "bin")) - dir_paths.extend(os.environ["PATH"].split(os.pathsep)) + _DIR_PATHS.extend(os.environ["PATH"].split(os.pathsep)) if on_win: exts = (".exe", ".bat", "") else: exts = ("",) all_matches_found = [] - for dir_path in dir_paths: + for dir_path in _DIR_PATHS: for ext in exts: path = expanduser(join(dir_path, executable + ext)) if isfile(path): diff --git a/tests/test_build.py b/tests/test_build.py index d94df2dd93..52d1e5425b 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -15,7 +15,7 @@ from typing import TYPE_CHECKING import pytest -from conda.common.compat import on_win +from conda.common.compat import on_linux, on_win from conda_build import api, build from conda_build.exceptions import CondaBuildUserError @@ -343,6 +343,16 @@ def test_check_external(): build.check_external() +@pytest.mark.skipif(not on_linux, reason="pathelf is only available on Linux") +def test_check_external_user_error(mocker: MockerFixture) -> None: + mocker.patch( + "conda_build.os_utils.external.find_executable", + return_value=None, + ) + with pytest.raises(CondaBuildUserError): + build.check_external() + + @pytest.mark.parametrize("readme", ["README.md", "README.rst", "README"]) def test_copy_readme(testing_metadata: MetaData, readme: str): testing_metadata.meta["about"]["readme"] = readme From 7f7092f45a627f2f66bc65f9bf926a32886c2557 Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Thu, 11 Jul 2024 17:02:08 -0400 Subject: [PATCH 08/11] Delete exception which will never get raised --- conda_build/build.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/conda_build/build.py b/conda_build/build.py index 947df0ee02..7982ca7e42 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -1647,27 +1647,9 @@ def post_process_files(m: MetaData, initial_prefix_files): # The post processing may have deleted some files (like easy-install.pth) current_prefix_files = utils.prefix_files(prefix=host_prefix) new_files = sorted(current_prefix_files - initial_prefix_files) - """ - if m.noarch == 'python' and m.config.subdir == 'win-32': - # Delete any PIP-created .exe launchers and fix entry_points.txt - # .. but we need to provide scripts instead here. - from .post import caseless_sepless_fnmatch - exes = caseless_sepless_fnmatch(new_files, 'Scripts/*.exe') - for ff in exes: - os.unlink(os.path.join(m.config.host_prefix, ff)) - new_files.remove(ff) - """ + + # filter_files will remove .git, trash directories, and conda-meta directories new_files = utils.filter_files(new_files, prefix=host_prefix) - meta_dir = m.config.meta_dir - if any(meta_dir in join(host_prefix, f) for f in new_files): - meta_files = ( - tuple(f for f in new_files if m.config.meta_dir in join(host_prefix, f)), - ) - CondaBuildUserError( - f"Error: Untracked file(s) {meta_files} found in conda-meta directory. This error usually comes " - "from using conda in the build script. Avoid doing this, as it can lead to packages " - "that include their dependencies." - ) post_build(m, new_files, build_python=python) entry_point_script_names = get_entry_point_script_names( From 2278264c94a17db84e3eef83f9dc11ae45076591 Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Thu, 11 Jul 2024 17:36:09 -0400 Subject: [PATCH 09/11] Add news file --- news/5402-deprecate-dir_path-constant | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/5402-deprecate-dir_path-constant diff --git a/news/5402-deprecate-dir_path-constant b/news/5402-deprecate-dir_path-constant new file mode 100644 index 0000000000..492a4cb356 --- /dev/null +++ b/news/5402-deprecate-dir_path-constant @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* + +### Deprecations + +* Mark `conda_build.os_utils.dir_paths` constant for deprecation. Use `_DIR_PATHS` instead. (#5402) + +### Docs + +* + +### Other + +* From 478dbb6bb7502269ef0b716c3227ef1ad8a2ac86 Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Fri, 12 Jul 2024 11:27:34 -0400 Subject: [PATCH 10/11] Revert deprecation of constant --- conda_build/build.py | 2 +- conda_build/os_utils/external.py | 21 +++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/conda_build/build.py b/conda_build/build.py index 7982ca7e42..b6ee26de27 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -3591,7 +3591,7 @@ def check_external(): patchelf = external.find_executable("patchelf") if patchelf is None: raise CondaBuildUserError( - f"Did not find 'patchelf' in: {os.pathsep.join(external._DIR_PATHS)} " + f"Did not find 'patchelf' in: {os.pathsep.join(external.dir_paths)} " f"'patchelf' is necessary for building conda packages on Linux with " f"relocatable ELF libraries. You can install patchelf using conda install " f"patchelf." diff --git a/conda_build/os_utils/external.py b/conda_build/os_utils/external.py index 7131faad3f..3ea8216a53 100644 --- a/conda_build/os_utils/external.py +++ b/conda_build/os_utils/external.py @@ -1,8 +1,5 @@ # Copyright (C) 2014 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause - -from __future__ import annotations - import os import stat from glob import glob @@ -10,47 +7,43 @@ from conda.base.context import context -from ..deprecations import deprecated from ..utils import on_win -_DIR_PATHS: list[str] = [] -deprecated.constant("24.7", "24.9", "dir_paths", _DIR_PATHS) - def find_executable(executable, prefix=None, all_matches=False): # dir_paths is referenced as a module-level variable # in other code - global _DIR_PATHS + global dir_paths result = None if on_win: - _DIR_PATHS = [ + dir_paths = [ 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] = [ + dir_paths[0:0] = [ join(prefix, "Scripts"), join(prefix, "Library\\mingw-w64\\bin"), join(prefix, "Library\\usr\\bin"), join(prefix, "Library\\bin"), ] else: - _DIR_PATHS = [ + dir_paths = [ join(context.root_prefix, "bin"), ] if prefix: - _DIR_PATHS.insert(0, join(prefix, "bin")) + dir_paths.insert(0, join(prefix, "bin")) - _DIR_PATHS.extend(os.environ["PATH"].split(os.pathsep)) + dir_paths.extend(os.environ["PATH"].split(os.pathsep)) if on_win: exts = (".exe", ".bat", "") else: exts = ("",) all_matches_found = [] - for dir_path in _DIR_PATHS: + for dir_path in dir_paths: for ext in exts: path = expanduser(join(dir_path, executable + ext)) if isfile(path): From 1fe96867cc75d06c8b103e48d9ff267de3f8448f Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Fri, 12 Jul 2024 11:28:06 -0400 Subject: [PATCH 11/11] Remove news file --- news/5402-deprecate-dir_path-constant | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 news/5402-deprecate-dir_path-constant diff --git a/news/5402-deprecate-dir_path-constant b/news/5402-deprecate-dir_path-constant deleted file mode 100644 index 492a4cb356..0000000000 --- a/news/5402-deprecate-dir_path-constant +++ /dev/null @@ -1,19 +0,0 @@ -### Enhancements - -* - -### Bug fixes - -* - -### Deprecations - -* Mark `conda_build.os_utils.dir_paths` constant for deprecation. Use `_DIR_PATHS` instead. (#5402) - -### Docs - -* - -### Other - -*