PyO3 / PyO3/pyo3

Set custom path with `run_code`

Open
#4,110 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

Hello!

I was wondering if it might be possible to add a path parameter to run_code, so that it could create a code objection a different path than the default of "<string>\0". It could be an optional parameter that defaults to the current value. Alternatively, to not break the API, maybe another function called run_code_path could be created that is also public that run_code calls with that parameter?

Currently, I am keeping a duplicate of that function in my source with the parameter added, which adds some overhead when changes happen upstream.

I am doing arbitrary code execution, but I want the tracebacks to refer to line numbers that can be referenced, so I am creating a temporary file, writing the code to it, then evaling that code with that path:

https://github.com/egraphs-good/egglog-python/blob/59b04eaa4f87ac320385efe4b6d71e93db64a116/src/py_object_sort.rs#L351-L365

I am happy to make a PR to add this feature if it is desired. Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the public run_code entry point and trace how it creates code objects, using the linked src/py_object_sort.rs implementation as context for the requested path behavior. Confirm that the optional path preserves the current default and that supplied paths appear in traceback filenames.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.