Skip to content

Executor update - #1

Merged
jesper-friis merged 6 commits into
mainfrom
executor
Aug 10, 2026
Merged

jesper-friis merged 6 commits into
mainfrom
executor

Conversation

@pintr

@pintr pintr commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Update executor to handle files as input, stdout and stderr files as results.

Comment thread pybox/executor.py Outdated
Comment thread pybox/executor.py Outdated
Comment thread pybox/executor.py Outdated
Comment thread pybox/executor.py Outdated
Comment on lines +252 to +253
except (OSError, json.JSONDecodeError):
input_dict = {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to verbosely return an error instead of silently ignoring invalid input.

Comment thread pybox/executor.py Outdated
Comment on lines +239 to +240
except OSError:
pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to verbosely return an error instead of silently treating a file as a code string if it fails to be read as a file. Enforsing that file paths must be pathlib.Path objects makes this easier.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properly managed by logging and raising a ValueError

Comment thread pybox/executor.py Outdated
Comment on lines +271 to +367
input: Optional[Dict[str, Any]] = None,
json_input: Optional[Any] = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as for run()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Managed as in run

Comment thread pybox/executor.py
Returns:
The executed result when status is ``ok``.

Raises:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On timeout, we should probably raise a executor.TimeoutError, inheriting from executor.ExecuteError and buildins.TimeoutError.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as requestesd

Comment thread README.md Outdated
Comment on lines +91 to +99
from pybox import Executor, Config

cfg = Config(
timeout=3.0,
stdout_file=".pybox/stdout.txt",
stderr_file=".pybox/stderr.txt",
)
executor = Executor(cfg)
result = executor.run("result = x + y", {"x": 2, "y": 3})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sence to add >>> prompts to the code examples? That would allow to test them with doctest.

With ipython it is not a problem, but for some people it may create problems for interactively copying the examples into the interpreter. Any thoughts or opinions?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the cleanest solution may be to keep the code blocks without prompt and them test with markdown-pytest?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into markdown-pytest, but it requires injecting HTML comments above every single code block to register them as tests.
Instead, I've added pytest-codeblocks to our dev dependencies. It automatically picks up standard Python markdown and execute the examples when running pytest --codeblocks README.md

@pintr pintr Aug 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update now it skips the unrunnable code blocks, we can discuss the best solution since there are only 3 runnable tests in README

Comment thread README.md Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result dict also has key: 'duration'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated accordingly and extended README

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see your changes, let me know if the new version is good

Comment thread requirements.txt Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it more modern to put the requirements in the pyproject.toml file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed requirements.txt everything is in pyproject.toml

@jesper-friis jesper-friis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Here are some suggestions that can be discussed.

Comment thread README.md Outdated
@jesper-friis
jesper-friis merged commit be8e79f into main Aug 10, 2026
1 check passed
@jesper-friis
jesper-friis deleted the executor branch August 10, 2026 19:54
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.

2 participants