Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow specifying interpreter args on a target #2668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rickeylev opened this issue Mar 16, 2025 · 0 comments · Fixed by #2669
Closed

Allow specifying interpreter args on a target #2668

rickeylev opened this issue Mar 16, 2025 · 0 comments · Fixed by #2669

Comments

@rickeylev
Copy link
Collaborator

Python supports various arguments to modify the interpreter's behavior: https://docs.python.org/3/using/cmdline.html

Today, however, user programs don't have a way to set these. By the time user code runs, the interpreter is already started and they can't change them. Working around this in user space is borderline impossible (they would have to re-exec, but somehow preserve various things the bootstrap did).

To fix this, lets add an interpreter_args attribute. It is a list of strings.

Since there's several sources of args passed to the interpreter, the ordering will be:

  1. bootstrap computed args (right now a special -X value)
  2. The target's interpreter_args attribute (the attr in this FR)
  3. Args set by an outer environment variable (as proposed in the PR to aid debugging)
  4. stage2 bootstrap path
  5. Any additional args from the environment ($@)

For the initial implementation, the values are just inserted as is.

Some open questions to think about:

Should the attribute support various expansions? The three types I can think of are:

  1. make vars expansion, e.g. interpreter_args = ["$(foo)"]
  2. location expansion, eg. interpreter_args = ["$(location :foo)"]
  3. Runtime environment variable expansion, e.g. interpreter_args = ["%RUNFILES_DIR%"]

Should there be a way to unset an arg? The particular case I have in mind is: we want to switch to using -P for setting PYTHONSAFEPATH. Unfortunately, Python doesn't have any way to unset boolean interpreter args.

However, sometimes people want to disable this. A special value to indicate removal of an interpreter arg is somewhat appealing over a dedicated attribute. e.g. interpreter_args=["--UNSET=-P"] or interpreter_args=["-P=REMOVE"] and then the bootstrap removes -P from the interpreter args.

Should there be flag to add args? This just sounds generally handy, but I'm not sure what the use case would be.

Should there be a target-accepting attribute? Targets can be handy if more complex logic is desired. It can be easier than trying to express non-trivial select conditions.

Actually, this might be solved by supporting make vars expansion. Users are able to make arbitrary variables available by setting toolchains on the target and then having it return the TemplateVariablesInfo provider with the values they want.

github-merge-queue bot pushed a commit that referenced this issue Mar 17, 2025
Today, there's way to control what startup args are used for the
interpreter.

To fix, add an `interpreter_args` attribute. These are written into the
bootstrap.

This is only implemented for the bootstrap=script method

Fixes #2668
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant