Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
dashboards
Commits
f5c739ce85e2
Commit
660ca0df
authored
Oct 14, 2020
by
Laurent Peuch
Browse files
feat(deprecated-warnings): highlight source code
parent
6fec7c1f4c4a
Changes
3
Hide whitespace changes
Inline
Side-by-side
deprecated-warnings.py
View file @
f5c739ce
...
...
@@ -8,6 +8,30 @@ import zipfile
from
collections
import
defaultdict
from
rdflib
import
ConjunctiveGraph
from
pygments
import
highlight
from
pygments.lexers
import
get_lexer_by_name
from
pygments.formatters.html
import
HtmlFormatter
def
highlight_code
(
file_content
,
lineno
):
file_content
=
file_content
.
split
(
"
\n
"
)[:
lineno
+
4
]
# si on est à la ligne 3
# d'un fichier de 4 lignes
if
len
(
file_content
)
>
lineno
:
hl_lines
=
[
5
]
file_content
=
file_content
[
lineno
-
5
:]
linenostart
=
lineno
-
4
else
:
hl_lines
=
[
lineno
]
linenostart
=
1
file_content
=
"
\n
"
.
join
(
file_content
)
return
highlight
(
file_content
,
get_lexer_by_name
(
"python"
,
stripnl
=
False
),
HtmlFormatter
(
wrapcode
=
True
,
linenos
=
True
,
linenostart
=
linenostart
,
hl_lines
=
hl_lines
))
def
download_heptapod_trig
():
gl
=
gitlab
.
Gitlab
(
'https://forge.extranet.logilab.fr'
,
oauth_token
=
os
.
environ
[
"GITLAB_TOKEN"
])
...
...
@@ -108,5 +132,9 @@ for key, value in all_artifacts.items():
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
)
rendered_template
=
jinja2
.
Template
(
open
(
"template/deprecated-warnings.html"
,
"r"
).
read
()).
render
(
warnings
=
result
,
files_to_url
=
files_to_url_cache
,
highlight_code
=
highlight_code
,
pygment_css
=
HtmlFormatter
().
get_style_defs
())
open
(
"public/deprecated-warnings.html"
,
"w"
).
write
(
rendered_template
)
requirements.txt
View file @
f5c739ce
...
...
@@ -3,3 +3,4 @@ jinja2
tox
requests
rdflib
pygments
template/deprecated-warnings.html
View file @
f5c739ce
...
...
@@ -3,6 +3,9 @@
<head>
<title>
Collected deprecated warnings
</title>
<link
href=
"css/style.css"
rel=
"stylesheet"
type=
"text/css"
>
<style>
{
{
pygment_css
}
}
</style>
</head>
<body>
<h1>
Collected deprecated warnings
</h1>
...
...
@@ -23,9 +26,7 @@
{% endif %}
{% if file_content %}
<pre>
{{ "\n".join(file_content.split("\n")[lineno - 5:lineno + 4]) }}
</pre>
{{ highlight_code(file_content, lineno) }}
{% endif %}
{% endfor %}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment