Commit 5268c007 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

feat(deprecated): display warnings per project and not all agregatted

parent a0716f0f809e
Pipeline #21351 passed with stages
in 4 minutes and 22 seconds
...@@ -146,46 +146,48 @@ for cube in get_all_cubes(): ...@@ -146,46 +146,48 @@ for cube in get_all_cubes():
result: dict = defaultdict(lambda: {"count": 0, "path": [], result: dict = defaultdict(lambda: {"count": 0, "path": [],
"projects": defaultdict(lambda: {"count": 0, "projects": defaultdict(lambda: {"count": 0,
"dependencies": {}})}) "dependencies": {},
"warnings": {}})})
for key, value in all_artifacts.items(): for gitlab_project, warnings in all_artifacts.items():
for warning in value: for warning in warnings:
warning_text = eval(warning["args"])[0] warning_text = eval(warning["args"])[0]
result[warning_text]["count"] += warning["count"] result[warning_text]["count"] += warning["count"]
result[warning_text]["projects"][key]["count"] += warning["count"] result[warning_text]["projects"][gitlab_project]["count"] += warning["count"]
if "dependencies" in warning and not result[warning_text]["projects"][key]["dependencies"]: if "dependencies" in warning and not result[warning_text]["projects"][gitlab_project]["dependencies"]:
result[warning_text]["projects"][key]["dependencies"] = warning["dependencies"] result[warning_text]["projects"][gitlab_project]["dependencies"] = warning["dependencies"]
file_name = warning["path"].split("/site-packages/")[-1]\ warning_key = (warning["filename"], warning["lineno"])
.split("/builds/cubicweb/")[-1]\
.split("/builds/open-source/")[-1]
if file_name not in {x[0] for x in result[warning_text]["path"]}: warning_key = (warning["filename"], warning["lineno"])
result[warning_text]["path"].append([f'{file_name}', if warning_key not in result[warning_text]["projects"][gitlab_project]["warnings"]:
warning["lineno"], result[warning_text]["projects"][gitlab_project]["warnings"][warning_key] = warning
warning.get("file_content")])
elif warning.get("file_content"):
for warning_content in result[warning_text]["path"]:
this_warning_file_name, _, file_content = warning_content
if this_warning_file_name != file_name: # if file_name not in {x[0] for x in result[warning_text]["path"]}:
continue # result[warning_text]["path"].append([f'{file_name}',
# warning["lineno"],
# warning.get("file_content")])
# elif warning.get("file_content"):
# for warning_content in result[warning_text]["path"]:
# this_warning_file_name, _, file_content = warning_content
# if this_warning_file_name != file_name:
# continue
if not file_content: # if not file_content:
warning_content[2] = warning["file_content"] # warning_content[2] = warning["file_content"]
# this is done to display a summary of the warning at the top
if warning["category"] != "DeprecationWarning": if warning["category"] != "DeprecationWarning":
if "test_file" in warning and "/site-packages/" in warning["test_file"]: if "test_file" in warning and "/site-packages/" in warning["test_file"]:
warning["test_file"] = warning["test_file"].split("/site-packages/")[1] warning["test_file"] = warning["test_file"].split("/site-packages/")[1]
result[warning_text]["projects"][key]["full_warning"] = warning result[warning_text]["projects"][gitlab_project]["full_warning"] = warning
if "full_warning" not in result[warning_text]: if "full_warning" not in result[warning_text]:
result[warning_text]["full_warning"] = warning result[warning_text]["full_warning"] = warning
result[warning_text]["path"] = sorted(result[warning_text]["path"], key=lambda x: x[0])
result = sorted(result.items(), key=lambda x: -x[1]["count"]) result = sorted(result.items(), key=lambda x: -x[1]["count"])
rendered_template = jinja2.Template(open("template/deprecated-warnings.html", rendered_template = jinja2.Template(open("template/deprecated-warnings.html",
......
...@@ -11,9 +11,12 @@ ...@@ -11,9 +11,12 @@
<h1>Collected deprecated warnings</h1> <h1>Collected deprecated warnings</h1>
{% for warning_name, warning_data in warnings %} {% for warning_name, warning_data in warnings %}
{% if not loop.first %}
<hr>
{% endif %}
<h3>Warning: "{{ warning_name }}"</h4> <h3>Warning: "{{ warning_name }}"</h4>
<p>Number of occurences: {{ warning_data["count"] }}</p> <p>Total number of occurences: {{ warning_data["count"] }}</p>
{% if "full_warning" in warning_data %} {% if "full_warning" in warning_data %}
<p>Structured data:</p> <p>Structured data:</p>
...@@ -31,44 +34,33 @@ ...@@ -31,44 +34,33 @@
</ul> </ul>
{% endif %} {% endif %}
{% for path, lineno, file_content in warning_data["path"] %} {% for project, project_data in warning_data["projects"].items() %}
<h5>In {{ path }} line {{ lineno }}</h5> <h4>Project <a target="_blank" href="{{ project.web_url }}">{{ project.name }}</a> ({{ project_data["count"] }} occurences)</h4>
{% 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 %}
{{ highlight_code(file_content, lineno) }}
{% endif %}
{% endfor %} <p>Dependencies (detected during tests execution):</p>
From those projects:
<ul> <ul>
{% for project, project_data in warning_data["projects"].items() %}
<li>
<a target="_blank" href="{{ project.web_url }}">{{ project.name }}</a>: {{ project_data["count"] }}
(
{%- for i in ("Cubicweb", "Yams", "RQL", "logilab-common", "logilab-database") -%} {%- for i in ("Cubicweb", "Yams", "RQL", "logilab-common", "logilab-database") -%}
{%- if i.lower() in project_data["dependencies"] -%} {%- if i.lower() in project_data["dependencies"] -%}
<i>{{ i }}</i> {{ project_data["dependencies"][i.lower()] }} <li><i>{{ i }}</i> {{ project_data["dependencies"][i.lower()] }}</li>
{%- if not loop.last %}, {% endif -%}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
)
{% if "full_warning" in project_data %}
<ul>
From at least this test: {{ project_data["full_warning"]["test_name"] }} (<a href="{{ project.web_url }}/-/blob/branch/default/{{ project_data["full_warning"]["test_file"] }}#L{{ project_data["full_warning"]["test_lineno"] + 1 }}" target="_blank">{{ project_data["full_warning"]["test_file"] }}:{{ project_data["full_warning"]["test_lineno"] + 1 }}</a>)
</ul>
{% endif %}
</li>
{% endfor %}
</ul> </ul>
{% for (path, lineno), warning in project_data["warnings"].items() %}
<p>
In <u>{{ path }}</u> line {{ lineno }}
{% if path in files_to_url %}(<a href="{{ files_to_url[path] }}#L{{ lineno }}" target="_blank">file on branch/default</a>){% endif %}
</p>
{% if "file_content" in warning %}
{{ highlight_code(warning["file_content"], lineno) }}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %} {% endfor %}
</body> </body>
......
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