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

Refactor: Extract environment related code from Candidate #920

Merged
merged 13 commits into from
Feb 17, 2022
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
- "*.md"
- Dockerfile

concurrency:
group: ${{ github.event.number || github.run_id }}
cancel-in-progress: true

jobs:
Testing:
runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions news/920.refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Extract the environment related code from `Candidate` into a new class `PreparedCandidate`.
2 changes: 1 addition & 1 deletion pdm/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def do_lock(
ui.echo(format_resolution_impossible(err), err=True)
raise ResolutionImpossible("Unable to find a resolution") from None
else:
data = format_lockfile(mapping, dependencies)
data = format_lockfile(project, mapping, dependencies)
spin.succeed(f"{termui.Emoji.LOCK} Lock successful")
signals.post_lock.send(project, resolution=mapping, dry_run=dry_run)

Expand Down
3 changes: 1 addition & 2 deletions pdm/cli/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
)
return
latest_stable = next(filter(filter_stable, matches), None)

metadata = latest.metadata
metadata = latest.prepare(project.environment).metadata
else:
if not project.meta.name:
raise PdmUsageError("This project is not a package")
Expand Down
6 changes: 4 additions & 2 deletions pdm/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ def format_dependency_graph(


def format_lockfile(
mapping: dict[str, Candidate], fetched_dependencies: dict[str, list[Requirement]]
project: Project,
mapping: dict[str, Candidate],
fetched_dependencies: dict[str, list[Requirement]],
) -> dict:
"""Format lock file from a dict of resolved candidates, a mapping of dependencies
and a collection of package summaries.
Expand All @@ -438,7 +440,7 @@ def format_lockfile(
file_hashes = tomlkit.table()
for k, v in sorted(mapping.items()):
base = tomlkit.table()
base.update(v.as_lockfile_entry()) # type: ignore
base.update(v.as_lockfile_entry(project.root)) # type: ignore
base.add("summary", v.summary or "")
deps = make_array(sorted(r.as_line() for r in fetched_dependencies[k]), True)
if len(deps) > 0:
Expand Down
2 changes: 1 addition & 1 deletion pdm/formats/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def ireq_as_line(ireq: InstallRequirement, environment: Environment) -> str:
else:
if not ireq.req:
req = parse_requirement("dummy @" + ireq.link.url) # type: ignore
req.name = Candidate(req, environment).metadata.metadata["Name"]
req.name = Candidate(req).prepare(environment).metadata.metadata["Name"]
ireq.req = req # type: ignore

line = _requirement_to_str_lowercase_name(cast(PRequirement, ireq.req))
Expand Down
3 changes: 2 additions & 1 deletion pdm/installers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def install(self, candidate: Candidate) -> None:
installer = install_wheel_with_cache
else:
installer = install_wheel
installer(candidate.build(), self.environment, candidate.direct_url())
prepared = candidate.prepare(self.environment)
installer(prepared.build(), self.environment, prepared.direct_url())

def get_paths_to_remove(self, dist: Distribution) -> BaseRemovePaths:
"""Get the path collection to be removed from the disk"""
Expand Down
2 changes: 1 addition & 1 deletion pdm/installers/synchronizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
candidate.req.editable = None # type: ignore
elif (
self.install_self
and getattr(self.environment.project.meta, "editable_backend", "editables")
and getattr(self.environment.project.meta, "editable_backend", "path")
== "editables"
and "editables" not in candidates
):
Expand Down
Loading