Skip to content

Commit

Permalink
Move parse_pyproject_toml subfunction to end
Browse files Browse the repository at this point in the history
  • Loading branch information
srilman committed Feb 9, 2023
1 parent b0856c8 commit 55b5fe2
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

0 comments on commit 55b5fe2

Please sign in to comment.