Skip to content

Commit

Permalink
fix: use shlex
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Apr 29, 2024
1 parent 3565421 commit 1b1faaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
9 changes: 2 additions & 7 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
import re
import shlex
import sys
import sysconfig
from pathlib import Path
Expand Down Expand Up @@ -95,13 +96,7 @@ def get_cmake_args(self) -> list[str]:
# Adding CMake arguments set as environment variable
# (needed e.g. to build for ARM OSX on conda-forge)
env_cmake_args: list[str] = list(
filter(
None,
re.findall(
r'(?<!\S)(?:"[^"]*"|\'[^\']*\'|\S)+',
self.config.env.get("CMAKE_ARGS", ""),
),
)
filter(None, shlex.split(self.config.env.get("CMAKE_ARGS", "")))
)

if env_cmake_args:
Expand Down
19 changes: 10 additions & 9 deletions tests/test_pyproject_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ def each_unignored_file_ordered(*args, **kwargs):
@pytest.mark.compile()
@pytest.mark.configure()
@pytest.mark.usefixtures("package_simple_pyproject_script_with_flags")
@pytest.mark.parametrize("env_var", ["CMAKE_ARGS", "SKBUILD_CMAKE_ARGS"])
def test_passing_cxx_flags(monkeypatch, env_var):
# Note: This is sensitive to the types of quotes because it's being forwarded to
# bash as an environment variable. If you use single quotes as the outer quote and
# double quotes inside the definition of CMAKE_CXX_FLAGS, it will get passed to
# CMake as a single quoted command line argument "-DFOO=1 -DBAR=" and fail. I don't
# know if we want scikit-build-core to be intelligent enough to handle that case,
# though, or if we should just document it.
monkeypatch.setenv(env_var, "-DCMAKE_C_FLAGS='-DFOO=1 -DBAR='")
@pytest.mark.parametrize(
("env_var", "setting"),
[
("CMAKE_ARGS", '-DCMAKE_C_FLAGS="-DFOO=1 -DBAR="'),
("SKBUILD_CMAKE_ARGS", "-DCMAKE_C_FLAGS=-DFOO=1 -DBAR="),
],
)
def test_passing_cxx_flags(monkeypatch, env_var, setting):
# Note: This is sensitive to the types of quotes for SKBUILD_CMAKE_ARGS
monkeypatch.setenv(env_var, setting)
build_wheel("dist", {"cmake.targets": ["cmake_example"]}) # Could leave empty
(wheel,) = Path("dist").glob("cmake_example-0.0.1-py3-none-*.whl")
with zipfile.ZipFile(wheel) as f:
Expand Down

0 comments on commit 1b1faaa

Please sign in to comment.