Skip to content

Commit

Permalink
sys.exit removals from build.py (#5402)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
beeankha authored Jul 12, 2024
1 parent c4d5b22 commit 2a0bf93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
33 changes: 7 additions & 26 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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."
)


Expand Down
12 changes: 11 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2a0bf93

Please sign in to comment.