Skip to content

Commit

Permalink
merge c_stdlib_version & MACOSX_DEPLOYMENT_TARGET on osx
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Mar 23, 2024
1 parent cac8e1b commit 43beab9
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
34 changes: 34 additions & 0 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,40 @@ def _collapse_subpackage_variants(
"BUILD",
}

# on osx, merge MACOSX_DEPLOYMENT_TARGET & c_stdlib_version to max of either; see #1884
if squished_used_variants["target_platform"][0].startswith("osx"):
# in global pinning, but use fallback to avoid having to set it in all tests
v_stdlib = squished_used_variants.get("c_stdlib_version", ["0.0"])
# also in global pinning, but prepare for eventual disappearance
macdt = squished_used_variants.get("MACOSX_DEPLOYMENT_TARGET", [None])
# the merge logic only deals with one version
if (len(v_stdlib) > 1 and macdt[0] is not None) or len(macdt) > 1:
raise ValueError(
"Not prepared to deal with multiple c_stdlib_version that do not match "
"MACOSX_DEPLOYMENT_TARGET! Please delete MACOSX_DEPLOYMENT_TARGET and "
"set only c_stdlib_version in conda_build_config.yaml!"
)
# now that we ruled out multiple values, extract the single value
v_stdlib = v_stdlib[0]
macdt = macdt[0]
if macdt is not None and v_stdlib != macdt:
logger.warn(
"Duplicate specification of macosx deployment target!\n"
"If your conda_build_config.yaml sets `MACOSX_DEPLOYMENT_TARGET`, "
"please change the name of that key to `c_stdlib_version`!"
)
# determine maximum version and use it to populate both
cond = VersionOrder(v_stdlib) > VersionOrder(macdt)
new_val = v_stdlib if cond else macdt
squished_used_variants["c_stdlib_version"] = [new_val]

# in any case, we set MACOSX_DEPLOYMENT_TARGET to match c_stdlib_version
# (if it is set), for ease of use in conda-forge-ci-setup
if "c_stdlib_version" in squished_used_variants:
squished_used_variants["MACOSX_DEPLOYMENT_TARGET"] = (
squished_used_variants["c_stdlib_version"]
)

if not is_noarch:
always_keep_keys.add("target_platform")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Ensure we populate MACOSX_DEPLOYMENT_TARGET for use in conda-forge-ci-setup also when using `c_stdlib_version` (#1884 via #1889)

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,30 @@ def stdlib_recipe(config_yaml, request):
)


@pytest.fixture(scope="function")
def stdlib_deployment_target_recipe(config_yaml, stdlib_recipe):
# append to existing stdlib_config.yaml from stdlib_recipe
with open(
os.path.join(config_yaml, "recipe", "stdlib_config.yaml"), "a"
) as f:
f.write(
"""\
MACOSX_DEPLOYMENT_TARGET: # [osx]
- 10.14 # [osx and x86_64]
- 12.0 # [osx and arm64]
"""
)
return RecipeConfigPair(
str(config_yaml),
_load_forge_config(
config_yaml,
exclusive_config_file=os.path.join(
config_yaml, "recipe", "stdlib_config.yaml"
),
),
)


@pytest.fixture(scope="function")
def upload_on_branch_recipe(config_yaml, request):
with open(os.path.join(config_yaml, "recipe", "meta.yaml"), "w") as fh:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,32 @@ def test_stdlib_on_azure(stdlib_recipe, jinja_env):
# no stdlib-version expected on windows


def test_stdlib_deployment_target(
stdlib_deployment_target_recipe, jinja_env, caplog
):
with caplog.at_level(logging.WARNING):
configure_feedstock.render_azure(
jinja_env=jinja_env,
forge_config=stdlib_deployment_target_recipe.config,
forge_dir=stdlib_deployment_target_recipe.recipe,
)
# this configuration should be run
assert stdlib_deployment_target_recipe.config["azure"]["enabled"]
matrix_dir = os.path.join(
stdlib_deployment_target_recipe.recipe, ".ci_support"
)
assert os.path.isdir(matrix_dir)
with open(os.path.join(matrix_dir, "osx_64_.yaml")) as f:
lines = f.readlines()
content = "".join(lines)
# ensure both MACOSX_DEPLOYMENT_TARGET and c_stdlib_version match
# the maximum of either, c.f. stdlib_deployment_target_recipe fixture
assert bool(re.match(r"(?s).*c_stdlib_version:\s*- ['\"]?10\.14", content))
assert bool(
re.match(r"(?s).*MACOSX_DEPLOYMENT_TARGET:\s*- ['\"]?10\.14", content)
)


def test_upload_on_branch_azure(upload_on_branch_recipe, jinja_env):
configure_feedstock.render_azure(
jinja_env=jinja_env,
Expand Down

0 comments on commit 43beab9

Please sign in to comment.