Skip to content

Commit

Permalink
Adjusted the test requirements to ensure 'python' is included and add…
Browse files Browse the repository at this point in the history
…ed a new function to enforce minimum Python version dependencies.

Signed-off-by: Marcelo Trevisani <[email protected]>
  • Loading branch information
marcelotrevisani committed Nov 13, 2024
1 parent b771c43 commit b594304
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 30 deletions.
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 = {
"test": f"={python_min}",
"host": f"{python_min}.*",
"run": f">={python_min}",
}
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
56 changes: 54 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ testing = [
"pytest",
"pytest-console-scripts",
"pytest-cov",
"pytest-xdist",
"pytest-mock",
"setuptools-scm",
"numpy"
]

docs = [
Expand Down
1 change: 1 addition & 0 deletions tests/data/poetry/langchain-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ test:
- langchain-server --help
requires:
- pip
- python

about:
home: https://www.github.com/hwchase17/langchain
Expand Down
Loading

0 comments on commit b594304

Please sign in to comment.