Skip to content

Narrow down the scope of ReST parsing. - #4085

Merged
pekkaklarck merged 2 commits into
robotframework:masterfrom
hidmic:parse-rst-subset-only
Sep 20, 2021
Merged

pekkaklarck merged 2 commits into
robotframework:masterfrom
hidmic:parse-rst-subset-only

Conversation

@hidmic

@hidmic hidmic commented Sep 13, 2021 •

Copy link
Copy Markdown

Closes #4086. This patch decorates docutils functionality so as to ignore every directive and role that is not directly relevant to RobotFramework. Alternative to error suppression (through report_level configuration, see #2093).

Ignore unknown and non-relevant directives and roles.
@hidmic

hidmic commented Sep 13, 2021 •

Copy link
Copy Markdown
Author

To put things in context, I'm using RobotFramework for RPA and attempting to use the same ReST file to describe the automation and to layout its output in a document. Thus, not all files that'd be required to render the ReST file are present at the time it is parsed by RobotFramework.

This patch allows RobotFramework to pick up what it needs from the ReST and nothing else.

@pekkaklarck

Copy link
Copy Markdown
Member

Could you clarify why this change is needed? More precisely, how is this better than what was done in #2093? It might be best to submit a separate issue explaining that. We anyway want to have issues for tracking purposes.

On a quick look the code looks ok but lacks tests. If we decide to add this, I'll review the PR more closely.

@hidmic

hidmic commented Sep 13, 2021

Copy link
Copy Markdown
Author

Could you clarify why this change is needed? More precisely, how is this better than what was done in #2093?

In the situation I described above, #2093 won't do. Parsing a .. csv-file:: directive with a :file: uri that points to a nonexistent file raises. But beyond my specific use case, with this patch there's less to process and there's no need to silently ignore any warnings or errors.

We anyway want to have issues for tracking purposes.

Got it. I took a look at the CONTRIBUTING guidelines and it wasn't clear to me whether you always had a tracking issue or not. I'll open one ASAP.

On a quick look the code looks ok but lacks tests. If we decide to add this, I'll review the PR more closely.

I did extend one of the acceptance tests. Would you like to have a unit test for read_rest_data()? There's none at the moment.

@pekkaklarck

Copy link
Copy Markdown
Member

So this fix is more general than what we have? Sounds good to me. I missed that you had modified test data in this regard. Didn't know csv-file import caused problems.

@pekkaklarck

Copy link
Copy Markdown
Member

As I commented #4086, this PR needs to be Python 2 compatible if we want it in RF 4.1.2. Looking at the code the only problem is __wrapped__ that's not set by functools.wraps in Python 2. That ought to be pretty easy to handle:

from robot.utils import PY2

...

@functools.wraps(directives.directive)
def directive(*args, **kwargs):
    ...

@functools.wraps(roles.role)
def role(*args, **kwargs):
    ...

if PY2:
    directive.__wrapped__ = directives.directive
    role.__wrapped__ = roles.role

directives.directive = directive
roles.role = role

@hidmic

hidmic commented Sep 14, 2021

Copy link
Copy Markdown
Author

@pekkaklarck suggestion applied in 35393bc.

@hidmic

hidmic commented Sep 17, 2021

Copy link
Copy Markdown
Author

@pekkaklarck acceptance tests for ReST format parsing pass locally for Python 2.7.18 and Python 3.8.10 using docutils 0.9 and docutils 0.17.1.

Could we fire up the workflows in this PR?

@pekkaklarck
pekkaklarck merged commit 33ee46d into robotframework:master Sep 20, 2021
@pekkaklarck

Copy link
Copy Markdown
Member

Thanks for the PR @hidmic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All irrelevant errors are not silenced when parsing reStructuredText data

2 participants