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

New Source File and Lock Specification Approach #316

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
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 @@ -232,44 +232,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 @@ -380,3 +342,41 @@ def parse_pdm_pyproject_toml(
res.dependencies.extend(dev_reqs)

return res


def parse_pyproject_toml(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, was there any particular reason to move parse_pyproject_toml to the end in da18f01?

Was it for type annotations? (I just opened #329, which would help a lot with this.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly for code-discoverability. The general pattern in most of the modules is that the last function in a module is the main function exposed by that module and used by the rest of the program. Since parse_pyproject_toml is the main exported function, I thought it should be at the end to fit that pattern.

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)