Commit 9d122ef0 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

feat(deprecated-warnings): (badly) display file content for the warning

parent 4afbedf266d5
......@@ -89,15 +89,23 @@ for cube in get_all_cubes():
content = json.loads(content)
all_artifacts[cube.name].extend(content)
result = defaultdict(lambda: {"count": 0, "path": set(), "projects": defaultdict(int)})
result: dict = defaultdict(lambda: {"count": 0, "path": [], "projects": defaultdict(int)})
for key, value in all_artifacts.items():
for warning in value:
warning_text = eval(warning["args"])[0]
result[warning_text]["count"] += warning["count"]
result[warning_text]["path"].add(f'{warning["path"].split("/site-packages/")[-1].split("/builds/cubicweb/")[-1].split("/builds/open-source/")[-1]}:{warning["lineno"]}')
result[warning_text]["projects"][key] += warning["count"]
file_name = warning["path"].split("/site-packages/")[-1].split("/builds/cubicweb/")[-1].split("/builds/open-source/")[-1]
if file_name not in {x[0] for x in result[warning_text]["path"]}:
result[warning_text]["path"].append((f'{file_name}',
warning["lineno"],
warning.get("file_content")))
result[warning_text]["path"] = sorted(result[warning_text]["path"], key=lambda x: x[0])
result = sorted(result.items(), key=lambda x: -x[1]["count"])
rendered_template = jinja2.Template(open("template/deprecated-warnings.html", "r").read()).render(warnings=result, files_to_url=files_to_url_cache)
......
......@@ -8,26 +8,27 @@
<h1>Collected deprecated warnings</h1>
{% for warning_name, warning_data in warnings %}
<h4>Warning: "{{ warning_name }}"</h4>
<h3>Warning: "{{ warning_name }}"</h4>
Number of occurences: {{ warning_data["count"] }}
<br>
File where it's raised:
<ul>
{% for path in warning_data["path"]|sort %}
<li>
{% if path.split(":")[0] in files_to_url %}
<a href="{{ files_to_url[path.split(":")[0]] }}#L{{ path.split(":")[1] }}" target="_blank">
{% endif %}
{{ path }}
{% if path.split(":")[0] in files_to_url %}
</a>
{% endif %}
</li>
{% for path, lineno, file_content in warning_data["path"] %}
<h5>In {{ path }} line {{ lineno }}</h5>
{% if path in files_to_url %}
<p>
<a href="{{ files_to_url[path] }}#L{{ lineno }}" target="_blank">
File on branch/default
</a>
</p>
{% endif %}
{% if file_content %}
<pre>
{{ "\n".join(file_content.split("\n")[lineno - 5:lineno + 4]) }}
</pre>
{% endif %}
{% endfor %}
</ul>
From those projects:
<ul>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment