Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Nov 15, 2024
1 parent 950cc74 commit 08073e3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ This code will be executed
```

# Changelog
#### 0.14 (2024-11-15)
- Add support for all options from code block
- Reworked how blocks and options are processed

#### 0.13 (2024-10-15)
- Add support for python 3.13

#### 0.12 (2024-01-09)
- Error when providing invalid options

Expand Down
2 changes: 1 addition & 1 deletion src/sphinx_exec_code/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.13'
__version__ = '0.14'
20 changes: 5 additions & 15 deletions src/sphinx_exec_code/sphinx_exec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import traceback
from pathlib import Path
from typing import Any, Final, Tuple

from docutils.statemachine import StringList
from sphinx.directives.code import CodeBlock
Expand Down Expand Up @@ -82,7 +81,7 @@ def _run(self) -> list:
raise ExtensionError(msg, orig_exc=e) from None

# Show the code from the user
self.create_literal_block(output, code_show, code_spec, str(file), line)
self.create_literal_block(output, code_show, code_spec, line)

try:
code_results = execute_code(code_exec, file, line)
Expand All @@ -98,10 +97,10 @@ def _run(self) -> list:
raise ExtensionError(msg) from None

# Show the output from the code execution
self.create_literal_block(output, code_results, output_spec, str(file), line)
self.create_literal_block(output, code_results, output_spec, line)
return output

def create_literal_block(self, objs: list, code: str, spec: SphinxSpecBase, file: str, line: int) -> None:
def create_literal_block(self, objs: list, code: str, spec: SphinxSpecBase, line: int) -> None:
if spec.hide or not code:
return None

Expand All @@ -111,18 +110,9 @@ def create_literal_block(self, objs: list, code: str, spec: SphinxSpecBase, file
line,
# I'm not sure what these two do
self.content_offset, '',
# Make the state machine report the proper source file because we support loading from files
self.state, DummyStateMachine(file, self.state_machine.reporter)
# Let's hope these are just for producing error messages and not for anything else
self.state, self.state_machine
)

objs.extend(c.run())
return None


class DummyStateMachine:
def __init__(self, source: str, reporter: Any) -> None:
self._source: Final = source
self.reporter: Final = reporter

def get_source_and_line(self, line: int) -> Tuple[str, int]:
return self._source, line

0 comments on commit 08073e3

Please sign in to comment.