Skip to content

Commit 86de305

Browse files
committed
Mark packages as user requested
1 parent ba4c4d0 commit 86de305

File tree

6 files changed

+64
-13
lines changed

6 files changed

+64
-13
lines changed

dof/_src/checkpoint.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
from dof._src.models import package, environment
99
from dof._src.utils import hash_string
1010
from dof._src.data.local import LocalData
11+
from dof._src.conda_meta.conda_meta import CondaMeta
1112

1213

1314
class Checkpoint():
1415
@classmethod
1516
def from_prefix(cls, prefix: str, uuid: str, tags: List[str] = []):
1617
packages = []
1718
channels = set()
19+
meta = CondaMeta(prefix=prefix)
20+
user_requested_specs_map = meta.get_requested_specs_map()
21+
1822
for prefix_record in PrefixData(prefix, pip_interop_enabled=True).iter_records_sorted():
1923
if prefix_record.subdir == "pypi":
2024
packages.append(
@@ -36,9 +40,9 @@ def from_prefix(cls, prefix: str, uuid: str, tags: List[str] = []):
3640
conda_channel=prefix_record.channel.url(),
3741
# TODO
3842
arch="",
39-
# not sure here
40-
platform="linux-64",
41-
url=prefix_record.url
43+
platform=prefix_record.channel.platform,
44+
url=prefix_record.url,
45+
user_requested_spec=user_requested_specs_map.get(prefix_record.name, None)
4246
)
4347
)
4448

dof/_src/conda_meta/conda.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@ def __init__(self, prefix):
2121
self.history = History(prefix)
2222

2323
def get_requested_specs(self) -> list[str]:
24-
"""Return a list of all the specs a user requested to be installed.
24+
"""Return a list of all the MatchSpecs a user requested to be installed
25+
2526
Returns
2627
-------
2728
specs: list[str]
28-
A list of all the specs a user requested to be installed.
29+
A list of all the MatchSpecs a user requested to be installed
30+
"""
31+
requested_specs = self.history.get_requested_specs_map()
32+
return [spec.spec for spec in requested_specs.values()]
33+
34+
def get_requested_specs_map(self) -> dict[str, str]:
35+
"""Return a dict of all the package name to MatchSpecs user requested
36+
specs to be installed.
37+
38+
Returns
39+
-------
40+
specs: dict[str, str]
41+
A list of all the package names to MatchSpecs a user requested to be installed
2942
"""
3043
requested_specs = self.history.get_requested_specs_map()
31-
return [spec.dist_str() for spec in requested_specs.values()]
44+
return {k: v.spec for k,v in requested_specs.items()}

dof/_src/conda_meta/conda_meta.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, prefix):
4040
raise Exception("Could not detect conda or pixi based conda meta")
4141

4242
def get_requested_specs(self) -> list[str]:
43-
"""Return a list of all the specs a user requested to be installed.
43+
"""Return a list of all the MatchSpecs a user requested to be installed.
4444
4545
A user_requested_spec is one that the user explicitly asked to be
4646
installed. These are different from dependency_specs which are specs
@@ -53,6 +53,17 @@ def get_requested_specs(self) -> list[str]:
5353
Returns
5454
-------
5555
specs: list[str]
56-
A list of all the specs a user requested to be installed.
56+
A list of all the MatchSpecs a user requested to be installed
5757
"""
5858
return self.conda_meta.get_requested_specs()
59+
60+
def get_requested_specs_map(self) -> dict[str, str]:
61+
"""Return a dict of all the package name to MatchSpecs user requested
62+
specs to be installed.
63+
64+
Returns
65+
-------
66+
specs: dict[str, str]
67+
A list of all the package names to MatchSpecs a user requested to be installed
68+
"""
69+
return self.conda_meta.get_requested_specs_map()

dof/_src/conda_meta/pixi.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@ def get_requested_specs(self) -> list[str]:
2424
specs: list[str]
2525
A list of all the specs a user requested to be installed.
2626
"""
27-
return []
27+
return []
28+
29+
# TODO
30+
def get_requested_specs_map(self) -> dict[str, str]:
31+
"""Return a dict of all the package name to MatchSpecs user requested
32+
specs to be installed.
33+
34+
Returns
35+
-------
36+
specs: dict[str, str]
37+
A list of all the package names to MatchSpecs a user requested to be installed
38+
"""
39+
return {}

dof/_src/models/package.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class CondaPackage(BaseModel):
1414
arch: str
1515
platform: str
1616
url: str
17+
# the string representation of the matchspec that the user
18+
# used to request the package. If this was not a package
19+
# the user explicitly added, this will be none.
20+
user_requested_spec: Optional[str] = None
1721

1822
def to_repodata_record(self):
1923
"""Converts a url package into a rattler compatible repodata record."""
@@ -28,7 +32,6 @@ def to_repodata_record(self):
2832
channel=self.conda_channel,
2933
url=self.url
3034
)
31-
3235

3336
def __str__(self):
3437
return f"conda: {self.name} - {self.version}"
@@ -59,6 +62,7 @@ def to_repodata_record(self):
5962
pass
6063

6164

65+
# TODO: probably remove?
6266
class UrlCondaPackage(BaseModel):
6367
url: str
6468

dof/cli/root.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,22 @@ def user_specs(
5555
),
5656
):
5757
"""Demo command: output the list of user requested specs for a revision"""
58+
prefix = os.environ.get("CONDA_PREFIX")
5859
if rev is None:
59-
prefix = os.environ.get("CONDA_PREFIX")
6060
meta = CondaMeta(prefix=prefix)
6161
specs = meta.get_requested_specs()
6262
print("the user requested specs in this environment are:")
63-
for spec in specs:
63+
# sort alphabetically for readability
64+
for spec in sorted(specs):
6465
print(f" {spec}")
6566
else:
66-
print("I don't know how to do this yet")
67+
chck = Checkpoint.from_uuid(prefix=prefix, uuid=rev)
68+
pkgs = chck.list_packages()
69+
print(f"the user requested specs rev {rev}:")
70+
# sort alphabetically for readability
71+
for spec in sorted(pkgs, key=lambda p: p.name):
72+
if spec.user_requested_spec is not None:
73+
print(f" {spec.user_requested_spec}")
6774

6875

6976
@app.command()

0 commit comments

Comments
 (0)