Skip to content

Commit

Permalink
Address errors in tests for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Jun 17, 2022
1 parent 8db675d commit a19c4df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
8 changes: 4 additions & 4 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,18 +290,18 @@ def _arbitrary_args(self, config_settings: _ConfigSettings) -> Iterator[str]:
"""
args = self._get_config("--global-option", config_settings)
global_opts = self._valid_global_options()
warn = []
bad_args = []

for arg in args:
if arg.strip("-") not in global_opts:
warn.append(arg)
bad_args.append(arg)
yield arg

yield from self._get_config("--build-option", config_settings)

if warn:
if bad_args:
msg = f"""
The arguments {warn!r} were given via `--global-option`.
The arguments {bad_args!r} were given via `--global-option`.
Please use `--build-option` instead,
`--global-option` is reserved to flags like `--verbose` or `--quiet`.
"""
Expand Down
43 changes: 23 additions & 20 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import pytest
from jaraco import path
from setuptools._deprecation_warning import SetuptoolsDeprecationWarning

from .textwrap import DALS

Expand Down Expand Up @@ -624,23 +623,31 @@ def test_build_sdist_relative_path_import(self, tmpdir_cwd):
}
}

# For some reason `pytest.warns` does no seem to work here
# but `pytest.raises` does works (in systems other then macOS),
# together with an error filter.
@pytest.mark.xfail(
sys.platform == "darwin",
reason="inconsistent behaviour in macOS"
)
@pytest.mark.filterwarnings("error::setuptools.SetuptoolsDeprecationWarning")
def test_editable_with_config_settings_warning(self, tmpdir_cwd):
def _assert_link_tree(self, parent_dir):
"""All files in the directory should be either links or hard links"""
files = list(Path(parent_dir).glob("**/*"))
assert files # Should not be empty
for file in files:
assert file.is_symlink() or os.stat(file).st_nlink > 0

@pytest.mark.filterwarnings("ignore::setuptools.SetuptoolsDeprecationWarning")
# Since the backend is running via a process pool, in some operating systems
# we may have problems to make assertions based on warnings/stdout/stderr...
# So the best is to ignore them for the time being.
def test_editable_with_global_option_still_works(self, tmpdir_cwd):
"""The usage of --global-option is now discouraged in favour of --build-option.
This is required to make more sense of the provided scape hatch and align with
previous pip behaviour. See pypa/setuptools#1928.
"""
path.build({**self._simple_pyproject_example, '_meta': {}})
build_backend = self.get_build_backend()
assert not Path("build").exists()

cfg = {"--global-option": "--strict"}
build_backend.prepare_metadata_for_build_editable("_meta", cfg)
build_backend.build_editable("temp", cfg, "_meta")

msg = "The arguments .'--strict'. were given via .--global-option."
with pytest.raises(SetuptoolsDeprecationWarning, match=msg):
cfg = {"--global-option": "--strict"}
build_backend.prepare_metadata_for_build_editable("_meta", cfg)
build_backend.build_editable("temp", cfg, "_meta")
self._assert_link_tree(next(Path("build").glob("__editable__.*")))

def test_editable_without_config_settings(self, tmpdir_cwd):
"""
Expand Down Expand Up @@ -668,11 +675,7 @@ def test_editable_with_config_settings(self, tmpdir_cwd, config_settings):
build_backend = self.get_build_backend()
build_backend.prepare_metadata_for_build_editable("_meta", config_settings)
build_backend.build_editable("temp", config_settings, "_meta")
files = list(Path("build").glob("__editable__.*/**/*"))
assert files
for file in files:
# All files should either links or hard links
assert file.is_symlink() or os.stat(file).st_nlink > 0
self._assert_link_tree(next(Path("build").glob("__editable__.*")))

@pytest.mark.parametrize('setup_literal, requirements', [
("'foo'", ['foo']),
Expand Down

0 comments on commit a19c4df

Please sign in to comment.