Skip to content

Commit

Permalink
Merge pull request #36 from martin-g/arch-filtering
Browse files Browse the repository at this point in the history
Issue #34 - Print the additional platforms in the `description` table column
  • Loading branch information
bgruening authored Nov 30, 2024
2 parents 5021bc4 + 4ecbd31 commit 471d2b1
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 17 deletions.
57 changes: 45 additions & 12 deletions source/_ext/bioconda_sphinx_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@
from bioconda_utils.githandler import BiocondaRepo
from bioconda_utils.lint import get_checks

# Aquire a logger
# Acquire a logger
try:
logger = sphinx_logging.getLogger(__name__) # pylint: disable=invalid-name
except AttributeError: # not running within sphinx
import logging
logger = logging.getLogger(__name__) # pylint: disable=invalid-name

# A structure that holds extra information about recipes
recipes_details = {}

def as_extlink_filter(text):
"""Jinja2 filter converting identifier (list) to extlink format
Expand Down Expand Up @@ -393,23 +395,25 @@ class PackageIndex(Index):

def generate(self, docnames: Optional[List[str]] = None):
"""build index"""
content = {}
content = []

objects = sorted(self.domain.data['objects'].items())
for (typ, name), (docname, labelid) in objects:
if docnames and docname not in docnames:
continue
entries = content.setdefault(name[0].lower(), [])
subtype = 0 # 1 has subentries, 2 is subentry
entries.append((
# TODO: Add meaningful info for extra/qualifier/description
# fields, e.g., latest package version.
# name, subtype, docname, labelid, 'extra', 'qualifier', 'description',
name, subtype, docname, labelid, '', '', '',
))

recipe_details = recipes_details.get(name, {})

# TODO: Add meaningful info for extra/qualifier/description
# fields, e.g., latest package version.
content.append({
"name": name,
"platforms": ', '.join(recipe_details.get('platforms', [])),
"latest_version": recipe_details.get('latest_version')
})

collapse = True
return sorted(content.items()), collapse
return content, collapse


class CondaDomain(Domain):
Expand Down Expand Up @@ -572,6 +576,8 @@ def generate_readme(recipe_basedir, output_dir, folder, repodata, renderer):
logger.error("Unable to process %s: %s", meta_fname, e)
return []

recipe_details = recipes_details.get(recipe.name, {})

# Format the README
packages = []
for package in sorted(list(set(recipe.package_names))):
Expand All @@ -590,6 +596,25 @@ def generate_readme(recipe_basedir, output_dir, folder, repodata, renderer):
build_number=sorted_versions[0][1],
)[0]
]

if recipe.name == package:
latest_version = sorted_versions[0][0]
platforms = set(repodata.get_package_data('platform', channels='bioconda', name=package, version=latest_version))
if "noarch" in platforms:
platforms = ["noarch"] # no need to list linux or osx
else:
def mapper(platform):
if "linux" == platform:
return "linux-64"
elif "osx" == platform:
return "osx-64"
else:
return platform
platforms = map(mapper, platforms)
recipe_details['platforms'] = list(platforms)

recipe_details['latest_version'] = latest_version
# recipe_details['build_number'] = sorted_versions[0][1]
else:
depends = []

Expand All @@ -599,14 +624,22 @@ def generate_readme(recipe_basedir, output_dir, folder, repodata, renderer):
'depends' : depends,
})

recipe_extra = recipe.get('extra', None)
template_options = {
'name': recipe.name,
'about': recipe.get('about', None),
'extra': recipe.get('extra', None),
'extra': recipe_extra,
'recipe': recipe,
'packages': packages,
}

if recipe_extra is None:
recipe_details['additional-platforms'] = []
else:
recipe_details['additional-platforms'] = recipe_extra.get('additional-platforms', [])

recipes_details[recipe.name] = recipe_details

renderer.render_to_file(output_file, 'readme.rst_t', template_options)
return [output_file]

Expand Down
145 changes: 145 additions & 0 deletions source/templates/domainindex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{# Template for domain indices (module index, ...). #}
{%- extends "layout.html" %}
{% set title = indextitle %}
{% block extrahead %}
{{ super() }}
{% if not embedded and collapse_index %}
<script>
DOCUMENTATION_OPTIONS.COLLAPSE_INDEX = true;
</script>
{% endif %}
<link rel="stylesheet" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/rowgroup/1.5.1/css/rowGroup.dataTables.min.css"/>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.datatables.net/2.1.8/js/dataTables.js"></script>
<script src="https://cdn.datatables.net/rowgroup/1.5.1/js/dataTables.rowGroup.min.js"></script>
{% endblock %}
{% block body %}

{%- set groupid = idgen() %}

<h1>{{ indextitle }}</h1>

<table>
<thead>
<tr>
<th>Recipes</th>
<th>Count</th>
<th>Ratio</th>
</tr>
</thead>
<tbody>
<tr>
<td>Total</td>
<td id="total-count" style="text-align: center;"></td>
<td></td>
</tr>
<tr>
<td>noarch</td>
<td id="noarch-count" style="text-align: center;"></td>
<td><span id="noarch-ratio"></span>%</td>
</tr>
<tr>
<td>linux-64</td>
<td id="linux-64-count" style="text-align: center;"></td>
<td><span id="linux-64-ratio"></span>%</td>
</tr>
<tr>
<td>linux-aarch64</td>
<td id="linux-aarch64-count" style="text-align: center;"></td>
<td><span id="linux-aarch64-ratio"></span>%</td>
</tr>
<tr>
<td>osx-64:</td>
<td id="osx-64-count" style="text-align: center;"></td>
<td><span id="osx-64-ratio"></span>%</td>
</tr>
<tr>
<td>osx-arm64:</td>
<td id="osx-arm64-count" style="text-align: center;"></td>
<td><span id="osx-arm64-ratio"></span>%</td>
</tr>
</tbody>
</table>

<table class="indextable modindextable" id="recipes-table"></table>

<script>

let dataset = [
{%- for (entry) in content %}
["{{ entry.name }}", "{{ entry.latest_version }}", "{{ entry.platforms }}"]{%- if not loop.last -%}{{ "," }}{%- endif -%}
{%- endfor %}
];

let linux64Count = 0;
let linuxAarch64Count = 0;
let osx64Count = 0;
let osxArm64Count = 0;
let noarchCount = 0;
for (let i=0; i<dataset.length; i++) {
let entry = dataset[i];
if (entry[2].includes("linux-64")) {
linux64Count += 1;
}
if (entry[2].includes("linux-aarch64")) {
linuxAarch64Count += 1;
}
if (entry[2].includes("osx-64")) {
osx64Count += 1;
}
if (entry[2].includes("osx-arm64")) {
osxArm64Count += 1;
}
if (entry[2].includes("noarch")) {
noarchCount += 1;
}
}
let totalCount = dataset.length;
document.getElementById("noarch-count").textContent = noarchCount;
document.getElementById("noarch-ratio").textContent = (noarchCount / totalCount * 100).toFixed(2);
document.getElementById("linux-64-count").textContent = linux64Count;
document.getElementById("linux-64-ratio").textContent = (linux64Count / totalCount * 100).toFixed(2);
document.getElementById("linux-aarch64-count").textContent = linuxAarch64Count;
document.getElementById("linux-aarch64-ratio").textContent = (linuxAarch64Count / totalCount * 100).toFixed(2);
document.getElementById("osx-64-count").textContent = osx64Count;
document.getElementById("osx-64-ratio").textContent = (osx64Count / totalCount * 100).toFixed(2);
document.getElementById("osx-arm64-count").textContent = osxArm64Count;
document.getElementById("osx-arm64-ratio").textContent = (osxArm64Count / totalCount * 100).toFixed(2);
document.getElementById("total-count").textContent = totalCount;

let table = new DataTable('#recipes-table', {
data: dataset,
columns: [
{ title: "Name" },
{
title: "Latest version",
orderable: false
},
{
title: "Platforms",
orderable: false
},
],
displayLength: 50,
lengthMenu: [
[10, 50, 100, -1],
[10, 50, 100, 'All']
],
columnDefs: [
{
render: (data, type, row) => {
return '<a href="./recipes/' + data + '/README.html#package-'+data+'"><code class="xref">' + data + '</code></a>';
},
targets: 0
},
],
rowGroup: {
enable: true,
dataSrc: (row) => row[0].charAt(0).toLowerCase()
}
});
</script>

{% endblock %}
12 changes: 7 additions & 5 deletions source/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
let closest;
// Get the last part of the URL after the # symbol - should match the div id to display
let id = window.location.hash.substring(1);
let elem = document.getElementById(id);
if (elem != null) {
// Get the closest "details" element and open it
closest = elem.closest("details");
if (closest) closest.open = true;
if (id) {
let elem = document.getElementById(id);
if (elem != null) {
// Get the closest "details" element and open it
closest = elem.closest("details");
if (closest) closest.open = true;
}
}
</script>

Expand Down
14 changes: 14 additions & 0 deletions source/templates/readme.rst_t
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@
{%- endfor %}
:requirements:

:additional platforms:
{% if extra and extra['additional-platforms']|length > 0 %}
.. raw:: html

<span class="additional-platforms">
{%- for platform in extra['additional-platforms'] -%}
<code>{{ platform }}</code>
{%- if not loop.last -%}
{{ ",\xa0 " }}
{%- endif -%}
{%- endfor -%}
</span>
{% endif %}

.. rubric:: Installation

You need a conda-compatible package manager
Expand Down

0 comments on commit 471d2b1

Please sign in to comment.