Compare commits

...

2 commits

Author SHA1 Message Date
gwen
cb52c774be add modif 2025-11-22 08:08:14 +01:00
gwen
2b0dd5e5bd add extinclude warning in directive 2025-11-22 08:04:51 +01:00
5 changed files with 115 additions and 10 deletions

View file

@ -34,6 +34,21 @@ extensions = [
'ext.xref', 'ext.extinclude' 'ext.xref', 'ext.extinclude'
] ]
#---- disable highlight warnings with yaml new version ----
# Configuration pour les blocs de code
highlight_language = 'yaml'
# Options spécifiques pour YAML
highlight_options = {
'yaml': {
'startinline': True
}
}
suppress_warnings = [
'misc.highlighting_failure'
]
#---- xref links ---- #---- xref links ----
#import the xref.py extension #import the xref.py extension
xref_links = {"link_name" : ("user text", "url")} xref_links = {"link_name" : ("user text", "url")}

View file

@ -1,6 +1,5 @@
from __future__ import annotations from __future__ import annotations
from docutils import nodes from docutils import nodes
from sphinx.application import Sphinx from sphinx.application import Sphinx
from sphinx.util.docutils import SphinxDirective, SphinxRole from sphinx.util.docutils import SphinxDirective, SphinxRole
@ -8,6 +7,8 @@ from sphinx.util.typing import ExtensionMetadata
from sphinx.directives.code import LiteralInclude, container_wrapper from sphinx.directives.code import LiteralInclude, container_wrapper
import requests import requests
from requests.exceptions import RequestException
from docutils.parsers.rst import directives
class ExtInclude(LiteralInclude): class ExtInclude(LiteralInclude):
"""A directive to include code that comes from an url """A directive to include code that comes from an url
@ -29,12 +30,40 @@ class ExtInclude(LiteralInclude):
def run(self) -> list[nodes.Node]: def run(self) -> list[nodes.Node]:
url = self.arguments[0] url = self.arguments[0]
headers = {
'accept': 'application/text', try:
'Content-Type': 'application/text', headers = {
'accept': 'application/text',
'Content-Type': 'application/text',
} }
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers)
#paragraph_node = nodes.paragraph(text=f'hello {self.arguments[0]}!') response.raise_for_status() # This will raise an exception for 4xx/5xx status codes
except requests.exceptions.HTTPError as e:
if response.status_code == 404:
error_msg = f"extinclude: URL not found (404): {url}"
else:
error_msg = f"extinclude: HTTP error {response.status_code}: {url}"
# Create an error node that will be displayed in the documentation
error_node = nodes.error()
para = nodes.paragraph()
para += nodes.Text(error_msg)
error_node += para
self.state.document.reporter.warning(error_msg, line=self.lineno)
return [error_node]
except requests.exceptions.RequestException as e:
error_msg = f"extinclude: Failed to fetch URL {url}: {str(e)}"
# Create an error node that will be displayed in the documentation
error_node = nodes.error()
para = nodes.paragraph()
para += nodes.Text(error_msg)
error_node += para
self.state.document.reporter.warning(error_msg, line=self.lineno)
return [error_node]
code = response.text code = response.text
literal = nodes.literal_block(code, code) literal = nodes.literal_block(code, code)
@ -54,12 +83,9 @@ class ExtInclude(LiteralInclude):
self.add_name(literal) self.add_name(literal)
return [literal] return [literal]
#paragraph_node = nodes.paragraph(text=content.text)
#return [paragraph_node]
def setup(app: Sphinx) -> ExtensionMetadata: def setup(app: Sphinx) -> ExtensionMetadata:
app.add_directive('extinclude', ExtInclude) app.add_directive('extinclude', ExtInclude)
return { return {

View file

@ -1,4 +1,29 @@
"""adds link url in the global scope """adds link url in the global scope
sample use:
:xref:`Tiramisu <tiramisu>`
You must declare in the `conf.py`
::
#---- xref links ----
#import the xref.py extension
xref_links = {"link_name" : ("user text", "url")}
#link_name = "Sphinx External Links"
#user_text = "modified External Links Extension"
#url = "http://www.sphinx-doc.org/en/stable/ext/extlinks.html"
#enables syntax like:
" :xref:`tiramisu` "
links = {
'tiramisu': ('Tiramisu', 'https://tiramisu.readthedocs.io/en/latest/'),
'tiramisu library': ('Tiramisu library homepage', 'https://forge.cloud.silique.fr/stove/tiramisu'),
}
xref_links.update(links)
""" """
from docutils import nodes from docutils import nodes

View file

@ -6,7 +6,7 @@ After construct a configuration, loads user datas, you can choose this configura
First of create, let's create a structural file like this: First of create, let's create a structural file like this:
.. code-block:: yaml .. code-block:: yaml
:caption: the :file:`dist/00-base.yml` file content :caption: the :file:`dist/00-base.yml` file content
%YAML 1.2 %YAML 1.2
--- ---

View file

@ -351,6 +351,45 @@ The constraints that come with the `choice` type
We say that the `proxy_mode` variable is *constrained* (by the `choice` type). We say that the `proxy_mode` variable is *constrained* (by the `choice` type).
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_004/config/03/config.yml
:linenos:
:language: yaml
:caption: A user data specification
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_004/config/03/config.yml>`
If we run the rougail CLI with this user datas, we have:
.. code-block:: text
:class: terminal
rougail -m firefox -u yaml -ff config/03/config.yaml
We have this output:
.. raw:: html
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_004/config/03/output_ro.html
:class: output
..
<pre>╭────────────── Caption ───────────────╮
│ Variable Modified value │
│ (<span style="color: #00aa00">⏳ Original default value</span>) │
╰──────────────────────────────────────╯
Variables:
<span style="color: #5c5cff">┗━━ </span>📓 Configure Proxy Access to the Internet: Manual proxy configuration ◀ loaded from the YAML file "config/03/config.yml" (⏳ <span style="color: #00aa00">No proxy</span>)
</pre>
As we set the `proxy_mode` variable from a user data file,
we now have specified a value which is **not** a default value,
and the value appears in green, which means : "user data value".
.. FIXME: verifier que cette sortie est bonne (on a des valeurs différentes)
.. type-along:: The constraints that come with the `choice` property
The `proxy_mode` variable's possible values is *constrained*.
We have the list of the possible (authorized) values: We have the list of the possible (authorized) values:
- `No proxy` - `No proxy`