Files
deepset-ai--haystack/.github/utils/pyproject_to_requirements.py
T
wehub-resource-sync c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:22:28 +08:00

54 lines
1.3 KiB
Python

import argparse
import re
import sys
from pathlib import Path
import toml
matcher = re.compile(r"farm-haystack\[(.+)\]")
parser = argparse.ArgumentParser(
prog="pyproject_to_requirements.py", description="Convert pyproject.toml to requirements.txt"
)
parser.add_argument("pyproject_path")
parser.add_argument("--extra", default="")
def resolve(target: str, extras: dict, results: set) -> None:
"""
Resolve the dependencies for a given target.
"""
if target not in extras:
results.add(target)
return
for t in extras[target]:
m = matcher.match(t)
if m:
for i in m.group(1).split(","):
resolve(i, extras, results)
else:
resolve(t, extras, results)
def main(pyproject_path: Path, extra: str = "") -> None:
"""
Convert a pyproject.toml file to a requirements.txt file.
"""
content = toml.load(pyproject_path)
# basic set of dependencies
deps = set(content["project"]["dependencies"])
if extra:
extras = content["project"]["optional-dependencies"]
resolve(extra, extras, deps)
sys.stdout.write("\n".join(sorted(deps)))
sys.stdout.write("\n")
if __name__ == "__main__":
args = parser.parse_args()
pyproject_path = Path(args.pyproject_path).absolute()
main(pyproject_path, args.extra)