From 2a0bf93ee17e148aac3f46cb07e3bc76fc6ade9b Mon Sep 17 00:00:00 2001 From: Bianca Henderson Date: Fri, 12 Jul 2024 12:43:22 -0400 Subject: [PATCH] `sys.exit` removals from `build.py` (#5402) * Remove remaining sys.exit calls from build.py * Remove sys.exit call from features.py * Revert cleanup changes in build.py * Remove sys.exit calls from main_build.py, update tests * Revert changes to in order to keep the PR small in scope * Revert changes to in order to keep the PR small in scope * Add test for build.py, deprecate constant * Delete exception which will never get raised * Add news file * Revert deprecation of constant * Remove news file --- conda_build/build.py | 33 +++++++-------------------------- tests/test_build.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/conda_build/build.py b/conda_build/build.py index b759f84967..b6ee26de27 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)), - ) - 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( @@ -3608,12 +3590,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." ) 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