diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index 45fbeb1c5..9e1798582 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -235,44 +235,6 @@ def to_match_spec(conda_dep_name: str, conda_version: Optional[str]) -> str: return spec -def parse_pyproject_toml( - pyproject_toml: pathlib.Path, -) -> LockSpecification: - with pyproject_toml.open("rb") as fp: - contents = toml_load(fp) - build_system = get_in(["build-system", "build-backend"], contents) - pep_621_probe = get_in(["project", "dependencies"], contents) - pdm_probe = get_in(["tool", "pdm"], contents) - parse = parse_poetry_pyproject_toml - if pep_621_probe is not None: - if pdm_probe is None: - parse = partial( - parse_requirements_pyproject_toml, - prefix=("project",), - main_tag="dependencies", - optional_tag="optional-dependencies", - ) - else: - parse = parse_pdm_pyproject_toml - elif build_system.startswith("poetry"): - parse = parse_poetry_pyproject_toml - elif build_system.startswith("flit"): - parse = partial( - parse_requirements_pyproject_toml, - prefix=("tool", "flit", "metadata"), - main_tag="requires", - optional_tag="requires-extra", - ) - else: - import warnings - - warnings.warn( - "Could not detect build-system in pyproject.toml. Assuming poetry" - ) - - return parse(pyproject_toml, contents) - - def parse_python_requirement( requirement: str, manager: Literal["conda", "pip"] = "conda", @@ -383,3 +345,41 @@ def parse_pdm_pyproject_toml( res.dependencies.extend(dev_reqs) return res + + +def parse_pyproject_toml( + pyproject_toml: pathlib.Path, +) -> LockSpecification: + with pyproject_toml.open("rb") as fp: + contents = toml_load(fp) + build_system = get_in(["build-system", "build-backend"], contents) + pep_621_probe = get_in(["project", "dependencies"], contents) + pdm_probe = get_in(["tool", "pdm"], contents) + parse = parse_poetry_pyproject_toml + if pep_621_probe is not None: + if pdm_probe is None: + parse = partial( + parse_requirements_pyproject_toml, + prefix=("project",), + main_tag="dependencies", + optional_tag="optional-dependencies", + ) + else: + parse = parse_pdm_pyproject_toml + elif build_system.startswith("poetry"): + parse = parse_poetry_pyproject_toml + elif build_system.startswith("flit"): + parse = partial( + parse_requirements_pyproject_toml, + prefix=("tool", "flit", "metadata"), + main_tag="requires", + optional_tag="requires-extra", + ) + else: + import warnings + + warnings.warn( + "Could not detect build-system in pyproject.toml. Assuming poetry" + ) + + return parse(pyproject_toml, contents)