Skip to content

Commit

Permalink
pass-through build dependencies properly for setup cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
msarahan committed Jan 5, 2024
1 parent e2da4e0 commit 0f448b5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
11 changes: 9 additions & 2 deletions grayskull/strategy/py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ def merge_setup_toml_metadata(setup_metadata: dict, pyproject_metadata: dict) ->
setup_metadata.get("install_requires", []),
pyproject_metadata["requirements"]["run"],
)
# this is not a valid setup_metadata field, but we abuse it to pass it
# through to the conda recipe generator downstream. It's because setup.py
# does not have a notion of build vs. host requirements. It only has
# equivalents to host and run.
if pyproject_metadata["requirements"]["build"]:
setup_metadata["__build_requirements_placeholder"] = pyproject_metadata[
"requirements"
]["build"]
if pyproject_metadata["requirements"]["run_constrained"]:
setup_metadata["requirements_run_constrained"] = pyproject_metadata[
"requirements"
Expand Down Expand Up @@ -802,9 +810,8 @@ def ensure_pep440_in_req_list(list_req: List[str]) -> List[str]:


def split_deps(deps: str) -> List[str]:
deps = deps.split(",")
result = []
for d in deps:
for d in deps.split(","):
constrain = ""
for val in re.split(r"([><!=~^]+)", d):
if not val:
Expand Down
15 changes: 8 additions & 7 deletions grayskull/strategy/py_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,16 @@ def get_pep725_mapping(purl: str):
# taken from

package_mapping = {
"virtual:compiler/c": '${{ compiler("c") }}',
"virtual:compiler/cpp": '${{ compiler("cxx") }}',
"virtual:compiler/fortran": '${{ compiler("fortran") }}',
"virtual:compiler/rust": '${{ compiler("rust") }}',
"virtual:interface/blas": "${{ blas }}",
"virtual:compiler/c": '{{ compiler("c") }}',
"virtual:compiler/cpp": '{{ compiler("cxx") }}',
"virtual:compiler/fortran": '{{ compiler("fortran") }}',
"virtual:compiler/rust": '{{ compiler("rust") }}',
"virtual:interface/blas": "{{ blas }}",
}
return (
package_mapping.get(purl)
or f'# WARNING: no matching mapping was found for PURL "{purl}". The dependency has been omitted here.'
or f'# WARNING: no matching mapping was found for PURL "{purl}".'
" The dependency has been omitted here."
)


Expand All @@ -285,7 +286,7 @@ def add_pep725_metadata(metadata: dict, toml_metadata: dict):
requirements[conda_section] = [
get_pep725_mapping(purl) for purl in externals.get(pep725_section, [])
]
# Conda doesn't really have a notion of optional dependencies. We just insert them all.
# TODO: handle optional dependencies properly
optional_features = toml_metadata.get(f"optional-{pep725_section}", {})
for feature_name, feature_deps in optional_features.items():
requirements[conda_section].append(
Expand Down
8 changes: 7 additions & 1 deletion grayskull/strategy/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def get_val(key):
"requires_dist": requires_dist,
"sdist_path": get_val("sdist_path"),
"requirements_run_constrained": get_val("requirements_run_constrained"),
"__build_requirements_placeholder": get_val("__build_requirements_placeholder"),
}


Expand Down Expand Up @@ -385,6 +386,7 @@ def get_metadata(recipe, config) -> dict:

requirements_section = extract_requirements(metadata, config, recipe)
optional_requirements = extract_optional_requirements(metadata, config)

for key in requirements_section:
requirements_section[key] = normalize_requirements_list(
requirements_section[key], config
Expand Down Expand Up @@ -556,6 +558,8 @@ def extract_requirements(metadata: dict, config, recipe) -> Dict[str, List[str]]
requires_dist = format_dependencies(metadata.get("requires_dist", []), name)
setup_requires = metadata.get("setup_requires", [])
host_req = format_dependencies(setup_requires or [], config.name)
build_requires = metadata.get("__build_requirements_placeholder", [])
build_req = format_dependencies(build_requires or [], config.name)
if not requires_dist and not host_req and not metadata.get("requires_python"):
if config.is_strict_cf:
py_constrain = (
Expand All @@ -571,7 +575,9 @@ def extract_requirements(metadata: dict, config, recipe) -> Dict[str, List[str]]

run_req = get_run_req_from_requires_dist(requires_dist, config)
host_req = get_run_req_from_requires_dist(host_req, config)
build_req = [f"<{{ compiler('{c}') }}}}" for c in metadata.get("compilers", [])]
build_req = build_req or [
f"<{{ compiler('{c}') }}}}" for c in metadata.get("compilers", [])
]
if build_req:
config.is_arch = True

Expand Down

0 comments on commit 0f448b5

Please sign in to comment.