Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #574 add python_min #581

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions grayskull/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class Configuration:
PyVer(3, 10),
PyVer(3, 11),
PyVer(3, 12),
PyVer(3, 13),
]
)
py_cf_supported: list[PyVer] = field(
default_factory=lambda: [
PyVer(3, 7),
PyVer(3, 8),
PyVer(3, 9),
PyVer(3, 10),
PyVer(3, 11),
PyVer(3, 12),
PyVer(3, 13),
]
)
is_strict_cf: bool = False
Expand Down
35 changes: 29 additions & 6 deletions grayskull/strategy/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ def get_metadata(recipe, config) -> dict:
test_requirements = optional_requirements.pop(config.extras_require_test, [])
test_section = compose_test_section(metadata, test_requirements)

if config.is_strict_cf and not config.is_arch:
test_section["requires"] = set_python_min(test_section["requires"], "test")

about_section = {
"home": metadata["url"] if metadata.get("url") else metadata.get("project_url"),
"summary": metadata.get("summary"),
Expand Down Expand Up @@ -582,6 +585,21 @@ def check_noarch_python_for_new_deps(
config.is_arch = False


def set_python_min(req_list: list, section: str) -> list:
if not req_list:
return req_list
python_min = "<{ python_min }}"
map_section = {
"host": f"{python_min}.*",
"run": f">={python_min}",
"test": f"={python_min}",
marcelotrevisani marked this conversation as resolved.
Show resolved Hide resolved
}
return [
f"python {map_section[section]}" if dep.lower().strip() == "python" else dep
for dep in req_list
]


def extract_requirements(metadata: dict, config, recipe) -> dict[str, list[str]]:
"""Extract the requirements for `build`, `host` and `run`"""
name = metadata["name"]
Expand All @@ -592,13 +610,13 @@ def extract_requirements(metadata: dict, config, recipe) -> dict[str, list[str]]
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 = (
f" >={config.py_cf_supported[0].major}"
f".{config.py_cf_supported[0].minor}"
)
requirements = {
"host": ["python", "pip"],
"run": ["python"],
}
return {
"host": [f"python {py_constrain}", "pip"],
"run": [f"python {py_constrain}"],
"host": set_python_min(requirements["host"], "host"),
"run": set_python_min(requirements["run"], "run"),
}
else:
return {"host": ["python", "pip"], "run": ["python"]}
Expand Down Expand Up @@ -648,6 +666,9 @@ def extract_requirements(metadata: dict, config, recipe) -> dict[str, list[str]]
if metadata.get("requirements_run_constrained", None):
result.update({"run_constrained": metadata["requirements_run_constrained"]})
update_requirements_with_pin(result)
if config.is_strict_cf and not config.is_arch:
result["host"] = set_python_min(result["host"], "host")
result["run"] = set_python_min(result["run"], "run")
return result


Expand Down Expand Up @@ -715,6 +736,8 @@ def normalize_requirements_list(requirements: list[str], config) -> list[str]:
def compose_test_section(metadata: dict, test_requirements: list[str]) -> dict:
test_imports = get_test_imports(metadata, metadata["name"])
test_requirements = ["pip"] + test_requirements
if "python" not in test_requirements:
test_requirements.append("python")
test_commands = ["pip check"]
if any("pytest" in req for req in test_requirements):
test_commands.extend(f"pytest --pyargs {module}" for module in test_imports)
Expand Down
Loading
Loading