Skip to content

python: Skip empty PYTHONWARNINGS entries in the inplace launcher - #1667

Closed
phr4nky wants to merge 1 commit into
meta:mainfrom
phr4nky:fix-run-inplace-empty-pythonwarnings
Closed

phr4nky wants to merge 1 commit into
meta:mainfrom
phr4nky:fix-run-inplace-empty-pythonwarnings

Conversation

@phr4nky

@phr4nky phr4nky commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

The inplace launcher (prelude/python/tools/run_inplace.py.in) passes each comma-separated entry of PYTHONWARNINGS to the interpreter as -W<entry>. An empty entry, from PYTHONWARNINGS= or a trailing comma, becomes a bare -W. That option takes the next argument as its value. When the empty entry comes last, the next argument is -c: the interpreter then tries to open the startup code as a script, and the python_binary or python_test never starts. When another entry follows, the bare -W swallows that entry instead, and its filter is lost.

CPython accepts both values: it skips empty entries when it reads the variable. This PR does the same.

Affected version

origin/main 00c2ee4. The loop is unchanged since the initial commit.

Reproduction

python_binary(name = "bin", main = "main.py")
PYTHONWARNINGS= buck2 run :bin
PYTHONWARNINGS='ignore::DeprecationWarning,' buck2 run :bin

Expected

The binary runs, as PYTHONWARNINGS= python3 main.py does.

Actual

Invalid -W option ignored: invalid action: '-c'
.../bin/python: can't open file '.../# .../bin.par\n# Wrap everything in a private function ...': [Errno 63] File name too long

With PYTHONWARNINGS=' , default', the binary runs but prints Invalid -W option ignored: invalid action: '-Wdefault'.

Test plan

  • prelude/python/tools/tests/make_py_package_inplace_test.py: the new WarningsTest launches the real template with PYTHONWARNINGS set to "", "ignore::DeprecationWarning," and " , default". It expects a successful run with no "Invalid -W option". All three cases fail without the fix and pass with it. _launch moves out of SafePathTest to module level so both test classes share it.
  • buck2 run of a python_binary with the prelude's demo toolchains on macOS: both values above failed before the change and run after it.
  • Note: on macOS, four existing TrampolineRuntimeTest cases fail on origin/main unless TMPDIR is set to its resolved path. They compare against /var/... while the launcher reports /private/var/.... That is unrelated to this change; with a resolved TMPDIR, all 13 tests pass.

The inplace launcher passes each comma-separated entry of PYTHONWARNINGS to
the interpreter as `-W<entry>`. An empty entry, from `PYTHONWARNINGS=` or a
trailing comma, became a bare `-W`, which takes the next argument as its
value: `-c`, so the interpreter tried to open the startup code as a script
and every inplace binary failed to start. Before another entry, it swallowed
that entry instead.

Leave empty entries out, as Python itself does when it reads the variable.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 27, 2026
@meta-codesync

meta-codesync Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D134829297. (Because this pull request was imported automatically, there will not be any future comments.)

@dtolnay dtolnay left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks!

@meta-codesync meta-codesync Bot closed this in 7f2701c Nov 28, 2026
@meta-codesync meta-codesync Bot added the Merged label Nov 28, 2026
@meta-codesync

meta-codesync Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 7f2701c.

meta-codesync Bot pushed a commit to meta/buck2-prelude that referenced this pull request Nov 28, 2026
Summary:
The inplace launcher (`prelude/python/tools/run_inplace.py.in`) passes each comma-separated entry of `PYTHONWARNINGS` to the interpreter as `-W<entry>`. An empty entry, from `PYTHONWARNINGS=` or a trailing comma, becomes a bare `-W`. That option takes the next argument as its value. When the empty entry comes last, the next argument is `-c`: the interpreter then tries to open the startup code as a script, and the `python_binary` or `python_test` never starts. When another entry follows, the bare `-W` swallows that entry instead, and its filter is lost.

CPython accepts both values: it skips empty entries when it reads the variable. This PR does the same.

## Affected version

origin/main 00c2ee4f74. The loop is unchanged since the initial commit.

## Reproduction

```python
python_binary(name = "bin", main = "main.py")
```

```
PYTHONWARNINGS= buck2 run :bin
PYTHONWARNINGS='ignore::DeprecationWarning,' buck2 run :bin
```

## Expected

The binary runs, as `PYTHONWARNINGS= python3 main.py` does.

## Actual

```
Invalid -W option ignored: invalid action: '-c'
.../bin/python: can't open file '.../# .../bin.par\n# Wrap everything in a private function ...': [Errno 63] File name too long
```

With `PYTHONWARNINGS=' , default'`, the binary runs but prints `Invalid -W option ignored: invalid action: '-Wdefault'`.

X-link: meta/buck2#1667

Reviewed By: dtolnay

Differential Revision: D134829297

fbshipit-source-id: ffc6b11045b09fb3129b91d840a29f9c16f181e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants