Comments (13)
I forgot to add: If I remove the python
part in my example, it works again
from sybil.
I just realized we do a heavy amount of our own parsing in the linked module.
Specifically here, we use example.end
to find the end of the sample and in previous versions that seemed to
match with position before the terminating tripple quotes.
from sybil.
I forgot to add: If I remove the python part in my example, it works again
Is the example even executed/checked if you do this?
Specifically here, we use example.end to find the end of the sample and in previous versions that seemed to match with position before the terminating tripple quotes.
It did, but that was a bug, even appears in the release notes ;-)
from sybil.
It did, but that was a bug, even appears in the release notes ;-)
I was wondering about that..one persons bug is another persons feature 😆
We're doing that extra parsing because we try to have the original line numbers, but maybe I am just not using some existing features to get the same?
Anyway, closing since it's not a bug, but appreciate any pointers if I can do it better.
from sybil.
Can you try changing this:
example_code = textwrap.dedent(
example.document.text[example.start : example.end]
)
to this:
example_code = example.parsed
from sybil.
Am I right in reading your code as only running pylint over the example rather than actually executing the examples?
Getting line numbers right is hard, especially if you're modifying the source before executing it. Sybil used to do that style of modification, but I managed to eradicate it by using compile flags instead, partly because getting it right is so hard.
Nonetheless, here's what Sybil does to get this right:
sybil/sybil/evaluators/python.py
Lines 23 to 26 in 9e12507
from sybil.
Am I right in reading your code as only running pylint over the example rather than actually executing the examples?
I mean, executing them fully is certainly desirable, but many of our code requires remote end points for most examples to work :)
I'll try your suggestions as soon as I have some time :) Thanks!
from sybil.
sybil/sybil/evaluators/python.py
Lines 23 to 26 in 9e12507
What I don't understand about this code (I do the padding the same), you use
example.parsed
, but that text bit has all the empty lines removed, thus it must also result in wrong line numbers the further you get to the end (more skipped blank lines).
Otherwise that whole hack I did would be obsolete as I could just use .parsed
.
from sybil.
you use
example.parsed
, but that text bit has all the empty lines removed
I don't believe this is the case, can you show me an example of .parsed
having empty lines removed?
Otherwise that whole hack I did would be obsolete as I could just use .parsed.
That's my hope :-) But, to get the line numbers right, you still have to prefix with the right number of newlines to match where the example was found in the source, and also the number of newlines between the start of the example and the actual line within the example, which is what the code on line 25 above is doing.
from sybil.
I don't believe this is the case, can you show me an example of .parsed having empty lines removed?
Sure, any example works for that for me.. I added the following code to the already linked snippets for the comparison:
# Dedent the code example
# There is also example.parsed that is already prepared, but it has
# empty lines stripped and thus fucks up the line numbers.
example_code = textwrap.dedent(
example.document.text[example.start : example.end]
)
# Remove first line (the line with the triple backticks)
example_code = example_code[example_code.find("\n") + 1 :]
print(f"Example code: >\n{example_code}<")
print(f"=================\n.parsed: >\n{example.parsed}<")
Output:
Example code: >
a = 2
# blank line follows this
b = 3
<
=================
.parsed: >
a = 2
# blank line follows this
b = 3
<
from sybil.
I added a test for this in https://github.com/simplistix/sybil/pull/116/files
It appears to show that no blank lines are removed by the MyST PythonCodeBlockParser
.
It you could work up a similar PR to the one above that shows the problem you are experiencing, I can take a look.
Otherwise, can you confirm this verifies the behaviour is introduced somewhere in your code?
from sybil.
I'll see if I can make a test
from sybil.
from sybil.
Related Issues (20)
- ModuleNotFoundError if pytest is not installed HOT 5
- Support GitHub Flavored Markdown (GFM)
- Request: Add test which fails if `self.evaluator = None` is removed HOT 2
- Parse and export directive options, too HOT 18
- `skip: next` now seems to require an empty line after it HOT 2
- Pytest 8 error: FixtureManager.getfixtureclosure() missing 1 required positional argument: 'ignore_args' HOT 14
- Support for `testcode` and `testoutput` in `DocTestDirectiveParser`s HOT 6
- MyST lexer can't handle code fences with additional backticks HOT 5
- sdist is missing some files needed for testing HOT 3
- pytest: `IndexError: list index out of range` when filtering traceback at `tb_entry = tb[1]` HOT 5
- Escapes inside docstring cause Sybil to fail HOT 3
- Discussion: Using multiple evaluators on the same region HOT 28
- Colored output in Python 3.13 causes Sybil to fail HOT 4
- Add support for the `code` MyST directive HOT 1
- Add support for the `.. code::` reStructuredText directive HOT 1
- TypeError related to FixtureManager.getfixtureclosure() on v7.0.0 HOT 5
- Docstring collection failure with ellipsis HOT 2
- Add a maximum version to pytest dependency for the pytest extra HOT 3
- AttributeError on bad skip comment HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sybil.