Repository navigation
Conversation
|
Hi @phr4nky! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
…t.py Summary: `extract.py` writes a script for each `console_scripts` entry of a prebuilt wheel and assumed every value is `module:function`: - a dotted object reference such as `demo:program.run` produced `from demo import program.run`, a SyntaxError when the script runs; - extras such as `mcp.cli:app [cli]` (mcp) or `watchdog.watchmedo:main [watchmedo]` (watchdog) produced `from mcp.cli import app [cli]`, the same SyntaxError; - a value without a colon failed the whole extract action with `ValueError: not enough values to unpack`; - configparser lowercased script names, so `MyTool` became `mytool`. The value is now parsed with the object-reference pattern that `importlib.metadata.EntryPoint` uses: the script imports the first name of the qualified name and calls the whole of it, as pip's scripts do, and extras are ignored. Script names keep their case. A reference without a callable is rejected with a message naming the entry, as pip rejects it. Test Plan: New `tests/extract_test.py` (target `extract_test`) builds a wheel with plain, dotted, extras and mixed-case entries and runs each generated script, and checks the error for a reference without a callable. Both cases fail on the parent commit and pass with this change.
d293346 to
24ef541
Compare
|
This pull request has been imported. If you are a Meta employee, you can view this in D134594510. (Because this pull request was imported automatically, there will not be any future comments.) |
|
This pull request has been merged in 4d81f76. |
…t.py
Summary:
For every `prebuilt_python_library`, `prelude/python/tools/extract.py` writes one script per `console_scripts` entry of the wheel, and it assumes each value is `module:function`. Entry points that use a dotted object reference (`module:object.method`) or extras, such as `mcp = mcp.cli:app [cli]` in mcp 1.29.0 and `watchmedo = watchdog.watchmedo:main [watchmedo]` in watchdog 6.0.0, get a script that fails with `SyntaxError` when run. A value without a colon fails the whole extract action, and script names are lowercased (`MyTool` becomes `mytool`).
## Affected version
Checked on `main` at 4b47e1430e and on the release `2026-11-15` (5b3b13d3ea); `extract.py` is identical in both.
## Reproduction
From a buck2 checkout in `$BUCK2`, in an empty directory:
```
python3 - <<'EOF'
import zipfile
with zipfile.ZipFile("demo-1.0-py3-none-any.whl", "w") as zf:
zf.writestr("demo/__init__.py",
"class _P:\n def run(self):\n print('program.run')\nprogram = _P()\n"
"def main():\n print('main')\n")
zf.writestr("demo-1.0.dist-info/METADATA", "Name: demo\nVersion: 1.0\n")
zf.writestr("demo-1.0.dist-info/entry_points.txt",
"[console_scripts]\ninv = demo:program.run\nx = demo:main [cli]\nMyTool = demo:main\n")
EOF
python3 "$BUCK2/prelude/python/tools/extract.py" --output out --entry-points bin --entry-points-manifest bin.json demo-1.0-py3-none-any.whl
ls bin
for s in bin/*; do PYTHONPATH=out python3 "$s" 2>&1 | tail -1; done
```
## Expected
Scripts `inv`, `MyTool` and `x` that print `program.run`, `main` and `main`, as pip installs them. The entry points specification (packaging.python.org, "Entry points specification", data model) defines the value as `importable.module:object.attr` with optional `[extras]`.
## Actual
```
inv
mytool
x
SyntaxError: invalid syntax
main
SyntaxError: invalid syntax
```
The generated script inv contains `from demo import program.run`, and x contains `from demo import main [cli]`.
## Analysis
`extract.py` splits the value with `entry_point.split(":")` and formats both parts into `from {mod} import {func}` and `{func}()`, so any dot or extras marker after the colon lands in the import statement, and a value without a colon raises `ValueError`. `configparser.ConfigParser` lowercases option names by default, which changes the script name.
## Patch
The value is parsed with the object-reference pattern used by `importlib.metadata.EntryPoint`. The script imports the first name of the qualified name and calls the whole of it, as pip's scripts do, and extras are ignored. `optionxform` keeps the case of script names. A value without a callable is rejected with a message naming the entry, as pip rejects it ("A callable suffix is required").
X-link: meta/buck2#1660
Reviewed By: dtolnay
Differential Revision: D134594510
fbshipit-source-id: 11bc18a57c0e08c459beff0f832aa78d9086077f
Summary
For every
prebuilt_python_library,prelude/python/tools/extract.pywrites one script perconsole_scriptsentry of the wheel, and it assumes each value ismodule:function. Entry points that use a dotted object reference (module:object.method) or extras, such asmcp = mcp.cli:app [cli]in mcp 1.29.0 andwatchmedo = watchdog.watchmedo:main [watchmedo]in watchdog 6.0.0, get a script that fails withSyntaxErrorwhen run. A value without a colon fails the whole extract action, and script names are lowercased (MyToolbecomesmytool).Affected version
Checked on
mainat 4b47e14 and on the release2026-11-15(5b3b13d);extract.pyis identical in both.Reproduction
From a buck2 checkout in
$BUCK2, in an empty directory:Expected
Scripts
inv,MyToolandxthat printprogram.run,mainandmain, as pip installs them. The entry points specification (packaging.python.org, "Entry points specification", data model) defines the value asimportable.module:object.attrwith optional[extras].Actual
The generated script inv contains
from demo import program.run, and x containsfrom demo import main [cli].Analysis
extract.pysplits the value withentry_point.split(":")and formats both parts intofrom {mod} import {func}and{func}(), so any dot or extras marker after the colon lands in the import statement, and a value without a colon raisesValueError.configparser.ConfigParserlowercases option names by default, which changes the script name.Patch
The value is parsed with the object-reference pattern used by
importlib.metadata.EntryPoint. The script imports the first name of the qualified name and calls the whole of it, as pip's scripts do, and extras are ignored.optionxformkeeps the case of script names. A value without a callable is rejected with a message naming the entry, as pip rejects it ("A callable suffix is required").Test Plan: new
prelude/python/tools/tests/extract_test.py(targetextract_test) builds a wheel with plain, dotted, extras and mixed-case entries, runs each generated script, and checks the error for a value without a callable. Both cases fail on the parent commit and pass with the change. With the change, the reproduction above listsMyTooland printsprogram.run,main,main.