Skip to content

Commit 6528895

Browse files
committed
feat: display src file location next to the version for each derivation
1 parent bf64ce1 commit 6528895

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

src/website/shared/listeners/cache_suggestions.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import re
3+
import urllib.parse
34
from itertools import chain
45
from typing import Any
56

@@ -179,6 +180,24 @@ def is_version_affected(version_statuses: list[str]) -> Version.Status:
179180
return result
180181

181182

183+
def get_src_position(derivation: NixDerivation) -> str | None:
184+
"""
185+
Get the GitHub URL pointing to the exact source file used for the evaluation of this derivation.
186+
E.g. https://github.com/NixOS/nixpkgs/blob/0e8be3827d0298743ba71b91eea652d43d7dc03d/pkgs/by-name/he/hello/package.nix#L47
187+
"""
188+
if derivation.metadata and derivation.metadata.position:
189+
rev = urllib.parse.quote(derivation.parent_evaluation.commit_sha1)
190+
# position is something like `/tmp/tmpfh7ff2xs/pkgs/development/python-modules/qemu/default.nix:67`
191+
position_match = re.match(
192+
r"/tmp/[^/]+/(.+):(\d+)", derivation.metadata.position
193+
)
194+
if position_match:
195+
path = urllib.parse.quote(position_match.group(1))
196+
linenumber = urllib.parse.quote(position_match.group(2))
197+
return f"https://github.com/NixOS/nixpkgs/blob/{rev}/{path}#L{linenumber}"
198+
return None
199+
200+
182201
def channel_structure(
183202
version_constraints: list[Version], derivations: list[NixDerivation]
184203
) -> dict:
@@ -211,21 +230,26 @@ def channel_structure(
211230
"major_version": None,
212231
"status": None,
213232
"uniform_versions": None,
233+
"src_position": None,
214234
"sub_branches": dict(),
215235
}
216-
if not branch_name == major_channel:
236+
if branch_name == major_channel:
237+
packages[attribute]["versions"][major_channel]["major_version"] = (
238+
version
239+
)
240+
packages[attribute]["versions"][major_channel]["src_position"] = (
241+
get_src_position(derivation)
242+
)
243+
else:
217244
packages[attribute]["versions"][major_channel]["sub_branches"][
218245
branch_name
219246
] = {
220247
"version": version,
221248
"status": is_version_affected(
222249
[v.is_affected(version) for v in version_constraints]
223250
),
251+
"src_position": get_src_position(derivation),
224252
}
225-
else:
226-
packages[attribute]["versions"][major_channel]["major_version"] = (
227-
version
228-
)
229253
for package_name in packages:
230254
for mc in packages[package_name]["versions"].keys():
231255
uniform_versions = True

src/website/webview/static/style.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ article .nixpkgs-packages {
722722
}
723723

724724
.nixpkgs-package summary {
725-
min-width: 19.5em; /* .version + .branch-name + 1.5em for the unfold triangle */
725+
min-width: 21.5em; /* .version + .branch-name + 1.5em for the unfold triangle */
726726
margin-left: auto;
727727
}
728728

@@ -774,6 +774,19 @@ article .nixpkgs-packages {
774774
background: var(--unaffected);
775775
}
776776

777+
.nixpkgs-package .src-position {
778+
width: 2em;
779+
text-align: right;
780+
font-family: "IBM Plex Sans Condensed";
781+
color: var(--dark-grey);
782+
text-decoration: none;
783+
}
784+
785+
.nixpkgs-package .src-position:hover,
786+
.src-position:focus {
787+
text-decoration: underline;
788+
}
789+
777790
.maintainers {
778791
margin-top: 1em;
779792
}

src/website/webview/templates/components/nixpkgs_package.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ <h3><span class="pkgs">pkgs.</span>{{ attribute_name }}</h3>
2020
???
2121
{% endif %}
2222
</span>
23+
{% if val.src_position %}
24+
<a class="src-position" target="_blank" href="{{ val.src_position }}">&lt;/&gt;</a>
25+
{% endif %}
2326
</span>
2427
</summary>
2528
<ul class="channel-list">
2629
{% for branch_name, vdata in val.sub_branches %}
2730
<li class="branch-minor">
2831
<span class="branch-name">{{ branch_name }}</span>
2932
<span class="version {{ vdata.status }}">{{ vdata.version }}</span>
33+
{% if val.src_position %}
34+
<a class="src-position" target="_blank" href="{{ val.src_position }}">&lt;/&gt;</a>
35+
{% endif %}
3036
</li>
3137
{% endfor %}
3238
</ul>

0 commit comments

Comments
 (0)